File size: 829 Bytes
2ae3a0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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()