-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from SylphAI-Inc/main
[Beta Release 0.0.0b1]
- Loading branch information
Showing
36 changed files
with
1,109 additions
and
455 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
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
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") |
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
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Oops, something went wrong.