#!/bin/env python3 # SPDX-License-Identifier: Apache-2.0 # derived from https://docs.vllm.ai/en/v0.8.1/getting_started/examples/openai_completion_client.html 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, ) import os stream = False # Completion API completion = client.completions.create( model=os.environ["MODEL"], prompt="A robot may not injure a human being", echo=False, n=2, stream=stream, logprobs=3) print("Completion results:") if stream: for c in completion: print(c) else: print(completion) completion = client.completions.create( model="myadapter", prompt="A robot may not injure a human being", echo=False, n=2, stream=stream, logprobs=3) print("Completion results:") if stream: for c in completion: print(c) else: print(completion)