vllm-test / app.py
Stanley Xu
add a simple vllm api application
2ae3a0e
raw
history blame contribute delete
829 Bytes
import openai
import gradio as gr
import os
openai.api_key = os.environ["SHOPPAL_VLLM_API_KEY"]
openai.api_base = os.environ["SHOPPAL_VLLM_API_URL"]
model_name = os.environ["SHOPPAL_VLLM_MODEL_NAME"]
def predict(message, history):
history_openai_format = []
for human, assistant in history:
history_openai_format.append({"role": "user", "content": human })
history_openai_format.append({"role": "assistant", "content":assistant})
history_openai_format.append({"role": "user", "content": message})
response = openai.ChatCompletion.create(
model=model_name,
messages= history_openai_format,
stop=[" Human:", " Assistant:"],
temperature=0.5,
max_tokens=2048,
)
return response.choices[0].message.content
gr.ChatInterface(predict).queue().launch()