Skip to content
Snippets Groups Projects
Commit 9beafe1c authored by Jan Frenzel's avatar Jan Frenzel
Browse files

Add base example

parent bcd337e0
No related branches found
No related tags found
1 merge request!1Base example
# Base functionality
This example intends to show you how to:
- list models
- select and use the first model with "llama" in its name to display a joke
## Installation
Do the following steps in your bash shell:
```bash
python3 -m venv myenv
source myenv/bin/activate
pip install -r requirements.txt
```
## Usage
1. Put your API key in the file `my_key`.
2. Then simply start the script `main.py` from your bash shell:
```bash
source myenv/bin/activate
./main.py
```
3. Read the joke.
#!/usr/bin/env python
# Find instructions how to install dependencies and how to run this script in README.md
from openai import OpenAI
my_api_key = ""
with open("my_key") as keyfile:
my_api_key = keyfile.readline()[:-1]
client = OpenAI(base_url="https://llm.scads.ai/v1",api_key=my_api_key)
# Get models
print("""
Available models:
""")
for model in client.models.list().data:
print(model.id)
# Find model with "llama" in name
for model in client.models.list().data:
model_name = model.id
if "llama" in model_name:
break
# Use model
response = client.chat.completions.create(messages=[{"role":"user","content":"Tell me a joke!"}],model=model_name)
# Print the joke
print("""
Your joke:
""")
joke = response.choices[0].message.content
print(joke)
openai
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment