OpenAI Completion Client
Source vllm-project/vllm.
1from openai import OpenAI23# Modify OpenAI's API key and API base to use vLLM's API server.4openai_api_key = "EMPTY"5openai_api_base = "http://localhost:8000/v1"67client = OpenAI(8 # defaults to os.environ.get("OPENAI_API_KEY")9 api_key=openai_api_key,10 base_url=openai_api_base,11)1213models = client.models.list()14model = models.data[0].id1516# Completion API17stream = False18completion = client.completions.create(19 model=model,20 prompt="A robot may not injure a human being",21 echo=False,22 n=2,23 stream=stream,24 logprobs=3)2526print("Completion results:")27if stream:28 for c in completion:29 print(c)30else:31 print(completion)