Package: phireact
YORG Test Packagethis is a test packagetest versionhow to useSet up test version packagepipinstall-ihttps://test.pypi.org/simple/--extra-index-urlhttps://pypi.org/simpleyorg-testSet up openapikey
(If you are in China, please set up a proxy to ensure that you can connect to openai.)importos#os.environ['http_proxy'] = 'http://127.0.0.1:10809'  # 这里设置自己的代理端口号#os.environ['https_proxy'] = 'http://127.0.0.1:10809'  # 这里设置自己的代理端口号os.environ['OPENAI_CHAT_API_KEY']='sk-br3j7Gxxxxxxxxvt8r'set up yaml file
We have some tools built in eg.code_interpreter,swe_tooltools.yamlYORG:0.0.1info:title:yorg_tools_documentdescription:yorg tool define document.version:'v1'tools:code_interpreter:name:code_interpreterentity_name:code_interpretersummary:Run the code through code_interpreter and return the result of the code run. If your query is about math, computer science, or data science, you can use this tool to get the result of the code run.parameters:-name:codedescription:code text that requires code_interpreter to runrequired:trueparameter_schema:type:stringresponses:success:description:OKcontent:result:type:stringdescription:the result of the code runexample_stateful_tool:name:example_stateful_toolentity_name:example_stateful_toolsummary:This tool is an example of a stateful tool. It will get two number from user input and return the sum of the two numbers.parameters:[]responses:{}swe_tool:name:sew_toolentity_name:swe_toolsummary:SoftWare Engineer Agent(swe_tool) specializes in working with code files.parameters:[]responses:{}Tools are categorized into stateful tools and function tools,
Function tools can describe parameters and return values directly in tools.yaml
Functions can be registered using decoratorsfromyorg_test.core.assistant.tools.toolsimportregister_function_tool@register_function_tooldefcode_test(code:str):return{"type":"success","content":{"result":"Hello, World!",},}If it's a stateful tool you need to write an additional yaml file with a stateful descriptionstart_stage:"init"finish_stage:"finish"all_stages:init:name:"init"next_stage_entry:stage_1:-name:xrequired:trueparameter_schema:type:numberdescription:"inputvaluex"need_llm_generate_parameters:falseneed_llm_generate_response:falsestage_1:name:"stage_1"next_stage_entry:stage_2:-name:yrequired:trueparameter_schema:type:numberdescription:"inputvaluey"need_llm_generate_parameters:falseneed_llm_generate_response:falsestage_2:name:"stage_2"next_stage_entry:stage_3:[]need_llm_generate_parameters:falseneed_llm_generate_response:falsestage_3:name:"stage_3"next_stage_entry:finish:[]need_llm_generate_parameters:falseneed_llm_generate_response:falsefinish:name:"finish"next_stage_entry:{}need_llm_generate_parameters:falseneed_llm_generate_response:falseStateful tools can also be registered using decorators.
The yaml file is registered in init.fromyorg_test.core.assistant.tools.toolsimportregister_stateful_toolfromyorg_test.core.assistant.tools.stateful_tool_entityimportStatefulToolEntity@register_stateful_toolclassExampleStatefulToolEntity(StatefulToolEntity):"""This example tool entity is stateful, and it has 3 inner stages.stage1: take integer x as inputstage2: take integer y as inputstage3: no input, return x + y"""def__init__(self):super().__init__("example_stateful_tool.yaml")def_call(self,**kwargs):if"goto"notinkwargs:ifself.current_stage.name==self.config.start_stage:return{"type":"success","content":{"message":"stateful tool is started"},}else:return{"type":"error","content":{"message":"please provide `goto` parameter"},}request_next_stage=kwargs["goto"]ifrequest_next_stagenotinself.config.all_stages:return{"type":"error","content":{"message":f"stage{request_next_stage}not found"},}self.current_stage=self.config.all_stages[request_next_stage]matchself.current_stage.name:case"stage_1":returnself._stage1(kwargs["x"])case"stage_2":returnself._stage2(kwargs["y"])case"stage_3":returnself._stage3()caseself.config.finish_stage:returnself._finish()case_:return{"type":"error","content":{"message":f"stage{self.current_stage.name}not found"},}def_stage1(self,x:int):self.x=xreturn{"type":"success","content":{"message":"stage1 done"}}def_stage2(self,y:int):self.y=yreturn{"type":"success","content":{"message":"stage2 done"}}def_stage3(self):return{"type":"success","content":{"result":self.x+self.y}}def_finish(self):return{"type":"success","content":{"message":"stateful tool is finished"}}run exampleimportyorg_testthreads=yorg_test.Threads.create('tools.yaml')assistant=yorg_test.Assistants.create(name="Test Assistant",model="gpt-4-1106-preview",instructions="Use swe tool auto fix code files",tools=[{'type':'swe_tool'}])print(assistant.id)# 运行 Threads 对象result=threads.run(assistant.id,"Use SoftWare Engineer Agent swe tool auto fix code files.")print(result)result=threads.run(assistant.id,"the repo url is https://github.com/YORG-AI/Open-Assistant",goto="stage_1")print(result)result=threads.run(assistant.id,"add helloworld feature to readme",goto="stage_2")print(result)result=threads.run(assistant.id,"focus_files_name_list = [README.md]",goto="stage_3")print(result)result=threads.run(assistant.id,"action=3",goto="stage_4")print(result)result=threads.run(assistant.id,"",goto="stage_5")print(result)result=threads.run(assistant.id,"action=0,action_idx=0",goto="stage_6")print(result)result=threads.run(assistant.id,"",goto="finish")print(result)