Created
May 21, 2024 00:03
-
-
Save cyyeh/b1042006b4ca067f2a75abd97e3749fb to your computer and use it in GitHub Desktop.
Test Ollama using OpenAI compatible API
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( | |
api_key='ollama', | |
base_url="http://localhost:11434/v1", | |
) | |
# this will fail, showing openai.NotFoundError: 404 page not found | |
data = client.embeddings.create( | |
input='hi', | |
model='nomic-embed-text', | |
dimensions=768 | |
) | |
print(data) | |
# this will succeed | |
data = client.chat.completions.create( | |
model='llama3:8b', | |
messages=[ | |
{ | |
"role": "system", | |
"content": "You are a helpful assistant." | |
}, | |
{ | |
"role": "user", | |
"content": "What is the capital of the United States?" | |
} | |
] | |
) | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment