Spaces:
Runtime error
Runtime error
谦言
commited on
Commit
·
c66e342
1
Parent(s):
0a72604
add multi-people support
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import importlib
|
| 2 |
import os
|
| 3 |
import random
|
|
@@ -75,7 +76,11 @@ def process_configuration(uuid_str, bot_avatar, name, description,
|
|
| 75 |
knowledge_files, capabilities_checkboxes,
|
| 76 |
openapi_schema, openapi_auth, openapi_auth_apikey,
|
| 77 |
openapi_auth_apikey_type, openapi_privacy_policy,
|
| 78 |
-
state):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
uuid_str = check_uuid(uuid_str)
|
| 80 |
tool_cfg = state['tool_cfg']
|
| 81 |
capabilities = state['capabilities']
|
|
@@ -406,7 +411,11 @@ with demo:
|
|
| 406 |
}
|
| 407 |
|
| 408 |
# tab 切换的事件处理
|
| 409 |
-
def on_congifure_tab_select(_state, uuid_str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
uuid_str = check_uuid(uuid_str)
|
| 411 |
configure_updated = _state.get('configure_updated', False)
|
| 412 |
if configure_updated:
|
|
@@ -448,7 +457,11 @@ with demo:
|
|
| 448 |
gr.Dataset.update(samples=suggestion)
|
| 449 |
}
|
| 450 |
|
| 451 |
-
def create_send_message(chatbot, input, _state, uuid_str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
uuid_str = check_uuid(uuid_str)
|
| 453 |
# 将发送的消息添加到聊天历史
|
| 454 |
builder_agent = _state['builder_agent']
|
|
@@ -512,7 +525,11 @@ with demo:
|
|
| 512 |
])
|
| 513 |
|
| 514 |
# 配置 "Preview" 的消息发送功能
|
| 515 |
-
def preview_send_message(chatbot, input, _state, uuid_str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
# 将发送的消息添加到聊天历史
|
| 517 |
_uuid_str = check_uuid(uuid_str)
|
| 518 |
user_agent = _state['user_agent']
|
|
@@ -568,7 +585,11 @@ with demo:
|
|
| 568 |
inputs=[user_chatbot, preview_chat_input, state, uuid_str],
|
| 569 |
outputs=[user_chatbot, user_chat_bot_cover, preview_chat_input])
|
| 570 |
|
| 571 |
-
def upload_file(chatbot, upload_button, _state, uuid_str):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
uuid_str = check_uuid(uuid_str)
|
| 573 |
new_file_paths = []
|
| 574 |
if 'file_paths' in _state:
|
|
@@ -606,7 +627,11 @@ with demo:
|
|
| 606 |
outputs=[user_chatbot, user_chat_bot_cover, preview_chat_input])
|
| 607 |
|
| 608 |
# configuration for publish
|
| 609 |
-
def publish_agent(name, uuid_str, state):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 610 |
uuid_str = check_uuid(uuid_str)
|
| 611 |
env_params = {}
|
| 612 |
env_params.update(
|
|
@@ -710,7 +735,28 @@ with demo:
|
|
| 710 |
publish_hint_md
|
| 711 |
])
|
| 712 |
|
| 713 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 714 |
uuid_str = check_uuid(uuid_str)
|
| 715 |
builder_cfg, model_cfg, tool_cfg, available_tool_list, _, _ = parse_configuration(
|
| 716 |
uuid_str)
|
|
@@ -727,9 +773,8 @@ with demo:
|
|
| 727 |
create_send_button:
|
| 728 |
gr.Button.update(value=i18n.get('send'), interactive=True),
|
| 729 |
}
|
| 730 |
-
|
| 731 |
demo.load(
|
| 732 |
-
init_all, inputs=[uuid_str, state], outputs=configure_updated_outputs)
|
| 733 |
|
| 734 |
demo.queue(concurrency_count=10)
|
| 735 |
demo.launch(show_error=True)
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
import importlib
|
| 3 |
import os
|
| 4 |
import random
|
|
|
|
| 76 |
knowledge_files, capabilities_checkboxes,
|
| 77 |
openapi_schema, openapi_auth, openapi_auth_apikey,
|
| 78 |
openapi_auth_apikey_type, openapi_privacy_policy,
|
| 79 |
+
state, request: gr.Request):
|
| 80 |
+
if request:
|
| 81 |
+
uuid_str = generate_user_id(request.headers)
|
| 82 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 83 |
+
|
| 84 |
uuid_str = check_uuid(uuid_str)
|
| 85 |
tool_cfg = state['tool_cfg']
|
| 86 |
capabilities = state['capabilities']
|
|
|
|
| 411 |
}
|
| 412 |
|
| 413 |
# tab 切换的事件处理
|
| 414 |
+
def on_congifure_tab_select(_state, uuid_str, request: gr.Request):
|
| 415 |
+
if request:
|
| 416 |
+
uuid_str = generate_user_id(request.headers)
|
| 417 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 418 |
+
|
| 419 |
uuid_str = check_uuid(uuid_str)
|
| 420 |
configure_updated = _state.get('configure_updated', False)
|
| 421 |
if configure_updated:
|
|
|
|
| 457 |
gr.Dataset.update(samples=suggestion)
|
| 458 |
}
|
| 459 |
|
| 460 |
+
def create_send_message(chatbot, input, _state, uuid_str, request: gr.Request):
|
| 461 |
+
if request:
|
| 462 |
+
uuid_str = generate_user_id(request.headers)
|
| 463 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 464 |
+
|
| 465 |
uuid_str = check_uuid(uuid_str)
|
| 466 |
# 将发送的消息添加到聊天历史
|
| 467 |
builder_agent = _state['builder_agent']
|
|
|
|
| 525 |
])
|
| 526 |
|
| 527 |
# 配置 "Preview" 的消息发送功能
|
| 528 |
+
def preview_send_message(chatbot, input, _state, uuid_str, request: gr.Request):
|
| 529 |
+
if request:
|
| 530 |
+
uuid_str = generate_user_id(request.headers)
|
| 531 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 532 |
+
|
| 533 |
# 将发送的消息添加到聊天历史
|
| 534 |
_uuid_str = check_uuid(uuid_str)
|
| 535 |
user_agent = _state['user_agent']
|
|
|
|
| 585 |
inputs=[user_chatbot, preview_chat_input, state, uuid_str],
|
| 586 |
outputs=[user_chatbot, user_chat_bot_cover, preview_chat_input])
|
| 587 |
|
| 588 |
+
def upload_file(chatbot, upload_button, _state, uuid_str, request: gr.Request):
|
| 589 |
+
if request:
|
| 590 |
+
uuid_str = generate_user_id(request.headers)
|
| 591 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 592 |
+
|
| 593 |
uuid_str = check_uuid(uuid_str)
|
| 594 |
new_file_paths = []
|
| 595 |
if 'file_paths' in _state:
|
|
|
|
| 627 |
outputs=[user_chatbot, user_chat_bot_cover, preview_chat_input])
|
| 628 |
|
| 629 |
# configuration for publish
|
| 630 |
+
def publish_agent(name, uuid_str, state, request: gr.Request):
|
| 631 |
+
if request:
|
| 632 |
+
uuid_str = generate_user_id(request.headers)
|
| 633 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 634 |
+
|
| 635 |
uuid_str = check_uuid(uuid_str)
|
| 636 |
env_params = {}
|
| 637 |
env_params.update(
|
|
|
|
| 735 |
publish_hint_md
|
| 736 |
])
|
| 737 |
|
| 738 |
+
|
| 739 |
+
def generate_user_id(request_headers):
|
| 740 |
+
# 提取所需的信息
|
| 741 |
+
ip_address = request_headers['host']
|
| 742 |
+
user_agent = request_headers['user-agent']
|
| 743 |
+
accept_language = request_headers['accept-language']
|
| 744 |
+
cookie = request_headers['cookie']
|
| 745 |
+
|
| 746 |
+
# 将信息组合成一个字符串
|
| 747 |
+
combined_info = f"{ip_address}-{user_agent}-{accept_language}-{cookie}"
|
| 748 |
+
|
| 749 |
+
# 使用哈希函数生成唯一标识符
|
| 750 |
+
user_id = hashlib.sha256(combined_info.encode()).hexdigest()
|
| 751 |
+
|
| 752 |
+
return user_id
|
| 753 |
+
|
| 754 |
+
|
| 755 |
+
def init_all(uuid_str, _state, request: gr.Request):
|
| 756 |
+
if request:
|
| 757 |
+
uuid_str = generate_user_id(request.headers)
|
| 758 |
+
logger.info(uuid=uuid_str, message='init_all', step='generate_uuid')
|
| 759 |
+
|
| 760 |
uuid_str = check_uuid(uuid_str)
|
| 761 |
builder_cfg, model_cfg, tool_cfg, available_tool_list, _, _ = parse_configuration(
|
| 762 |
uuid_str)
|
|
|
|
| 773 |
create_send_button:
|
| 774 |
gr.Button.update(value=i18n.get('send'), interactive=True),
|
| 775 |
}
|
|
|
|
| 776 |
demo.load(
|
| 777 |
+
init_all, inputs=[uuid_str, state,], outputs=configure_updated_outputs)
|
| 778 |
|
| 779 |
demo.queue(concurrency_count=10)
|
| 780 |
demo.launch(show_error=True)
|