"integration-tests/vscode:/vscode.git/clone" did not exist on "2e4f4ba1bb0c656e19d01e268573fdbfaf5f7705"
Unverified Commit c07a4428 authored by Massimiliano Pronesti's avatar Massimiliano Pronesti Committed by GitHub
Browse files

chore(examples-docs): upgrade to OpenAI V1 (#1785)

parent cd3aa153
...@@ -157,11 +157,16 @@ Since this server is compatible with OpenAI API, you can use it as a drop-in rep ...@@ -157,11 +157,16 @@ Since this server is compatible with OpenAI API, you can use it as a drop-in rep
.. code-block:: python .. code-block:: python
import openai from openai import OpenAI
# Modify OpenAI's API key and API base to use vLLM's API server. # Modify OpenAI's API key and API base to use vLLM's API server.
openai.api_key = "EMPTY" openai_api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1" openai_api_base = "http://localhost:8000/v1"
completion = openai.Completion.create(model="facebook/opt-125m", client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
completion = client.completions.create(model="facebook/opt-125m",
prompt="San Francisco is a") prompt="San Francisco is a")
print("Completion result:", completion) print("Completion result:", completion)
...@@ -194,11 +199,17 @@ Using the `openai` python package, you can also communicate with the model in a ...@@ -194,11 +199,17 @@ Using the `openai` python package, you can also communicate with the model in a
.. code-block:: python .. code-block:: python
import openai from openai import OpenAI
# Set OpenAI's API key and API base to use vLLM's API server. # Set OpenAI's API key and API base to use vLLM's API server.
openai.api_key = "EMPTY" openai_api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1" openai_api_base = "http://localhost:8000/v1"
chat_response = openai.ChatCompletion.create(
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
chat_response = client.chat.completions.create(
model="facebook/opt-125m", model="facebook/opt-125m",
messages=[ messages=[
{"role": "system", "content": "You are a helpful assistant."}, {"role": "system", "content": "You are a helpful assistant."},
......
import openai from openai import OpenAI
# Modify OpenAI's API key and API base to use vLLM's API server. # Modify OpenAI's API key and API base to use vLLM's API server.
openai.api_key = "EMPTY" openai_api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1" openai_api_base = "http://localhost:8000/v1"
# List models API client = OpenAI(
models = openai.Model.list() # defaults to os.environ.get("OPENAI_API_KEY")
print("Models:", models) api_key=openai_api_key,
base_url=openai_api_base,
)
model = models["data"][0]["id"] models = client.models.list()
model = models.data[0].id
# Chat completion API chat_completion = client.chat.completions.create(
chat_completion = openai.ChatCompletion.create(
model=model,
messages=[{ messages=[{
"role": "system", "role": "system",
"content": "You are a helpful assistant." "content": "You are a helpful assistant."
...@@ -27,7 +28,10 @@ chat_completion = openai.ChatCompletion.create( ...@@ -27,7 +28,10 @@ chat_completion = openai.ChatCompletion.create(
}, { }, {
"role": "user", "role": "user",
"content": "Where was it played?" "content": "Where was it played?"
}]) }],
model=model,
)
print("Chat completion results:") print("Chat completion results:")
print(chat_completion) print(chat_completion)
import openai from openai import OpenAI
# Modify OpenAI's API key and API base to use vLLM's API server. # Modify OpenAI's API key and API base to use vLLM's API server.
openai.api_key = "EMPTY" openai_api_key = "EMPTY"
openai.api_base = "http://localhost:8000/v1" openai_api_base = "http://localhost:8000/v1"
# List models API client = OpenAI(
models = openai.Model.list() # defaults to os.environ.get("OPENAI_API_KEY")
print("Models:", models) api_key=openai_api_key,
base_url=openai_api_base,
)
model = models["data"][0]["id"] models = client.models.list()
model = models.data[0].id
# Completion API # Completion API
stream = False stream = False
completion = openai.Completion.create( completion = client.completions.create(
model=model, model=model,
prompt="A robot may not injure a human being", prompt="A robot may not injure a human being",
echo=False, echo=False,
n=2, n=2,
stream=stream, stream=stream,
logprobs=3) logprobs=3
)
print("Completion results:") print("Completion results:")
if stream: if stream:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment