Files
lagent/examples/react_example.py
loveSnowBest a88764e9e0 [Fix] fix sample bugs & ReAct (#11)
* fix sample bugs

* update typos and ReAct

* update v1.1 for internlm

* add space between CN and EN

* update internlm response
2023-08-21 21:07:40 +08:00

37 lines
956 B
Python

from lagent.actions.action_executor import ActionExecutor
from lagent.actions.python_interpreter import PythonInterpreter
from lagent.agents.react import ReAct
from lagent.llms.openai import GPTAPI
def input_prompt():
print('\ndouble enter to end input >>> ', end='')
sentinel = '' # ends when this string is seen
return '\n'.join(iter(input, sentinel))
def main():
# set OPEN_API_KEY in your environment or directly pass it with key=''
model = GPTAPI(model_type='gpt-3.5-turbo')
chatbot = ReAct(
llm=model,
action_executor=ActionExecutor(actions=[PythonInterpreter()]),
)
while True:
try:
prompt = input_prompt()
except UnicodeDecodeError:
print('UnicodeDecodeError')
continue
if prompt == 'exit':
exit(0)
agent_return = chatbot.chat(prompt)
print(agent_return.response)
if __name__ == '__main__':
main()