2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-05-11 11:30:37 -07:00
|
|
|
from openai 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"
|
|
|
|
|
|
|
|
client = OpenAI(
|
|
|
|
# defaults to os.environ.get("OPENAI_API_KEY")
|
|
|
|
api_key=openai_api_key,
|
|
|
|
base_url=openai_api_base,
|
|
|
|
)
|
|
|
|
|
|
|
|
models = client.models.list()
|
|
|
|
model = models.data[0].id
|
|
|
|
|
2024-07-24 22:48:07 -07:00
|
|
|
responses = client.embeddings.create(
|
|
|
|
input=[
|
|
|
|
"Hello my name is",
|
|
|
|
"The best thing about vLLM is that it supports many different models"
|
|
|
|
],
|
|
|
|
model=model,
|
|
|
|
)
|
2024-05-11 11:30:37 -07:00
|
|
|
|
|
|
|
for data in responses.data:
|
|
|
|
print(data.embedding) # list of float of len 4096
|