Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix React #41

Merged
merged 3 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
SOURCEDIR = doc/source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
Expand Down
11 changes: 5 additions & 6 deletions gentopia/agent/react/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def run(self, instruction, max_iterations=10):
:return: AgentOutput object.
:rtype: AgentOutput
"""
self.intermediate_steps.clear()
logging.info(f"Running {self.name + ':' + self.version} with instruction: {instruction}")
total_cost = 0.0
total_token = 0
Expand All @@ -158,8 +159,8 @@ def run(self, instruction, max_iterations=10):
logging.info(f"Prompt: {prompt}")
response = self.llm.completion(prompt, stop=["Observation:"])
if response.state == "error":
print("Planner failed to retrieve response from LLM")
raise ValueError("Planner failed to retrieve response from LLM")
print("Failed to retrieve response from LLM")
raise ValueError("Failed to retrieve response from LLM")

logging.info(f"Response: {response.content}")
total_cost += calculate_cost(self.llm.model_name, response.prompt_token,
Expand All @@ -180,7 +181,7 @@ def run(self, instruction, max_iterations=10):
self.intermediate_steps[-1].append(result)
return AgentOutput(output=response.content, cost=total_cost, token_usage=total_token)

def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput] = None):
def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput] = None, max_iterations: int = 10):
"""
Stream output the agent with the given instruction.

Expand All @@ -197,7 +198,7 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
if output is None:
output = BaseOutput()
output.thinking(self.name)
for _ in range(10):
for _ in range(max_iterations):

prompt = self._compose_prompt(instruction)
logging.info(f"Prompt: {prompt}")
Expand All @@ -208,8 +209,6 @@ def stream(self, instruction: Optional[str] = None, output: Optional[BaseOutput]
for i in response:
content += i.content
output.panel_print(i.content, self.name, True)

# print(i.content)
output.clear()

logging.info(f"Response: {content}")
Expand Down
7 changes: 5 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
enable_log(log_level='debug')
dotenv.load_dotenv(".env")

assembler = AgentAssembler(file='configs/memory.yaml')
assembler = AgentAssembler(file='configs/react.yaml')

# # assembler.manager = LocalLLMManager()
agent = assembler.get_agent()
chat(agent)

# chat(agent)
print(agent.run("1+sqrt(33)=?"))
print(agent.run("1+sqrt(35)=?"))