Skip to content

Instantly share code, notes, and snippets.

@jfjensen
Created September 14, 2023 20:01
Show Gist options
  • Save jfjensen/1205d4444a565d4d77ebe46d94c00e39 to your computer and use it in GitHub Desktop.
Save jfjensen/1205d4444a565d4d77ebe46d94c00e39 to your computer and use it in GitHub Desktop.
Using the OpenAI API to access an LLM on a vLLM server
import openai
base_url = "http://localhost:9999/v1"
openai.api_key = "***"
openai.api_base = base_url
models = openai.Model.list()
model = models["data"][0]["id"]
print(f"model: {model}")
prompt = "What is the capital of France?"
stream = False
completion = openai.Completion.create(
model=model,
prompt=prompt,
echo=False,
max_tokens=1500,
temperature=0.0,
frequency_penalty=1.1,
stream=stream)
print(completion["choices"][0]["text"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment