import os from together import Together import gradio as gr demo = None #added to allow restart system_prompt = """You are a reservation assistant for a hotel. Talk to customers and help them make, modify, or cancel reservations. For new reaservations, get the check-in date, check-out date, number of guests, and number of rooms.\ For modifications, get the reservation number and the new check-in date, check-out date, number of guests, and number of rooms. \ For cancellations, get the reservation number.\ """ def start_game(main_loop, share=False): # added code to support restart global demo # If demo is already running, close it first if demo is not None: demo.close() demo = gr.ChatInterface( main_loop, chatbot=gr.Chatbot(height=250, placeholder="I can help you with reservations"), textbox=gr.Textbox(placeholder="Look around", container=False, scale=7), title="Reservations", # description="Ask Yes Man any question", theme="soft", examples=["Make a new reservation", "Cancel a reservation", "Modify and existing reservation"], cache_examples=False, retry_btn="Retry", undo_btn="Undo", clear_btn="Clear", ) demo.launch(share=share, server_name="0.0.0.0") client = Together(api_key=os.getenv('TOGETHER_API_KEY')) def run_action(message, history): messages = [ {"role": "system", "content": system_prompt}, ] for action in history: messages.append({"role": "assistant", "content": action[0]}) messages.append({"role": "user", "content": action[1]}) messages.append({"role": "user", "content": message}) model_output = client.chat.completions.create( model="meta-llama/Llama-3-70b-chat-hf", messages=messages ) result = model_output.choices[0].message.content return result def main_loop(message, history): return run_action(message, history) start_game(main_loop, False)