Skip to content

Commit

Permalink
chore: Update examples in README.md and completions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
herumes committed Jun 9, 2024
1 parent f541350 commit 29cf392
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ poetry install

## Getting Started

Below are some basic streaming examples for the ShuttleAI API. You can find more examples in the `examples/` directory.
Below is a non-streamed sync and async example for the ShuttleAI API. You can find more examples in the `examples/` directory.

### Synchronous Client

Expand All @@ -44,11 +44,12 @@ from shuttleai import ShuttleAI

shuttleai = ShuttleAI()

for chunk in shuttleai.chat.completions.create(
messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
stream=True
):
print(chunk.choices[0].delta.content, end="", flush=True)
response = shuttleai.chat.completions.create(
model="shuttle-2-turbo",
messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
)

print(chunk.choices[0].message.content)
```

### Asynchronous Client
Expand All @@ -60,11 +61,12 @@ from shuttleai import AsyncShuttleAI
async def main():
shuttleai = AsyncShuttleAI()

async for chunk in shuttleai.chat.completions.create(
response = await shuttleai.chat.completions.create(
model="shuttle-2-turbo",
messages=[{"role": "user", "content": "Imagine an AI like no other, its name is ShuttleAI."}],
stream=True
):
print(chunk.choices[0].delta.content, end="", flush=True)
)

print(response.choices[0].message.content)

asyncio.run(main())
```
Expand Down Expand Up @@ -107,6 +109,12 @@ After you have an API key, you can set it as an environment variable:
```s
setx SHUTTLEAI_API_KEY "<your_api_key>"
```
[!Note]
This will only work in the current terminal session. To set it permanently, you can use the `setx` command with the `/m` flag.

```s
setx SHUTTLEAI_API_KEY "<your_api_key>" /m
```

### macOS/Linux

Expand Down

0 comments on commit 29cf392

Please sign in to comment.