ankush13r commited on
Commit
3721bf6
·
verified ·
1 Parent(s): 13b7887

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -6,6 +6,8 @@ from openai import OpenAI
6
  from tools import tools, oitools
7
  from dotenv import load_dotenv
8
  import os
 
 
9
  load_dotenv(".env")
10
  HF_TOKEN = os.environ["HF_TOKEN"]
11
  BASE_URL = os.environ["BASE_URL"]
@@ -21,6 +23,10 @@ client = OpenAI(
21
  )
22
 
23
 
 
 
 
 
24
  def complation(history, model, system_prompt, tools=None):
25
  messages = [{"role": "system", "content": system_prompt}]
26
  for msg in history:
@@ -108,8 +114,9 @@ def respond(
108
 
109
  if not arguments:
110
  arguments = "{}"
111
- elif arguments.strip() == "} }" or arguments.strip() == "}}":
112
- arguments = arguments.strip()[:-1]
 
113
  if name:
114
  result = f"💥 Error using tool {name}, tools doesn't exists"
115
  print("arguments:", arguments)
 
6
  from tools import tools, oitools
7
  from dotenv import load_dotenv
8
  import os
9
+ import re
10
+
11
  load_dotenv(".env")
12
  HF_TOKEN = os.environ["HF_TOKEN"]
13
  BASE_URL = os.environ["BASE_URL"]
 
23
  )
24
 
25
 
26
+ def clean_json_string(json_str):
27
+ # Strip spaces and '}' from the end, then add back a single '}'
28
+ return re.sub(r'[ }\s]+$', '', json_str) + '}'
29
+
30
  def complation(history, model, system_prompt, tools=None):
31
  messages = [{"role": "system", "content": system_prompt}]
32
  for msg in history:
 
114
 
115
  if not arguments:
116
  arguments = "{}"
117
+ else:
118
+ arguments = clean_json_string(arguments)
119
+
120
  if name:
121
  result = f"💥 Error using tool {name}, tools doesn't exists"
122
  print("arguments:", arguments)