Skip to content

Commit

Permalink
fix user_token
Browse files Browse the repository at this point in the history
  • Loading branch information
suluyan committed Jan 8, 2025
1 parent a77c2c1 commit 37f1480
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/agentfabric/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def generate():
assert isinstance(exec_result, Config)
builder_cfg = exec_result.to_dict()
save_builder_configuration(builder_cfg, uuid_str)
app.session_manager.renew_user_bot(uuid_str)
app.session_manager.clear_user_bot(uuid_str)
res = json.dumps(
{
'data': response,
Expand Down Expand Up @@ -353,7 +353,7 @@ def save_builder_config(uuid_str):
error=str(e),
details={'error_traceback': traceback.format_exc()})
save_builder_configuration(builder_cfg=builder_config, uuid_str=uuid_str)
app.session_manager.renew_user_bot(uuid_str)
app.session_manager.clear_user_bot(uuid_str)

return jsonify({'success': True, 'request_id': request_id_var.get('')})

Expand Down
8 changes: 2 additions & 6 deletions apps/agentfabric/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ def get_builder_bot(
builder_id,
renew=False) -> Tuple[AgentBuilder, MemoryWithRetrievalKnowledge]:
builder_agent = self.builder_bots[builder_id]
print(f'builder_id: {builder_id}')
print(f'builder_bots: {self.builder_bots.keys()}')
if renew or builder_agent is None:
logger.info(f'init_builder_chatbot_agent: {builder_id} ')
builder_agent = init_builder_chatbot_agent(builder_id)
Expand All @@ -141,10 +139,7 @@ def get_user_bot(
session,
user_token=None) -> Tuple[RolePlay, MemoryWithRetrievalKnowledge]:
unique_id = builder_id + '_' + session
print(f'unique_id: {unique_id}')
user_agent = self.user_bots[unique_id]
print(f'self.user_bots: {self.user_bots}')
print(f'user_agent: {user_agent}')
if user_agent is None:
logger.info(f'init_user_chatbot_agent: {builder_id} {session}')
user_agent = init_user_chatbot_agent(
Expand All @@ -164,9 +159,10 @@ def renew_user_bot(
builder_id, session, use_tool_api=True, user_token=user_token)
self.user_bots[unique_id] = user_agent

def clear_user_bot(self, builder_id, session):
def clear_user_bot(self, builder_id, session='default'):
unique_id = builder_id + '_' + session
user_agent = self.user_bots[unique_id]
logger.info(f'clear_user_chatbot_agent: {builder_id} {session}')
if user_agent is not None:
self.user_bots.delete_key(unique_id)
shutil.rmtree(
Expand Down

0 comments on commit 37f1480

Please sign in to comment.