forked from SylphAI-Inc/AdalFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleaned up all react agent code and finished first draft of react agent
- Loading branch information
Showing
5 changed files
with
462 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from lightrag.components.agent import ReActAgent | ||
from lightrag.core import Generator, ModelClientType, ModelClient | ||
from lightrag.utils import setup_env | ||
|
||
setup_env() | ||
|
||
|
||
# Define tools | ||
def multiply(a: int, b: int) -> int: | ||
""" | ||
Multiply two numbers. | ||
""" | ||
return a * b | ||
|
||
|
||
def add(a: int, b: int) -> int: | ||
""" | ||
Add two numbers. | ||
""" | ||
return a + b | ||
|
||
|
||
def divide(a: float, b: float) -> float: | ||
""" | ||
Divide two numbers. | ||
""" | ||
return float(a) / b | ||
|
||
|
||
llama3_model_kwargs = { | ||
"model": "llama3-70b-8192", # llama3 70b works better than 8b here. | ||
"temperature": 0.0, | ||
} | ||
gpt_model_kwargs = { | ||
"model": "gpt-3.5-turbo", | ||
"temperature": 0.0, | ||
} | ||
|
||
|
||
def test_react_agent(model_client: ModelClient, model_kwargs: dict): | ||
tools = [multiply, add, divide] | ||
queries = [ | ||
"What is the capital of France? and what is 465 times 321 then add 95297 and then divide by 13.2?", | ||
"Give me 5 words rhyming with cool, and make a 4-sentence poem using them", | ||
] | ||
# define a generator without tools for comparison | ||
|
||
generator = Generator( | ||
model_client=model_client, | ||
model_kwargs=model_kwargs, | ||
) | ||
|
||
react = ReActAgent( | ||
max_steps=6, | ||
add_llm_as_fallback=True, | ||
tools=tools, | ||
model_client=model_client, | ||
model_kwargs=model_kwargs, | ||
) | ||
# print(react) | ||
|
||
for query in queries: | ||
print(f"Query: {query}") | ||
agent_response = react.call(query) | ||
llm_response = generator.call(prompt_kwargs={"input_str": query}) | ||
print(f"Agent response: {agent_response}") | ||
print(f"LLM response: {llm_response}") | ||
print("") | ||
|
||
|
||
if __name__ == "__main__": | ||
test_react_agent(ModelClientType.GROQ(), llama3_model_kwargs) | ||
# test_react_agent(ModelClientType.OPENAI(), gpt_model_kwargs) | ||
print("Done") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.