soyleyicicem commited on
Commit
f4fd216
·
verified ·
1 Parent(s): f63d7ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -31
app.py CHANGED
@@ -52,7 +52,9 @@ def chat_gpt(prompt=None, history=[], model=model, client=client, tools=[None]):
52
  completion = client.chat.completions.create(
53
  model=model,
54
  messages=messages,
55
- tools=tools
 
 
56
  )
57
  return completion
58
 
@@ -232,44 +234,70 @@ def chat(question, manual, history, liked):
232
 
233
  """
234
  # conv = [{"role": "system", "content": f"{first_hop}"}]
235
- conv.append({"role": "system", "content": f"{first_hop}"})
 
 
 
 
236
  first_hop_response = chat_gpt(prompt=f"Soru: {question}", history=conv, tools=retrieval_functions)
237
- conv.append(first_hop_response.choices[-1].message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  print("First_hop:--- %s seconds ---" % (time.time() - start_time))
239
 
240
  path = "Contents/" + manual + ".json"
241
 
242
- start_time = time.time()
243
- i = 0
244
- while(i < 2):
245
- tool_calls = first_hop_response.choices[-1].message.tool_calls
246
- if tool_calls:
247
- for tool_call in tool_calls:
248
- function_name = tool_call.function.name
249
- args = json.loads(tool_call.function.arguments)
250
- print(f"Will call {function_name} with arguments {args}")
251
 
252
- if function_name == 'get_section_content':
253
- addition = get_section_content(str(args['section_title']), str(args['sub_section_title']), str(args['sub_sub_section_title']), content_path=path)
254
- if not addition:
255
- addition = ' '
256
 
257
- conv.append({
258
- "tool_call_id": tool_call.id,
259
- "role": "tool",
260
- "name": function_name,
261
- "content": addition
262
- })
263
- first_hop_response = chat_gpt(prompt=None, history=conv, tools=retrieval_functions)
264
- else:
265
- conv.append(first_hop_response.choices[-1].message)
266
- break
267
- i += 1
268
-
269
- print("Second_hop:--- %s seconds ---" % (time.time() - start_time))
270
-
271
  start_time = time.time()
272
- documents = retriever.invoke(question)
 
 
 
 
 
 
273
  print("Retriever:--- %s seconds ---" % (time.time() - start_time))
274
 
275
  start_time = time.time()
 
52
  completion = client.chat.completions.create(
53
  model=model,
54
  messages=messages,
55
+ tools=tools,
56
+ tool_choice="required",
57
+ temperature=0.0
58
  )
59
  return completion
60
 
 
234
 
235
  """
236
  # conv = [{"role": "system", "content": f"{first_hop}"}]
237
+ # conv.append({"role": "system", "content": f"{first_hop}"})
238
+ # first_hop_response = chat_gpt(prompt=f"Soru: {question}", history=conv, tools=retrieval_functions)
239
+ # conv.append(first_hop_response.choices[-1].message)
240
+
241
+ conv = [{"role": "system", "content": f"{first_hop}"}]
242
  first_hop_response = chat_gpt(prompt=f"Soru: {question}", history=conv, tools=retrieval_functions)
243
+
244
+ tool_calls = first_hop_response.choices[-1].message.tool_calls
245
+ arg_list = []
246
+ for i in range(3)
247
+
248
+ if tool_calls:
249
+ for tool_call in tool_calls:
250
+ function_name = tool_call.function.name
251
+ args = json.loads(tool_call.function.arguments)
252
+ arg_list.append(args)
253
+ print(f"Will call {function_name} with arguments {args}")
254
+ break
255
+ else:
256
+ conv = [{"role": "system", "content": f"{first_hop}"}]
257
+ first_hop_response = chat_gpt(prompt=f"Soru: {question}", history=conv, tools=retrieval_functions)
258
+ print("No tool calls")
259
+
260
  print("First_hop:--- %s seconds ---" % (time.time() - start_time))
261
 
262
  path = "Contents/" + manual + ".json"
263
 
264
+ # start_time = time.time()
265
+ # i = 0
266
+ # while(i < 2):
267
+ # tool_calls = first_hop_response.choices[-1].message.tool_calls
268
+ # if tool_calls:
269
+ # for tool_call in tool_calls:
270
+ # function_name = tool_call.function.name
271
+ # args = json.loads(tool_call.function.arguments)
272
+ # print(f"Will call {function_name} with arguments {args}")
273
 
274
+ # if function_name == 'get_section_content':
275
+ # addition = get_section_content(str(args['section_title']), str(args['sub_section_title']), str(args['sub_sub_section_title']), content_path=path)
276
+ # if not addition:
277
+ # addition = ' '
278
 
279
+ # conv.append({
280
+ # "tool_call_id": tool_call.id,
281
+ # "role": "tool",
282
+ # "name": function_name,
283
+ # "content": addition
284
+ # })
285
+ # first_hop_response = chat_gpt(prompt=None, history=conv, tools=retrieval_functions)
286
+ # else:
287
+ # conv.append(first_hop_response.choices[-1].message)
288
+ # break
289
+ # i += 1
290
+
291
+ # print("Second_hop:--- %s seconds ---" % (time.time() - start_time))
292
+
293
  start_time = time.time()
294
+ documents = []
295
+ for i in arg_list:
296
+ documents.append(get_section_content(str(args['section_title']), str(args['sub_section_title']), str(args['sub_sub_section_title']), content_path=path))
297
+
298
+ documents_db = retriever.invoke(question)
299
+ documents.append(documents_db)
300
+
301
  print("Retriever:--- %s seconds ---" % (time.time() - start_time))
302
 
303
  start_time = time.time()