Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
9090538
update
wangyijunlyy Dec 2, 2023
3fce704
update
wangyijunlyy Dec 2, 2023
649c3ae
add style_repaint
wangyijunlyy Dec 12, 2023
3b48baf
恢复
wangyijunlyy Dec 12, 2023
5d73f22
恢复
wangyijunlyy Dec 12, 2023
9259188
解决合并冲突
wangyijunlyy Dec 12, 2023
e2c8a67
add style_repaint tool
wangyijunlyy Dec 12, 2023
c67430d
modify style_repaint
wangyijunlyy Dec 14, 2023
df77577
fix error
wangyijunlyy Dec 14, 2023
81ac82c
fix
wangyijunlyy Dec 14, 2023
cbe8236
fix rate limit
wangyijunlyy Dec 15, 2023
092a914
improve stability
wangyijunlyy Dec 15, 2023
b2ebd10
use dashscope to convert url
wangyijunlyy Dec 19, 2023
81866ff
update
wangyijunlyy Dec 19, 2023
a0cf87f
modify and better
wangyijunlyy Dec 19, 2023
6d29120
fix
wangyijunlyy Dec 19, 2023
f375ff0
refact framework: add base class for llm, tool, and agent
tuhahaha Jan 3, 2024
0d0dc8d
refact llm
tuhahaha Jan 4, 2024
31aeb30
refact llm for custom
tuhahaha Jan 4, 2024
4609cb2
add role_play agent
tuhahaha Jan 4, 2024
80cfa38
add unittest for role-play agent
tuhahaha Jan 4, 2024
b60db37
refactor/tool/image_gen
Jan 4, 2024
fd6537e
fix pre-commit
Jan 4, 2024
d4b68fc
add agent_builder agent
tuhahaha Jan 4, 2024
4689856
revert modelscope_agent/agent.py
Jan 5, 2024
b4bb3b8
Merge pull request #247 from suluyana/refactor/tool/image_gen
tuhahaha Jan 5, 2024
388e152
update agent and add react prompt
tuhahaha Jan 5, 2024
6cb1217
adapt agentbuilder in apps
tuhahaha Jan 8, 2024
41f6854
Merge remote-tracking branch 'upstream/refactor0103' into new_version
wangyijunlyy Jan 8, 2024
10c78f1
update style_repaint
wangyijunlyy Jan 8, 2024
4ad14ca
update style_repaint
wangyijunlyy Jan 8, 2024
053ad15
Merge pull request #250 from wangyijunlyy/new_version
tuhahaha Jan 8, 2024
b5f2a0b
change pipeline plugin tool (#248)
mushenL Jan 8, 2024
deba841
refactor ms agent
Jan 9, 2024
3e38201
save system to history
Jan 9, 2024
ddbf6e4
avoid duplicated system in roleplay
Jan 9, 2024
716aec8
builder with history running
Jan 9, 2024
079e85a
test case
wangyijunlyy Jan 9, 2024
5fbaf67
update tool
wangyijunlyy Jan 9, 2024
316931b
update
wangyijunlyy Jan 9, 2024
0c966d0
modify import method
wangyijunlyy Jan 9, 2024
812fe8d
Merge pull request #251 from wangyijunlyy/new_version
tuhahaha Jan 9, 2024
181b07d
code interpreter and knowledge
Jan 10, 2024
a3bf326
running code interpreter with file
Jan 10, 2024
c3efe6b
Refactor/citest (#257)
zzhangpurdue Jan 10, 2024
2a3b43d
add modelscope tool (#258)
mushenL Jan 11, 2024
7abdbd3
unittest-web search web browser
Jan 11, 2024
d968bf0
Merge branch 'refactor0103' of github.com:modelscope/modelscope-agent…
Jan 11, 2024
5dd2975
update tool and unittest
Jan 11, 2024
5346fe2
Refactor/gradio4 (#260)
suluyana Jan 12, 2024
9f97e1a
update reame and tool cfg
tuhahaha Jan 12, 2024
42f94cd
Merge branch 'refactor0103' of https://github.com/modelscope/modelsco…
tuhahaha Jan 12, 2024
92467e1
Refactor/unittest (#264)
zzhangpurdue Jan 13, 2024
ef7711f
Merge remote-tracking branch 'origin/master' into refactor0103
Jan 13, 2024
148a423
merge origin master
Jan 13, 2024
ace5831
fix bugs
Jan 13, 2024
17d9a0d
fix video-to-image
Jan 13, 2024
09dc91d
add qwen-max
Jan 15, 2024
408bd92
fix apps/agentfabric & update release version
Jan 15, 2024
fefdf54
apps/agentfabric/user_core.py
Jan 15, 2024
d0e11f1
fix pre-commit
Jan 15, 2024
79cfacc
Merge branch 'refactor0103' into release/0.3.0
Jan 15, 2024
2e72081
fix bugs & add video play for code interpreter
Jan 15, 2024
f5f4a89
comment out translate
Jan 15, 2024
3ccf308
Refactor log (#268)
lylalala Jan 15, 2024
9500ec7
Refactor/knowledgeretrieval (#271)
zzhangpurdue Jan 15, 2024
694154a
Merge remote-tracking branch 'origin/release/0.3.0' into refactor0103
Jan 15, 2024
5fce22c
add logger (#272)
zzhangpurdue Jan 15, 2024
36d250f
pass code unittest
Jan 15, 2024
7ecaf91
Merge branch 'release/0.3.0' into refactor0103
Jan 15, 2024
3b0f236
fix publish for missing MODELSCOPE_API_TOKEN alert & rm translation tool
Jan 16, 2024
8c8b611
fix bugs
Jan 16, 2024
deb2825
update log
Jan 16, 2024
93e2cda
fix bugs
Jan 17, 2024
c69bc5c
fix instruction
Jan 17, 2024
8437504
fix tool log
Jan 17, 2024
7dc36d1
fix bugs
Jan 19, 2024
a042aa0
fix pre-commit
Jan 19, 2024
517ff5f
Zhipu-glm4 (#276)
suluyana Jan 19, 2024
2bb40f3
add zhipuai to requirements.txt
Jan 19, 2024
caa1af9
make sure .md file is parsed by nltk
zzhangpurdue Jan 19, 2024
84c38e3
Update demo 20240118 (#275)
mushenL Jan 19, 2024
e671b63
add zhipuai
zzhangpurdue Jan 19, 2024
c23d191
Merge branch 'release/0.3.0' into refactor0103
zzhangpurdue Jan 21, 2024
be9777b
update retrieval knowledge logic to not load in agent fabric
zzhangpurdue Jan 22, 2024
53f92ca
update name
zzhangpurdue Jan 22, 2024
9097520
Merge branch 'release/0.3.0' of github.com:modelscope/modelscope-agen…
Jan 22, 2024
c275142
fix bugs
Jan 22, 2024
43ed672
fix pre-commit
Jan 22, 2024
5979950
fix ci
Jan 22, 2024
786a947
update max_token setting
zzhangpurdue Jan 22, 2024
2df7096
Merge remote-tracking branch 'origin/release/0.3.0' into release/0.3.0
zzhangpurdue Jan 22, 2024
da9e7e4
fix doc list extend method
zzhangpurdue Jan 23, 2024
6b91f14
fix ci
zzhangpurdue Jan 23, 2024
6388e69
fix ci
zzhangpurdue Jan 23, 2024
53d40c8
add docstr
tuhahaha Jan 24, 2024
befd8c5
rm useless agent: function call, react, react_chat
tuhahaha Jan 24, 2024
5ebc687
bugfix
tuhahaha Jan 24, 2024
1094f14
bugfix
tuhahaha Jan 24, 2024
5f7292e
bugfix: change _detect_tool for role_play
tuhahaha Jan 24, 2024
00515dc
remove uuid related log in ms
zzhangpurdue Jan 24, 2024
6c38563
fix publish avatar
Jan 25, 2024
6c1d023
version 0.3.0rc0
Jan 26, 2024
7e3bb66
fix bugs
zzhangpurdue Jan 26, 2024
938aac2
fix bug
Jan 26, 2024
bbc572b
fix audio->video
Jan 26, 2024
ad8abbc
Merge remote-tracking branch 'origin/release/0.3.0' into refactor0103
zzhangpurdue Jan 28, 2024
209d3da
update demo
zzhangpurdue Jan 30, 2024
e0a232a
bug fixed by comment
zzhangpurdue Jan 30, 2024
3a930ff
lint pass
zzhangpurdue Jan 30, 2024
82aefed
bug fixed
zzhangpurdue Jan 30, 2024
5cc2110
bug fixed
zzhangpurdue Jan 30, 2024
760d4dd
merge master
wenmengzhou Feb 3, 2024
df1415f
fix ci (not complete)
Feb 4, 2024
5d06ba4
add hf tool unit test
zzhangpurdue Feb 4, 2024
8a7451e
Openapi (#287)
suluyana Feb 4, 2024
db4354c
bug fixed
zzhangpurdue Feb 4, 2024
2287855
pass lint
zzhangpurdue Feb 4, 2024
ea81126
fix ci
Feb 5, 2024
858170c
update ci_env
Feb 5, 2024
dbe53a2
fix ci
Feb 5, 2024
53ffd1e
fix ci
Feb 5, 2024
3d696ad
fix pre-commit
Feb 5, 2024
e15391b
update ci
Feb 5, 2024
7808cc7
fix pre-commit
Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
390 changes: 194 additions & 196 deletions apps/agentfabric/app.py

Large diffs are not rendered by default.

152 changes: 68 additions & 84 deletions apps/agentfabric/appBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
import traceback

import gradio as gr
import modelscope_gradio_components as mgr
from config_utils import get_avatar_image, get_ci_dir, parse_configuration
from gradio_utils import ChatBot, format_cover_html
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 user_core import init_user_chatbot_agent

uuid_str = 'local_user'
Expand All @@ -33,9 +37,10 @@ def check_uuid(uuid_str):
def init_user(state):
try:
seed = state.get('session_seed', random.randint(0, 1000000000))
user_agent = init_user_chatbot_agent(uuid_str)
user_agent, user_memory = init_user_chatbot_agent(uuid_str)
user_agent.seed = seed
state['user_agent'] = user_agent
state['user_memory'] = user_memory
except Exception as e:
logger.error(
uuid=uuid_str,
Expand All @@ -57,115 +62,94 @@ def init_user(state):
with gr.Column(scale=4):
with gr.Column():
# Preview
user_chatbot = ChatBot(
user_chatbot = mgr.Chatbot(
value=[[None, '尝试问我一点什么吧~']],
elem_id='user_chatbot',
elem_classes=['markdown-body'],
avatar_images=avatar_pairs,
height=600,
latex_delimiters=[],
show_label=False)
show_label=False,
show_copy_button=True,
llm_thinking_presets=[
qwen(
action_input_title='调用 <Action>',
action_output_title='完成调用')
])
with gr.Row():
with gr.Column(scale=12):
preview_chat_input = gr.Textbox(
show_label=False,
container=False,
placeholder='跟我聊聊吧~')
with gr.Column(min_width=70, scale=1):
upload_button = gr.UploadButton(
'上传',
file_types=['file', 'image', 'audio', 'video', 'text'],
file_count='multiple')
with gr.Column(min_width=70, scale=1):
preview_send_button = gr.Button('发送', variant='primary')
user_chatbot_input = mgr.MultimodalInput(
interactive=True,
placeholder='跟我聊聊吧~',
upload_button_props=dict(
file_count='multiple',
file_types=['file', 'image', 'audio', 'video',
'text']))

with gr.Column(scale=1):
user_chat_bot_cover = gr.HTML(
format_cover_html(builder_cfg, avatar_pairs[1]))
user_chat_bot_suggest = gr.Examples(
label='Prompt Suggestions',
examples=suggests,
inputs=[preview_chat_input])
inputs=[user_chatbot_input])

def upload_file(chatbot, upload_button, _state):
def send_message(chatbot, input, _state):
# 将发送的消息添加到聊天历史
if 'user_agent' not in _state:
init_user(_state)
# 将发送的消息添加到聊天历史
_uuid_str = check_uuid(uuid_str)
new_file_paths = []
if 'file_paths' in _state:
file_paths = _state['file_paths']
else:
file_paths = []
for file in upload_button:
file_name = os.path.basename(file.name)
user_agent = _state['user_agent']
user_memory = _state['user_memory']
append_files = []
for file in input.files:
file_name = os.path.basename(file.path)
# covert xxx.json to xxx_uuid_str.json
file_name = file_name.replace('.', f'_{_uuid_str}.')
file_path = os.path.join(get_ci_dir(), file_name)
if not os.path.exists(file_path):
# make sure file path's directory exists
os.makedirs(os.path.dirname(file_path), exist_ok=True)
shutil.copy(file.name, file_path)
file_paths.append(file_path)
new_file_paths.append(file_path)
if file_name.endswith(('.jpeg', '.png', '.jpg')):
chatbot += [((file_path, ), None)]

else:
chatbot.append((None, f'上传文件{file_name},成功'))
shutil.copy(file.path, file_path)
append_files.append(file_path)
chatbot.append([{'text': input.text, 'files': input.files}, None])
yield {
user_chatbot: gr.Chatbot.update(visible=True, value=chatbot),
preview_chat_input: gr.Textbox.update(value='')
user_chatbot: chatbot,
user_chatbot_input: None,
}

_state['file_paths'] = file_paths
_state['new_file_paths'] = new_file_paths

upload_button.upload(
upload_file,
inputs=[user_chatbot, upload_button, state],
outputs=[user_chatbot, preview_chat_input])
# get short term memory history
history = user_memory.get_history()

def send_message(chatbot, input, _state):
# 将发送的消息添加到聊天历史
if 'user_agent' not in _state:
init_user(_state)

user_agent = _state['user_agent']
if 'new_file_paths' in _state:
new_file_paths = _state['new_file_paths']
else:
new_file_paths = []
_state['new_file_paths'] = []
chatbot.append((input, ''))
yield {
user_chatbot: chatbot,
preview_chat_input: gr.Textbox.update(value=''),
}
# get long term memory knowledge, currently get one file
uploaded_file = None
if len(append_files) > 0:
uploaded_file = append_files[0]
ref_doc = user_memory.run(
query=input.text, url=uploaded_file, checked=True)

response = ''
try:
for frame in user_agent.stream_run(
input,
print_info=True,
remote=False,
append_files=new_file_paths):
# is_final = frame.get("frame_is_final")
llm_result = frame.get('llm_text', '')
exec_result = frame.get('exec_result', '')
# llm_result = llm_result.split("<|user|>")[0].strip()
if len(exec_result) != 0:
# action_exec_result
if isinstance(exec_result, dict):
exec_result = str(exec_result['result'])
frame_text = f'<result>{exec_result}</result>'
else:
# llm result
frame_text = llm_result
for frame in user_agent.run(
input.text,
history=history,
ref_doc=ref_doc,
append_files=append_files):

# important! do not change this
response += frame_text
chatbot[-1] = (input, response)
response += frame
chatbot[-1][1] = response
yield {
user_chatbot: chatbot,
}
if len(history) == 0:
user_memory.update_history(
Message(role='system', content=user_agent.system_prompt))

user_memory.update_history([
Message(role='user', content=input.text),
Message(role='assistant', content=response),
])
except Exception as e:
if 'dashscope.common.error.AuthenticationError' in str(e):
msg = 'DASHSCOPE_API_KEY should be set via environment variable. You can acquire this in ' \
Expand All @@ -174,15 +158,15 @@ def send_message(chatbot, input, _state):
msg = 'Too many people are calling, please try again later.'
else:
msg = str(e)
chatbot[-1] = (input, msg)
chatbot[-1][1] = msg
yield {user_chatbot: chatbot}

preview_send_button.click(
send_message,
inputs=[user_chatbot, preview_chat_input, state],
outputs=[user_chatbot, preview_chat_input])
gr.on([user_chatbot_input.submit],
fn=send_message,
inputs=[user_chatbot, user_chatbot_input, state],
outputs=[user_chatbot, user_chatbot_input])

demo.load(init_user, inputs=[state], outputs=[state])

demo.queue(concurrency_count=10)
demo.launch(show_error=True)
demo.queue()
demo.launch(show_error=True, max_threads=10)
Loading