try vscode plugin
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
import json
|
||||
from flask import current_app, request, session
|
||||
from flask_socketio import Namespace, join_room, leave_room, emit
|
||||
|
||||
from ..function_tools import judge
|
||||
from ..services.memory_service import save_chapter_memory_by_uuid
|
||||
from ..services.backboard_service import realtime_response
|
||||
from ..services.markdown_service import load_full_markdown_file
|
||||
from ..extension_ase.ase_client import ASEngineClient
|
||||
from ..extension_ase.ase_client import HSAEngineClient, ChatManager
|
||||
|
||||
|
||||
class VSCodeNamespace(Namespace):
|
||||
def on_login(self,data):
|
||||
@@ -50,32 +53,32 @@ class AgentNamespace(Namespace):
|
||||
user_id = uuid2username[user_uuid]
|
||||
session['user_uuid'] = user_uuid
|
||||
print(f'User connected with session user_uuid: {user_uuid}')
|
||||
user_uuid2chatmanager = ex["user_uuid2chatmanager"]
|
||||
user_uuid2ase_client = ex["user_uuid2ase_client"]
|
||||
user_uuid2ase_client[user_uuid] = ASEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"])
|
||||
user_uuid2ase_client[user_uuid] = HSAEngineClient(current_app.config["ASE_ENGINE_URL"], current_app.config["ASE_ENGINE_NAMESPACE"])
|
||||
user_uuid2ase_client[user_uuid].connect()
|
||||
user_uuid2ase_client[user_uuid].register_route_with_entry(
|
||||
route='dialog',
|
||||
callback=self.receive_ase_dialog,
|
||||
entry=self, # 传你的 Namespace 对象
|
||||
init_data={'room': user_uuid} # 想传啥都可以
|
||||
entry=self,
|
||||
init_data={'room': user_uuid}
|
||||
)
|
||||
|
||||
fmd,fmdp,fsp = load_full_markdown_file(course_id, chapter_name, lesson_name)
|
||||
# 从markdown、markdown_prompts、score_prompts中各读取数据folder.md并进行new_agent
|
||||
user_uuid2chatmanager[user_uuid] = ChatManager(user_uuid, user_uuid2ase_client[user_uuid], fmd, fmdp, fsp, max_iter=5, app=current_app, socketio=self)
|
||||
chatmanager = user_uuid2chatmanager[user_uuid]
|
||||
chatmanager.function_manager.add_function(judge, {'course_id': course_id, 'lesson_name': lesson_name, 'root_path': f'../../study/{user_id}/{course_id}/{chapter_name}/{lesson_name}'})
|
||||
|
||||
user_uuid, agent = agent_manager.new_agent(course_id, lesson_name, fmd, fmdp, fsp, id=user_uuid,
|
||||
root_path=f'../../study/{user_id}/{course_id}/{chapter_name}/{lesson_name}')
|
||||
print(user_uuid)
|
||||
user_uuid2ase_client[user_uuid].loadmarkdown(fmd, fmdp, fsp)
|
||||
|
||||
join_room(user_uuid, namespace='/agent') # 将该用户加入以user_id为名的room
|
||||
backboard_manager.add_backboard(user_uuid, user_id, course_id, lesson_name, root_path=f'../../study/{user_id}/{course_id}/{chapter_name}/{lesson_name}')
|
||||
|
||||
chatmanager.focus_chapter(0)
|
||||
|
||||
def on_language(self, language):
|
||||
ex = current_app.extensions
|
||||
agent_manager = ex["agent_manager"]
|
||||
uuid2username = ex["uuid2username"]
|
||||
uuid = session.get('user_uuid')
|
||||
user_id = uuid2username[uuid]
|
||||
agent_manager.change_language(uuid, language)
|
||||
print(f"Language changed to: {language}")
|
||||
|
||||
def on_message(self, data):
|
||||
print(f"Message from client: {data}")
|
||||
@@ -89,7 +92,6 @@ class AgentNamespace(Namespace):
|
||||
if (type(data)==str):
|
||||
data = json.loads(data)
|
||||
if data['type'] == 'text':
|
||||
# res = agent_manager.invoke(uuid, data['data'], backboard_manager.get_backboard(uuid).get_info_prompt())
|
||||
user_uuid2ase_client[uuid].send_text('dialog', data['data'])
|
||||
# print('=*='*20)
|
||||
# print(res.content)
|
||||
@@ -102,12 +104,11 @@ class AgentNamespace(Namespace):
|
||||
agent_manager.function_call(uuid, data['data'])
|
||||
|
||||
|
||||
def receive_ase_dialog(client_entry: ASEngineClient, namespace_entry: Namespace, data, init_data):
|
||||
print(f"Received from ASEngine: {data}")
|
||||
# 直接使用 entry(也就是你的 Namespace 对象)
|
||||
def receive_ase_dialog(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||
namespace_entry.emit('message', data['data'], room=init_data['room'], namespace='/agent')
|
||||
|
||||
|
||||
def receive_ase_function(client_entry: HSAEngineClient, namespace_entry: Namespace, data, init_data):
|
||||
namespace_entry.emit('request_function', data['data'], room=init_data['room'], namespace='/agent')
|
||||
|
||||
def on_initiative(self,data):
|
||||
print("User active function call")
|
||||
|
||||
Reference in New Issue
Block a user