Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 15, 2024
1 parent dc73eeb commit 53a8b27
Show file tree
Hide file tree
Showing 19 changed files with 288 additions and 96 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,10 @@ jobs:
RYE_INSTALL_OPTION: '--yes'

- name: Install dependencies
run: |
rye sync --all-features
- name: Run ruff
run: |
rye run check:ruff
run: rye sync --all-features

- name: Run type checking
run: |
rye run typecheck
- name: Ensure importable
run: |
rye run python -c 'import groq'
- name: Run lints
run: ./scripts/lint
test:
name: test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-0a3089666368ff1ff668f2a73ea3b40d8b20420d8403a18579a1168dd67f2220.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-c28de228634e737a173375583a09eef5e0d7fa81fcdf7090d14d194e6ef4fdc5.yml
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```bash
pip install git+ssh://git@github.com/groq/groq-python.git
pip install git+ssh://git@github.com/groq/groq-python#main.git
```

Alternatively, you can build from source and install the wheel file:
Expand Down
12 changes: 9 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ from groq.types import Translation
Types:

```python
from groq.types.audio import Transcription
from groq.types.audio import Transcription, TranscriptionCreateResponse
```

Methods:

- <code title="post /openai/v1/audio/transcriptions">client.audio.transcriptions.<a href="./src/groq/resources/audio/transcriptions.py">create</a>(\*\*<a href="src/groq/types/audio/transcription_create_params.py">params</a>) -> <a href="./src/groq/types/audio/transcription.py">Transcription</a></code>
- <code title="post /openai/v1/audio/transcriptions">client.audio.transcriptions.<a href="./src/groq/resources/audio/transcriptions.py">create</a>(\*\*<a href="src/groq/types/audio/transcription_create_params.py">params</a>) -> <a href="./src/groq/types/audio/transcription_create_response.py">TranscriptionCreateResponse</a></code>

## Translations

Types:

```python
from groq.types.audio import TranslationCreateResponse
```

Methods:

- <code title="post /openai/v1/audio/translations">client.audio.translations.<a href="./src/groq/resources/audio/translations.py">create</a>(\*\*<a href="src/groq/types/audio/translation_create_params.py">params</a>) -> <a href="./src/groq/types/translation.py">Translation</a></code>
- <code title="post /openai/v1/audio/translations">client.audio.translations.<a href="./src/groq/resources/audio/translations.py">create</a>(\*\*<a href="src/groq/types/audio/translation_create_params.py">params</a>) -> <a href="./src/groq/types/audio/translation_create_response.py">TranslationCreateResponse</a></code>

# Models

Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ pluggy==1.3.0
# via pytest
py==1.11.0
# via pytest
pydantic==2.4.2
pydantic==2.7.1
# via groq
pydantic-core==2.10.1
pydantic-core==2.18.2
# via pydantic
pyright==1.1.359
pytest==7.1.1
Expand Down
4 changes: 2 additions & 2 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ httpx==0.25.2
idna==3.4
# via anyio
# via httpx
pydantic==2.4.2
pydantic==2.7.1
# via groq
pydantic-core==2.10.1
pydantic-core==2.18.2
# via pydantic
sniffio==1.3.0
# via anyio
Expand Down
2 changes: 1 addition & 1 deletion scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ set -e

cd "$(dirname "$0")/.."

echo "==> Running formatters"
rye run format

4 changes: 4 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ set -e

cd "$(dirname "$0")/.."

echo "==> Running lints"
rye run lint

echo "==> Making sure it imports"
rye run python -c 'import groq'

1 change: 0 additions & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ else
echo
fi

# Run tests
echo "==> Running tests"
rye run pytest "$@"
20 changes: 16 additions & 4 deletions src/groq/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from ._constants import RAW_RESPONSE_HEADER

if TYPE_CHECKING:
from pydantic_core.core_schema import ModelField, ModelFieldsSchema
from pydantic_core.core_schema import ModelField, LiteralSchema, ModelFieldsSchema

__all__ = ["BaseModel", "GenericModel"]

Expand Down Expand Up @@ -251,7 +251,9 @@ def model_dump(
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
warnings: bool | Literal["none", "warn", "error"] = True,
context: dict[str, Any] | None = None,
serialize_as_any: bool = False,
) -> dict[str, Any]:
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
Expand Down Expand Up @@ -279,6 +281,10 @@ def model_dump(
raise ValueError("round_trip is only supported in Pydantic v2")
if warnings != True:
raise ValueError("warnings is only supported in Pydantic v2")
if context is not None:
raise ValueError("context is only supported in Pydantic v2")
if serialize_as_any != False:
raise ValueError("serialize_as_any is only supported in Pydantic v2")
return super().dict( # pyright: ignore[reportDeprecated]
include=include,
exclude=exclude,
Expand All @@ -300,7 +306,9 @@ def model_dump_json(
exclude_defaults: bool = False,
exclude_none: bool = False,
round_trip: bool = False,
warnings: bool = True,
warnings: bool | Literal["none", "warn", "error"] = True,
context: dict[str, Any] | None = None,
serialize_as_any: bool = False,
) -> str:
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
Expand All @@ -324,6 +332,10 @@ def model_dump_json(
raise ValueError("round_trip is only supported in Pydantic v2")
if warnings != True:
raise ValueError("warnings is only supported in Pydantic v2")
if context is not None:
raise ValueError("context is only supported in Pydantic v2")
if serialize_as_any != False:
raise ValueError("serialize_as_any is only supported in Pydantic v2")
return super().json( # type: ignore[reportDeprecated]
indent=indent,
include=include,
Expand Down Expand Up @@ -550,7 +562,7 @@ def _build_discriminated_union_meta(*, union: type, meta_annotations: tuple[Any,
field_schema = field["schema"]

if field_schema["type"] == "literal":
for entry in field_schema["expected"]:
for entry in cast("LiteralSchema", field_schema)["expected"]:
if isinstance(entry, str):
mapping[entry] = variant
else:
Expand Down
46 changes: 28 additions & 18 deletions src/groq/resources/audio/transcriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import List, Union, Mapping, cast
from typing import Any, List, Union, Mapping, cast
from typing_extensions import Literal

import httpx
Expand All @@ -26,7 +26,7 @@
from ..._base_client import (
make_request_options,
)
from ...types.audio.transcription import Transcription
from ...types.audio.transcription_create_response import TranscriptionCreateResponse

__all__ = ["TranscriptionsResource", "AsyncTranscriptionsResource"]

Expand Down Expand Up @@ -56,7 +56,7 @@ def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Transcription:
) -> TranscriptionCreateResponse:
"""
Transcribes audio into the input language.
Expand Down Expand Up @@ -115,14 +115,19 @@ def create(
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
"/openai/v1/audio/transcriptions",
body=maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
TranscriptionCreateResponse,
self._post(
"/openai/v1/audio/transcriptions",
body=maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(
Any, TranscriptionCreateResponse
), # Union types cannot be passed in as arguments in the type system
),
cast_to=Transcription,
)


Expand Down Expand Up @@ -151,7 +156,7 @@ async def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Transcription:
) -> TranscriptionCreateResponse:
"""
Transcribes audio into the input language.
Expand Down Expand Up @@ -210,14 +215,19 @@ async def create(
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
"/openai/v1/audio/transcriptions",
body=await async_maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
TranscriptionCreateResponse,
await self._post(
"/openai/v1/audio/transcriptions",
body=await async_maybe_transform(body, transcription_create_params.TranscriptionCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(
Any, TranscriptionCreateResponse
), # Union types cannot be passed in as arguments in the type system
),
cast_to=Transcription,
)


Expand Down
46 changes: 28 additions & 18 deletions src/groq/resources/audio/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Union, Mapping, cast
from typing import Any, Union, Mapping, cast
from typing_extensions import Literal

import httpx
Expand All @@ -26,7 +26,7 @@
from ..._base_client import (
make_request_options,
)
from ...types.translation import Translation
from ...types.audio.translation_create_response import TranslationCreateResponse

__all__ = ["TranslationsResource", "AsyncTranslationsResource"]

Expand Down Expand Up @@ -54,7 +54,7 @@ def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Translation:
) -> TranslationCreateResponse:
"""
Translates audio into English.
Expand Down Expand Up @@ -100,14 +100,19 @@ def create(
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return self._post(
"/openai/v1/audio/translations",
body=maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
TranslationCreateResponse,
self._post(
"/openai/v1/audio/translations",
body=maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(
Any, TranslationCreateResponse
), # Union types cannot be passed in as arguments in the type system
),
cast_to=Translation,
)


Expand All @@ -134,7 +139,7 @@ async def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Translation:
) -> TranslationCreateResponse:
"""
Translates audio into English.
Expand Down Expand Up @@ -180,14 +185,19 @@ async def create(
# sent to the server will contain a `boundary` parameter, e.g.
# multipart/form-data; boundary=---abc--
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
return await self._post(
"/openai/v1/audio/translations",
body=await async_maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
return cast(
TranslationCreateResponse,
await self._post(
"/openai/v1/audio/translations",
body=await async_maybe_transform(body, translation_create_params.TranslationCreateParams),
files=files,
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=cast(
Any, TranslationCreateResponse
), # Union types cannot be passed in as arguments in the type system
),
cast_to=Translation,
)


Expand Down
2 changes: 2 additions & 0 deletions src/groq/types/audio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from .transcription import Transcription as Transcription
from .translation_create_params import TranslationCreateParams as TranslationCreateParams
from .transcription_create_params import TranscriptionCreateParams as TranscriptionCreateParams
from .translation_create_response import TranslationCreateResponse as TranslationCreateResponse
from .transcription_create_response import TranscriptionCreateResponse as TranscriptionCreateResponse
Loading

0 comments on commit 53a8b27

Please sign in to comment.