kenken999 commited on
Commit
f023718
·
1 Parent(s): b9d14d0
chat_history.db CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e52c7021bd429aa8758ed47b7a37e236b5f24ec7a5cc48ca38cfe70f374dec75
3
  size 1839104
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60480537d9f77b3681f5294e468a0bbfe35834401f3fd648a29631617f351bda
3
  size 1839104
controllers/gra_02_openInterpreter/OpenInterpreter.py CHANGED
@@ -120,6 +120,13 @@ def format_responses(chunk, full_response):
120
  # This function will format the response from the interpreter
121
  return full_response + chunk.get("content", "")
122
 
 
 
 
 
 
 
 
123
  def chat_with_interpreter(message, history=None, a=None, b=None, c=None, d=None):
124
  if message == "reset":
125
  interpreter.reset()
@@ -135,22 +142,17 @@ def chat_with_interpreter(message, history=None, a=None, b=None, c=None, d=None)
135
  user_entry = {"role": "user", "type": "message", "content": message}
136
  interpreter.messages.append(user_entry)
137
  add_message_to_db("user", "message", message)
138
- all_result = ""
139
- for chunk in interpreter.chat(message, display=False, stream=False):
140
- #if isinstance(chunk, dict):
141
- # full_response = format_response(chunk, full_response)
142
- #else:
143
- # raise TypeError("Expected chunk to be a dictionary")
144
 
 
 
 
 
145
 
146
- #print(full_response)
147
- #yield full_response
148
- \
149
- #for chunk in response:
150
- current_content = chunk.choices[0].delta.content or ""
151
- all_result += current_content
152
- yield current_content
153
- yield all_result
154
 
155
  assistant_entry = {"role": "assistant", "type": "message", "content": full_response}
156
  interpreter.messages.append(assistant_entry)
 
120
  # This function will format the response from the interpreter
121
  return full_response + chunk.get("content", "")
122
 
123
+ def ensure_triple_quotes(s):
124
+ if not (s.rstrip().endswith("'''") or s.rstrip().endswith('"""')):
125
+ s += "'''"
126
+ return s
127
+
128
+
129
+
130
  def chat_with_interpreter(message, history=None, a=None, b=None, c=None, d=None):
131
  if message == "reset":
132
  interpreter.reset()
 
142
  user_entry = {"role": "user", "type": "message", "content": message}
143
  interpreter.messages.append(user_entry)
144
  add_message_to_db("user", "message", message)
 
 
 
 
 
 
145
 
146
+ for chunk in interpreter.chat(message, display=False, stream=False):
147
+ if isinstance(chunk, dict):
148
+ full_response = format_response(chunk, full_response)
149
+ full_response = ensure_triple_quotes(full_response)
150
 
151
+ else:
152
+ raise TypeError("Expected chunk to be a dictionary")
153
+
154
+ print(full_response)
155
+ yield full_response
 
 
 
156
 
157
  assistant_entry = {"role": "assistant", "type": "message", "content": full_response}
158
  interpreter.messages.append(assistant_entry)