kenken999 commited on
Commit
eca448f
1 Parent(s): 989091a
Files changed (2) hide show
  1. mysite/gradio/chat.py +2 -1
  2. mysite/libs/utilities.py +16 -1
mysite/gradio/chat.py CHANGED
@@ -6,7 +6,8 @@ import mysite.interpreter.interpreter_config # インポートするだけで
6
  import importlib
7
  import os
8
  import pkgutil
9
-
 
10
 
11
 
12
  DESCRIPTION = """
 
6
  import importlib
7
  import os
8
  import pkgutil
9
+ import async_timeout
10
+ import asyncio
11
 
12
 
13
  DESCRIPTION = """
mysite/libs/utilities.py CHANGED
@@ -73,8 +73,22 @@ def chat_with_interpreter(
73
  user_entry = {"role": "user", "type": "message", "content": message}
74
  #messages.append(user_entry)
75
  # Call interpreter.chat and capture the result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
 
77
- for chunk in interpreter.chat(message, display=False, stream=True):
78
  # print(chunk)
79
  # output = '\n'.join(item['content'] for item in result if 'content' in item)
80
  full_response = format_response(chunk, full_response)
@@ -155,6 +169,7 @@ async def completion(message: str, history, c=None, d=None):
155
  all_result += current_content
156
  yield current_content
157
  yield all_result
 
158
  except asyncio.TimeoutError:
159
  raise HTTPException(status_code=504, detail="Stream timed out")
160
 
 
73
  user_entry = {"role": "user", "type": "message", "content": message}
74
  #messages.append(user_entry)
75
  # Call interpreter.chat and capture the result
76
+ messages = []
77
+ recent_messages = history[-20:]
78
+ for conversation in recent_messages:
79
+ user_message = conversation[0]
80
+ user_entry = {"role": "user", "content": user_message}
81
+ messages.append(user_entry)
82
+ assistant_message = conversation[1]
83
+ assistant_entry = {"role": "assistant", "content": assistant_message}
84
+ messages.append(assistant_entry)
85
+
86
+ user_entry = {"role": "user", "content": message}
87
+ messages.append(user_entry)
88
+ #system_prompt = {"role": "system", "content": "あなたは日本語の優秀なアシスタントです。"}
89
+ #messages.insert(0, system_prompt)
90
 
91
+ for chunk in interpreter.chat(messages, display=False, stream=True):
92
  # print(chunk)
93
  # output = '\n'.join(item['content'] for item in result if 'content' in item)
94
  full_response = format_response(chunk, full_response)
 
169
  all_result += current_content
170
  yield current_content
171
  yield all_result
172
+ #return all_result
173
  except asyncio.TimeoutError:
174
  raise HTTPException(status_code=504, detail="Stream timed out")
175