Skip to content

Commit

Permalink
GitHub merge gitlab (#393)
Browse files Browse the repository at this point in the history
Co-authored-by: wangyijunlyy <1157637345@qq.com>
Co-authored-by: tujianhong.tjh <tujianhong.tjh@alibaba-inc.com>
Co-authored-by: suluyan.sly <suluyan.sly@alibaba-inc.com>
Co-authored-by: Jianhong Tu <37433392+tuhahaha@users.noreply.github.com>
Co-authored-by: mushenL <125954878+mushenL@users.noreply.github.com>
Co-authored-by: Zhicheng Zhang <zhangzhicheng.zzc@alibaba-inc.com>
Co-authored-by: Zhicheng Zhang <zczhang.hvac@gmail.com>
Co-authored-by: wyw <1006629314@qq.com>
Co-authored-by: nil.wyw <nil.wyw@alibaba-inc.com>
Co-authored-by: Col0ring <1561999073@qq.com>
Co-authored-by: wenmeng.zwm <wenmeng.zwm@alibaba-inc.com>
Co-authored-by: Col0ring <47329987+Col0ring@users.noreply.github.com>
Co-authored-by: skyline2006 <skyline2006@163.com>
Co-authored-by: lylalala <liuyang070424@163.com>
Co-authored-by: ly119399 <ly119399@alibaba-inc.com>
Co-authored-by: Jintao Huang <huangjintao.hjt@alibaba-inc.com>
Co-authored-by: ljy266987 <ljy266987@alibaba-inc.com>
Co-authored-by: yangkun <yk01645326@alibaba-inc.com>
Co-authored-by: 临泮 <xuyanlan.xyl@alibaba-inc.com>
Co-authored-by: 杨堃 <yangkun@beyondosftdeMacBook-Pro.local>
Co-authored-by: Zhicheng Zhang <zzhang.purdue@gmail.com>
  • Loading branch information
22 people committed Apr 11, 2024
1 parent 8deef6d commit 68c7dd7
Show file tree
Hide file tree
Showing 29 changed files with 1,181 additions and 170 deletions.
2 changes: 1 addition & 1 deletion apps/agentfabric/README.md
Expand Up @@ -5,8 +5,8 @@ domain: #领域:cv/nlp/audio/multi-modal/AutoML
tags: #自定义标签
- agent
- AgentFabric

## 启动文件(若SDK为Gradio/Streamlit,默认为app.py, 若为Static HTML, 默认为index.html)

deployspec:
entry_file: app.py

Expand Down
55 changes: 42 additions & 13 deletions apps/agentfabric/app.py
Expand Up @@ -5,7 +5,7 @@

import gradio as gr
import json
import modelscope_gradio_components as mgr
import modelscope_studio as mgr
import yaml
from builder_core import (beauty_output, gen_response_and_process,
init_builder_chatbot_agent)
Expand All @@ -18,8 +18,7 @@
from i18n import I18n
from modelscope_agent.schemas import Message
from modelscope_agent.utils.logger import agent_logger as logger
from modelscope_gradio_components.components.Chatbot.llm_thinking_presets import \
qwen
from modelscope_studio.components.Chatbot.llm_thinking_presets import qwen
from publish_util import (pop_user_info_from_config, prepare_agent_zip,
reload_agent_zip)
from user_core import init_user_chatbot_agent
Expand Down Expand Up @@ -156,6 +155,10 @@ def check_uuid(uuid_str):
label=i18n.get('form_agent_language'),
choices=['zh', 'en'],
value='zh')
prologue_input = gr.Textbox(
label=i18n.get('form_prologue'),
placeholder=i18n.get('form_prologue_placeholder'),
lines=2)
suggestion_input = gr.Dataframe(
show_label=False,
value=[['']],
Expand All @@ -175,6 +178,12 @@ def check_uuid(uuid_str):
file_types=[
'text', '.json', '.csv', '.pdf', '.md'
])
knowledge_upload_button = gr.UploadButton(
i18n.get('form_knowledge_upload_button'),
file_count='multiple',
file_types=[
'text', '.json', '.csv', '.pdf', '.md'
])
capabilities_checkboxes = gr.CheckboxGroup(
label=i18n.get('form_capabilities'))

Expand Down Expand Up @@ -228,7 +237,6 @@ def check_uuid(uuid_str):
elem_classes=['markdown-body'],
avatar_images=get_avatar_image('', uuid_str),
height=650,
latex_delimiters=[],
show_label=False,
visible=False,
show_copy_button=True,
Expand Down Expand Up @@ -280,6 +288,7 @@ def check_uuid(uuid_str):
instructions_input,
model_selector,
agent_language_selector,
prologue_input,
suggestion_input,
knowledge_input,
capabilities_checkboxes,
Expand Down Expand Up @@ -323,6 +332,8 @@ def init_ui_config(uuid_str, _state, builder_cfg, model_cfg, tool_cfg):
value=builder_cfg.get('model', models[0]), choices=models),
agent_language_selector:
builder_cfg.get('language') or 'zh',
prologue_input:
builder_cfg.get('prologue') or '',
suggestion_input:
[[str] for str in suggests] if len(suggests) > 0 else [['']],
knowledge_input:
Expand Down Expand Up @@ -362,6 +373,16 @@ def on_congifure_tab_select(_state, uuid_str):
inputs=[state, uuid_str],
outputs=configure_updated_outputs)

# 上传文件到知识库的按钮
def on_append_file_to_knowledge(files, knowledge_input):
file_paths = [file.name for file in files]
return (knowledge_input or []) + file_paths

knowledge_upload_button.upload(
on_append_file_to_knowledge,
inputs=[knowledge_upload_button, knowledge_input],
outputs=[knowledge_input])

# 配置 "Create" 标签页的消息发送功能
def format_message_with_builder_cfg(_state, chatbot, builder_cfg,
uuid_str):
Expand Down Expand Up @@ -444,11 +465,12 @@ def create_send_message(chatbot, input, _state, uuid_str):
])

def process_configuration(uuid_str, bot_avatar, name, description,
instructions, model, agent_language, suggestions,
knowledge_files, capabilities_checkboxes,
openapi_schema, openapi_auth,
openapi_auth_apikey, openapi_auth_apikey_type,
openapi_privacy_policy, state):
instructions, model, agent_language, prologue,
suggestions, knowledge_files,
capabilities_checkboxes, openapi_schema,
openapi_auth, openapi_auth_apikey,
openapi_auth_apikey_type, openapi_privacy_policy,
state):
uuid_str = check_uuid(uuid_str)
tool_cfg = state['tool_cfg']
capabilities = state['capabilities']
Expand All @@ -473,6 +495,7 @@ def process_configuration(uuid_str, bot_avatar, name, description,
'avatar': bot_avatar,
'description': description,
'instruction': instructions,
'prologue': prologue,
'prompt_recommend': [row[0] for row in suggestions_filtered],
'knowledge': new_knowledge_files,
'tools': {
Expand Down Expand Up @@ -537,9 +560,10 @@ def process_configuration(uuid_str, bot_avatar, name, description,
inputs=[
uuid_str, bot_avatar_comp, name_input, description_input,
instructions_input, model_selector, agent_language_selector,
suggestion_input, knowledge_input, capabilities_checkboxes,
openapi_schema, openapi_auth_type, openapi_auth_apikey,
openapi_auth_apikey_type, openapi_privacy_policy, state
prologue_input, suggestion_input, knowledge_input,
capabilities_checkboxes, openapi_schema, openapi_auth_type,
openapi_auth_apikey, openapi_auth_apikey_type,
openapi_privacy_policy, state
],
outputs=[
user_chat_bot_cover, user_chatbot, user_chat_bot_suggest,
Expand Down Expand Up @@ -678,8 +702,12 @@ def change_lang(language):
gr.Dropdown(label=i18n.get('form_model')),
agent_language_selector:
gr.Dropdown(label=i18n.get('form_agent_language')),
prologue_input:
gr.update(label=i18n.get('form_prologue')),
knowledge_input:
gr.File(label=i18n.get('form_knowledge')),
knowledge_upload_button:
gr.update(label=i18n.get('form_knowledge_upload_button')),
capabilities_checkboxes:
gr.CheckboxGroup(label=i18n.get('form_capabilities')),
open_api_accordion:
Expand Down Expand Up @@ -725,7 +753,8 @@ def change_lang(language):
outputs=configure_updated_outputs + [
configure_button, create_chat_input, open_api_accordion,
preview_header, preview_chat_input, publish_accordion, header,
publish_alert_md, build_hint_md, publish_hint_md
publish_alert_md, build_hint_md, publish_hint_md,
knowledge_upload_button
])

def init_all(uuid_str, _state):
Expand Down
15 changes: 9 additions & 6 deletions apps/agentfabric/appBot.py
Expand Up @@ -4,18 +4,22 @@
import traceback

import gradio as gr
import modelscope_gradio_components as mgr
import modelscope_studio as mgr
from config_utils import get_avatar_image, get_ci_dir, parse_configuration
from gradio_utils import format_cover_html
from modelscope_agent.schemas import Message
from modelscope_agent.utils.logger import agent_logger as logger
from modelscope_gradio_components.components.Chatbot.llm_thinking_presets import \
qwen
from modelscope_studio.components.Chatbot.llm_thinking_presets import qwen
from user_core import init_user_chatbot_agent

dir_need_to_rm = '/tmp/agentfabric/config/local_user/'
if os.path.exists(dir_need_to_rm):
shutil.rmtree(dir_need_to_rm, ignore_errors=True)

uuid_str = 'local_user'
builder_cfg, model_cfg, tool_cfg, available_tool_list, _, _ = parse_configuration(
uuid_str)
prologue = builder_cfg.get('prologue', '尝试问我一点什么吧~')
suggests = builder_cfg.get('prompt_recommend', [])
avatar_pairs = get_avatar_image(builder_cfg.get('avatar', ''), uuid_str)

Expand Down Expand Up @@ -54,7 +58,7 @@ def init_user(state):
demo = gr.Blocks(css='assets/appBot.css', theme=customTheme)
with demo:
gr.Markdown(
'# <center> \N{fire} AgentFabric powered by Modelscope-agent ([github star](https://github.com/modelscope/modelscope-agent/tree/main))</center>' # noqa E501
'# <center class="agent_title"> \N{fire} AgentFabric powered by Modelscope-agent [github star](https://github.com/modelscope/modelscope-agent/tree/main)</center>' # noqa E501
)
draw_seed = random.randint(0, 1000000000)
state = gr.State({'session_seed': draw_seed})
Expand All @@ -63,12 +67,11 @@ def init_user(state):
with gr.Column():
# Preview
user_chatbot = mgr.Chatbot(
value=[[None, '尝试问我一点什么吧~']],
value=[[None, prologue]],
elem_id='user_chatbot',
elem_classes=['markdown-body'],
avatar_images=avatar_pairs,
height=600,
latex_delimiters=[],
show_label=False,
show_copy_button=True,
llm_thinking_presets=[
Expand Down
4 changes: 0 additions & 4 deletions apps/agentfabric/assets/app.css
Expand Up @@ -128,10 +128,6 @@
filter: grayscale(30%);
}

.markdown-body .message {
white-space: pre-wrap;
}

.markdown-body details {
white-space: nowrap;
}
Expand Down

0 comments on commit 68c7dd7

Please sign in to comment.