forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] Add chat completion Example and simplify dependencies (vllm-pro…
- Loading branch information
1 parent
df5dd3c
commit 82ad323
Showing
4 changed files
with
52 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import openai | ||
|
||
# Modify OpenAI's API key and API base to use vLLM's API server. | ||
openai.api_key = "EMPTY" | ||
openai.api_base = "http://localhost:8000/v1" | ||
|
||
# List models API | ||
models = openai.Model.list() | ||
print("Models:", models) | ||
|
||
model = models["data"][0]["id"] | ||
|
||
# Chat completion API | ||
chat_completion = openai.ChatCompletion.create( | ||
model=model, | ||
messages=[{ | ||
"role": "system", | ||
"content": "You are a helpful assistant." | ||
}, { | ||
"role": "user", | ||
"content": "Who won the world series in 2020?" | ||
}, { | ||
"role": | ||
"assistant", | ||
"content": | ||
"The Los Angeles Dodgers won the World Series in 2020." | ||
}, { | ||
"role": "user", | ||
"content": "Where was it played?" | ||
}]) | ||
|
||
print("Chat completion results:") | ||
print(chat_completion) |
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
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
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