Skip to content

Instantly share code, notes, and snippets.

@burgil
Last active April 26, 2024 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burgil/8d53f5f18612b811f6bfa93c4aba691b to your computer and use it in GitHub Desktop.
Save burgil/8d53f5f18612b811f6bfa93c4aba691b to your computer and use it in GitHub Desktop.
Python - use the OpenAI library with a local LLM (Ollama)
from openai import OpenAI
client = OpenAI(
base_url = 'http://localhost:11434/v1',
api_key='ollama', # required, but unused
)
response = client.chat.completions.create(
model="mistral",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The LA Dodgers won in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
print(response.choices[0].message.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment