Files
OS-Copilot/examples/4_open_document.py
2023-12-14 19:30:52 +08:00

30 lines
1.0 KiB
Python

from jarvis.agent.openai_agent import OpenAIAgent
from jarvis.environment.py_env import PythonEnv
'''
Made By DZC
The function is to be able to open any type of document.
'''
environment = PythonEnv()
agent = OpenAIAgent(config_path="examples/config.json")
response = '''
Thought: To open a document named , we can focus on one goal: open the specified document(word, pdf, pptx, txt etc.).
Actions:
1. <action>open_document</action>
Check local action_lib, the required action code is in the library, according to the function description in the code, combined with the information provided by the user, You can instantiate classes for different tasks.
invoke:
1. <invoke>open_document()("/home/heroding/桌面/rnn.pptx" , "pptx")</invoke>
'''
action = agent.extract_action(response, begin_str='<action>', end_str='</action>')
invoke = agent.extract_invoke(response, begin_str='<invoke>', end_str='</invoke>')
for (i, a) in enumerate(action):
command = agent.action_lib[a] + "\n" + invoke[i]
print(environment.step(command).result)