Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OpenAI example in README.md. #282

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,32 @@ async def chat():
asyncio.run(chat())
```

## OpenAI client

Install [openai-python](https://github.com/openai/openai-python)

```sh
pip install openai
```

```python
from openai import OpenAI

client = OpenAI(
api_key = 'not required',
base_url = 'http://localhost:11434/v1'
)

completion = client.chat.completions.create(
model = 'llama3.1',
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello! Are you there?"}
]
)
print(completion.choices[0].message.content)
```

## Errors

Errors are raised if requests return an error status or if an error is detected while streaming.
Expand Down