mirror of
https://github.com/katanemo/plano.git
synced 2026-07-11 16:12:13 +02:00
move demo functions out of model_server (#67)
* pending * remove * fix docker build
This commit is contained in:
parent
ca5c9e4824
commit
31f26ef7ac
9 changed files with 122 additions and 50 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import os
|
||||
from openai import OpenAI
|
||||
import gradio as gr
|
||||
import logging as log
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
|
@ -9,6 +10,8 @@ OPEN_API_KEY=os.getenv("OPENAI_API_KEY")
|
|||
CHAT_COMPLETION_ENDPOINT = os.getenv("CHAT_COMPLETION_ENDPOINT")
|
||||
MODEL_NAME = os.getenv("MODEL_NAME", "gpt-3.5-turbo")
|
||||
|
||||
log.info("CHAT_COMPLETION_ENDPOINT: ", CHAT_COMPLETION_ENDPOINT)
|
||||
|
||||
client = OpenAI(api_key=OPEN_API_KEY, base_url=CHAT_COMPLETION_ENDPOINT)
|
||||
|
||||
def predict(message, history):
|
||||
|
|
@ -17,16 +20,20 @@ def predict(message, history):
|
|||
# history_openai_format.append({"role": "user", "content": human })
|
||||
# history_openai_format.append({"role": "assistant", "content":assistant})
|
||||
history.append({"role": "user", "content": message})
|
||||
log.info("CHAT_COMPLETION_ENDPOINT: ", CHAT_COMPLETION_ENDPOINT)
|
||||
log.info("history: ", history)
|
||||
|
||||
try:
|
||||
response = client.chat.completions.create(model='gpt-3.5-turbo',
|
||||
response = client.chat.completions.create(model=MODEL_NAME,
|
||||
messages= history,
|
||||
temperature=1.0
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
log.info(e)
|
||||
# remove last user message in case of exception
|
||||
history.pop()
|
||||
log.info("CHAT_COMPLETION_ENDPOINT: ", CHAT_COMPLETION_ENDPOINT)
|
||||
log.info("Error with OpenAI API: {}".format(e.message))
|
||||
raise gr.Error("Error with OpenAI API: {}".format(e.message))
|
||||
|
||||
# for chunk in response:
|
||||
|
|
@ -52,4 +59,4 @@ with gr.Blocks(fill_height=True, css="footer {visibility: hidden}") as demo:
|
|||
|
||||
txt.submit(predict, [txt, state], [chatbot, state])
|
||||
|
||||
demo.launch(server_name="0.0.0.0", server_port=8080, show_error=True)
|
||||
demo.launch(server_name="0.0.0.0", server_port=8080, show_error=True, debug=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue