ankush13r commited on
Commit
80b38e7
·
verified ·
1 Parent(s): 163361e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -10,8 +10,7 @@ load_dotenv(".env")
10
  HF_TOKEN = os.environ["HF_TOKEN"]
11
  BASE_URL = os.environ["BASE_URL"]
12
 
13
- SYSTEM_PROMPT_TEMPLATE = """
14
- You are an AI assistant designed to assist users with a hotel booking and information system. Your role is to provide detailed and accurate information about the hotel, including available accommodations, facilities, dining options, and reservation services. You can check room availability, assist with bookings, modify or cancel reservations, and answer general inquiries about the hotel.
15
 
16
  Maintain clarity, conciseness, and relevance in your responses, ensuring a seamless user experience. Always respond in the same **language as the user’s query** to preserve their preferred language.
17
  """
@@ -22,8 +21,7 @@ client = OpenAI(
22
  )
23
 
24
 
25
- def complation(history, model, tools=None):
26
- system_prompt = SYSTEM_PROMPT_TEMPLATE
27
  messages = [{"role": "system", "content": system_prompt}]
28
  for msg in history:
29
  if type(msg) == dict:
@@ -66,6 +64,7 @@ def complation(history, model, tools=None):
66
  def respond(
67
  message:any,
68
  history:any,
 
69
  ):
70
  try:
71
  models = client.models.list()
@@ -83,7 +82,7 @@ def respond(
83
  content=message,
84
  )
85
  )
86
- completion = complation(history=history, tools=oitools, model=model)
87
  appended = False
88
  for chunk in completion:
89
  if len(chunk.choices) > 0 and chunk.choices[0].delta.tool_calls and len(chunk.choices[0].delta.tool_calls) > 0 :
@@ -119,13 +118,13 @@ def respond(
119
  ChatMessage(
120
  role="assistant",
121
  content=result,
122
- metadata= {"title": f"🛠️ Used tool '{name}'"},
123
  options=[{"label":"tool_calls", "value": json.dumps([{"id": "call_FthC9qRpsL5kBpwwyw6c7j4k","function": {"arguments": arguments,"name": name},"type": "function"}])}]
124
  )
125
  )
126
  yield history[-1]
127
 
128
- completion = complation(history=history, tools=oitools, model=model)
129
  result = ""
130
  appended = False
131
  for chunk in completion:
@@ -146,5 +145,6 @@ def respond(
146
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
147
  """
148
  if __name__ == "__main__":
149
- demo = gr.ChatInterface(respond, type="messages")
150
- demo.launch()
 
 
10
  HF_TOKEN = os.environ["HF_TOKEN"]
11
  BASE_URL = os.environ["BASE_URL"]
12
 
13
+ SYSTEM_PROMPT_TEMPLATE = """You are an AI assistant designed to assist users with a hotel booking and information system. Your role is to provide detailed and accurate information about the hotel, including available accommodations, facilities, dining options, and reservation services. You can check room availability, assist with bookings, modify or cancel reservations, and answer general inquiries about the hotel.
 
14
 
15
  Maintain clarity, conciseness, and relevance in your responses, ensuring a seamless user experience. Always respond in the same **language as the user’s query** to preserve their preferred language.
16
  """
 
21
  )
22
 
23
 
24
+ def complation(history, model, system_prompt, tools=None):
 
25
  messages = [{"role": "system", "content": system_prompt}]
26
  for msg in history:
27
  if type(msg) == dict:
 
64
  def respond(
65
  message:any,
66
  history:any,
67
+ system_propmt,
68
  ):
69
  try:
70
  models = client.models.list()
 
82
  content=message,
83
  )
84
  )
85
+ completion = complation(history=history, tools=oitools, model=model, system_propmt=system_propmt)
86
  appended = False
87
  for chunk in completion:
88
  if len(chunk.choices) > 0 and chunk.choices[0].delta.tool_calls and len(chunk.choices[0].delta.tool_calls) > 0 :
 
118
  ChatMessage(
119
  role="assistant",
120
  content=result,
121
+ metadata= {"title": f"🛠️ Used tool '{name}', arguments: {json.dumps(json_arguments, ensure_ascii=False)}"},
122
  options=[{"label":"tool_calls", "value": json.dumps([{"id": "call_FthC9qRpsL5kBpwwyw6c7j4k","function": {"arguments": arguments,"name": name},"type": "function"}])}]
123
  )
124
  )
125
  yield history[-1]
126
 
127
+ completion = complation(history=history, tools=oitools, model=model, system_prompt=system_prompt)
128
  result = ""
129
  appended = False
130
  for chunk in completion:
 
145
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
146
  """
147
  if __name__ == "__main__":
148
+ system_prompt = gr.Textbox(label="System propmt", value=SYSTEM_PROMPT_TEMPLATE, lines=3)
149
+ demo = gr.ChatInterface(respond, type="messages", additional_inputs=[system_prompt])
150
+ demo.launch()