Last active
April 26, 2024 21:03
-
-
Save burgil/8d53f5f18612b811f6bfa93c4aba691b to your computer and use it in GitHub Desktop.
Python - use the OpenAI library with a local LLM (Ollama)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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