Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed May 6, 2024
1 parent 0b5e3f0 commit 5ca3b78
Show file tree
Hide file tree
Showing 66 changed files with 1,524 additions and 773 deletions.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: 0.24.0
RYE_INSTALL_OPTION: "--yes"
RYE_INSTALL_OPTION: '--yes'

- name: Install dependencies
run: |
Expand All @@ -39,3 +39,24 @@ jobs:
- name: Ensure importable
run: |
rye run python -c 'import groq'
test:
name: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Rye
run: |
curl -sSf https://rye-up.com/get | bash
echo "$HOME/.rye/shims" >> $GITHUB_PATH
env:
RYE_VERSION: 0.24.0
RYE_INSTALL_OPTION: '--yes'

- name: Bootstrap
run: ./scripts/bootstrap

- name: Run tests
run: ./scripts/test

2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Rye
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
if: github.repository == 'groq/groq-python' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Check release environment
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist
.env
.envrc
codegen.log
Brewfile.lock.json
1 change: 1 addition & 0 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/groqcloud%2Fgroqcloud-0a3089666368ff1ff668f2a73ea3b40d8b20420d8403a18579a1168dd67f2220.yml
2 changes: 2 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
brew "rye"

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Most tests require you to [set up a mock server](https://github.com/stoplightio/

```bash
# you will need npm installed
npx prism path/to/your/openapi.yml
npx prism mock path/to/your/openapi.yml
```

```bash
Expand Down Expand Up @@ -121,5 +121,5 @@ You can release to package managers by using [the `Publish PyPI` GitHub action](

### Publish manually

If you need to manually release a package, you can run the `bin/publish-pypi` script with an `PYPI_TOKEN` set on
If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on
the environment.
66 changes: 47 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The Groq Python library provides convenient access to the Groq REST API from any
application. The library includes type definitions for all request params and response fields,
and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).

It is generated with [Stainless](https://www.stainlessapi.com/).

## Documentation

The REST API documentation can be found [on console.groq.com](https://console.groq.com/docs). The full API of this library can be found in [api.md](api.md).
Expand All @@ -22,13 +24,9 @@ pip install groq
The full API of this library can be found in [api.md](api.md).

```python
import os
from groq import Groq

client = Groq(
# This is the default and can be omitted
api_key=os.environ.get("GROQ_API_KEY"),
)
client = Groq()

chat_completion = client.chat.completions.create(
messages=[
Expand All @@ -39,7 +37,7 @@ chat_completion = client.chat.completions.create(
],
model="mixtral-8x7b-32768",
)
print(chat_completion.choices[0].message.content)
print(chat_completion.choices_0.message.content)
```

While you can provide an `api_key` keyword argument,
Expand All @@ -52,14 +50,10 @@ so that your API Key is not stored in source control.
Simply import `AsyncGroq` instead of `Groq` and use `await` with each API call:

```python
import os
import asyncio
from groq import AsyncGroq

client = AsyncGroq(
# This is the default and can be omitted
api_key=os.environ.get("GROQ_API_KEY"),
)
client = AsyncGroq()


async def main() -> None:
Expand All @@ -72,7 +66,7 @@ async def main() -> None:
],
model="mixtral-8x7b-32768",
)
print(chat_completion.choices[0].message.content)
print(chat_completion.choices_0.message.content)


asyncio.run(main())
Expand All @@ -82,10 +76,10 @@ Functionality between the synchronous and asynchronous clients is otherwise iden

## Using types

Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev), which provide helper methods for things like:
Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:

- Serializing back into JSON, `model.model_dump_json(indent=2, exclude_unset=True)`
- Converting to a dictionary, `model.model_dump(exclude_unset=True)`
- Serializing back into JSON, `model.to_json()`
- Converting to a dictionary, `model.to_dict()`

Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.

Expand Down Expand Up @@ -195,7 +189,7 @@ client = Groq(
)

# Override per-request:
client.with_options(timeout=5 * 1000).chat.completions.create(
client.with_options(timeout=5.0).chat.completions.create(
messages=[
{
"role": "system",
Expand Down Expand Up @@ -294,6 +288,41 @@ with client.chat.completions.with_streaming_response.create(

The context manager is required so that the response will reliably be closed.

### Making custom/undocumented requests

This library is typed for convenient access to the documented API.

If you need to access undocumented endpoints, params, or response properties, the library can still be used.

#### Undocumented endpoints

To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
http verbs. Options on the client will be respected (such as retries) will be respected when making this
request.

```py
import httpx

response = client.post(
"/foo",
cast_to=httpx.Response,
body={"my_param": True},
)

print(response.headers.get("x-foo"))
```

#### Undocumented request params

If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
options.

#### Undocumented response properties

To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
can also get all the extra fields on the Pydantic model as a dict with
[`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).

### Configuring the HTTP client

You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
Expand All @@ -303,13 +332,12 @@ You can directly override the [httpx client](https://www.python-httpx.org/api/#c
- Additional [advanced](https://www.python-httpx.org/advanced/#client-instances) functionality

```python
import httpx
from groq import Groq
from groq import Groq, DefaultHttpxClient

client = Groq(
# Or use the `GROQ_BASE_URL` env var
base_url="http:https://my.test.server.example.com:8083",
http_client=httpx.Client(
http_client=DefaultHttpxClient(
proxies="http:https://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
Expand Down
40 changes: 0 additions & 40 deletions bin/check-env-state.py

This file was deleted.

50 changes: 0 additions & 50 deletions bin/check-test-server

This file was deleted.

3 changes: 0 additions & 3 deletions bin/test

This file was deleted.

Loading

0 comments on commit 5ca3b78

Please sign in to comment.