Spaces:
Sleeping
Sleeping
Test2
Browse files43 unmodified lines4445464748495051525354555657585960613 unmodified lines6566676869707143 unmodified lines"- Always prioritize short, snappy interactions so the user can type back and forth quickly.")def predict(message, history, selected_model):# Initialize messages with your system promptmessages = [{"role": "system", "content": SYSTEM_PROMPT}]# Format the existing chat history to match the API structurefor user_msg, assistant_msg in history:messages.append({"role": "user", "content": user_msg})messages.append({"role": "assistant", "content": assistant_msg})messages.append({"role": "user", "content": message})try:# Pass the 'selected_model' dynamically from the dropdownresponse = client.chat.completions.create(model=selected_model,messages=messages,3 unmodified lines)return response.choices[0].message.contentexcept Exception as e:return f"[Error]: {str(e)} - The model might be temporarily busy. Try selecting another one!"# Custom Layout to incorporate the Model Dropdown and Chatwith gr.Blocks() as gradio_app:43 unmodified lines44454647484950515253545556575859603 unmodified lines6465666768697043 unmodified lines"- Always prioritize short, snappy interactions so the user can type back and forth quickly.")def predict(message, history, selected_model):# 1. Initialize messages with your system promptmessages = [{"role": "system", "content": SYSTEM_PROMPT}]# 2. Gradio history is already a list of {"role": "...", "content": "..."} dicts!# Just extend your messages list with it.messages.extend(history)# 3. Add the current messagemessages.append({"role": "user", "content": message})try:response = client.chat.completions.create(model=selected_model,messages=messages,3 unmodified lines)return response.choices[0].message.contentexcept Exception as e:return f"[Error]: {str(e)}"# Custom Layout to incorporate the Model Dropdown and Chatwith gr.Blocks() as gradio_app:
app.py+8-9