desert commited on
Commit ·
408d189
1
Parent(s): b2af35c
init inference
Browse files14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464748495014 unmodified linestemperature,top_p,):messages = [{"role": "system", "content": system_message}]for val in history:if val[0]:messages.append({"role": "user", "content": val[0]})if val[1]:messages.append({"role": "assistant", "content": val[1]})messages.append({"role": "user", "content": message})response = ""for message in client.chat_completion(messages,max_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):token = message.choices[0].delta.contentresponse += tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),14 unmodified lines15161718192021222324252627282930313233343536373839404142434445464714 unmodified linestemperature,top_p,):# Combine the system message and chat history into a single stringprompt = system_message + "\n"for user_input, assistant_reply in history:if user_input:prompt += f"User: {user_input}\n"if assistant_reply:prompt += f"Assistant: {assistant_reply}\n"prompt += f"User: {message}\nAssistant:"# Send the request to the modelresponse = ""for token in client.text_generation(prompt,max_new_tokens=max_tokens,stream=True,temperature=temperature,top_p=top_p,):response += token.tokenyield response"""For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface"""demo = gr.ChatInterface(respond,type="messages",additional_inputs=[gr.Textbox(value="You are a friendly Chatbot.", label="System message"),gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
app.py+15-18