vllm/examples/openai_client.py

24 lines
587 B
Python
Raw Normal View History

2023-05-23 21:39:50 -07:00
import openai
# Modify OpenAI's API key and API base to use CacheFlow's API server.
2023-05-23 21:39:50 -07:00
openai.api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1"
model = "facebook/opt-125m"
# Test list models API
2023-05-23 21:39:50 -07:00
models = openai.Model.list()
print("Models:", models)
2023-05-23 21:39:50 -07:00
# Test completion API
2023-05-23 21:39:50 -07:00
stream = True
completion = openai.Completion.create(
model=model, prompt="A robot may not injure a human being", echo=False, n=2,
best_of=3, stream=stream, logprobs=3)
# print the completion
if stream:
for c in completion:
print(c)
else:
print("Completion result:", completion)