Skip to content

Commit

Permalink
Create openai.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitprasad15 authored Nov 7, 2024
1 parent 724cbfe commit fcdd672
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions guides/openai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# OpenAI

To use OpenAI with `aisuite`, you’ll need an [OpenAI account](https://platform.openai.com/). After logging in, go to the [API Keys](https://platform.openai.com/account/api-keys) section in your account settings and generate a new key. Once you have your key, add it to your environment as follows:

```shell
export OPENAI_API_KEY="your-openai-api-key"
```

## Create a Chat Completion

Install the `openai` Python client:

Example with pip:
```shell
pip install openai
```

Example with poetry:
```shell
poetry add openai
```

In your code:
```python
import aisuite as ai
client = ai.Client()

provider = "openai"
model_id = "gpt-4-turbo"

messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What’s the weather like in San Francisco?"},
]

response = client.chat.completions.create(
model=f"{provider}:{model_id}",
messages=messages,
)

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

Happy coding! If you’d like to contribute, please read our [Contributing Guide](CONTRIBUTING.md).

0 comments on commit fcdd672

Please sign in to comment.