"vllm/vscode:/vscode.git/clone" did not exist on "86ee94912896d1ea251d42e7cf7350f9a32b32ca"
openai_embedding_client.py 644 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

16
17
18
19
20
21
22
23
responses = client.embeddings.create(
    input=[
        "Hello my name is",
        "The best thing about vLLM is that it supports many different models"
    ],
    model=model,
    encoding_format="float",
)
24
25
26

for data in responses.data:
    print(data.embedding)  # list of float of len 4096