Skip to content

Instantly share code, notes, and snippets.

@jfjensen
Created September 14, 2023 20:03
Show Gist options
  • Save jfjensen/147931f959d159144095b06e6f94cbc1 to your computer and use it in GitHub Desktop.
Save jfjensen/147931f959d159144095b06e6f94cbc1 to your computer and use it in GitHub Desktop.
Using the OpenAI Chat 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?"
messages = [{"role": "user", "content": prompt}]
chat_completion = openai.ChatCompletion.create(
model=model,
messages=messages,
echo=False,
max_tokens=1500,
temperature=0.0,
frequency_penalty=1.1)
question = messages[0]
answer = chat_completion["choices"][0]["message"]
print(f"{question['role']}: {question['content']}")
print(f"{answer['role']}: {answer['content']}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment