Feat: support response from FinishAction (#122)

This commit is contained in:
liujiangning30
2024-01-31 16:09:14 +08:00
committed by GitHub
parent d943becaec
commit f974a7bd39
3 changed files with 14 additions and 7 deletions

View File

@@ -5,10 +5,8 @@ import os
import streamlit as st
from lagent.actions import (ActionExecutor, ArxivSearch, GoogleScholar,
IPythonInterpreter)
from lagent.agents.internlm2_agent import (INTERPRETER_CN, META_INS, PLUGIN_CN,
Internlm2Agent, Internlm2Protocol)
from lagent.actions import ActionExecutor, ArxivSearch, GoogleScholar, IPythonInterpreter # noqa: E501
from lagent.agents.internlm2_agent import INTERPRETER_CN, META_INS, PLUGIN_CN, Internlm2Agent, Internlm2Protocol
from lagent.llms.lmdepoly_wrapper import LMDeployClient
from lagent.llms.meta_template import INTERNLM2_META as META
from lagent.schema import AgentStatusCode
@@ -299,7 +297,8 @@ def main():
st.session_state['ui'].render_action_results(
agent_return.actions[-1])
elif (agent_return.state == AgentStatusCode.STREAM_ING
or agent_return.state == AgentStatusCode.CODING):
or agent_return.state == AgentStatusCode.CODING
or agent_return.state == AgentStatusCode.END):
# st.markdown(agent_return.response)
# 清除占位符的当前内容,并显示新内容
with st.container():

View File

@@ -342,9 +342,16 @@ class Internlm2Agent(BaseAgent):
action_return.thought = language
agent_return.actions.append(action_return)
inner_history.append(dict(role='language', content=language))
if not name or action_return.type == executor.finish_action.name:
if not name:
agent_return.response = language
agent_return.state = AgentStatusCode.END
break
elif action_return.type == executor.finish_action.name:
try:
response = action_return.args['text']['response']
except Exception:
logging.info(msg='Unable to parse FinishAction.')
response = ''
agent_return.response = response
break
else:
inner_history.append(

View File

@@ -22,3 +22,4 @@ ignore-words-list = patten,nd,ty,mot,hist,formating,winn,gool,datas,wan,confids,
[flake8]
per-file-ignores = ftdp/configs/*: F401,F403,F405
max-line-length = 120