forked from ComposioHQ/composio
-
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.
Rishabh/research assistant (ComposioHQ#396)
- Loading branch information
1 parent
a3a9421
commit c9c15ee
Showing
14 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
python/examples/research_assistant/research_assistant_camelai/main.py
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,67 @@ | ||
import os | ||
import dotenv | ||
from colorama import Fore | ||
from camel.agents import ChatAgent | ||
from camel.configs import ChatGPTConfig | ||
from camel.messages import BaseMessage | ||
from camel.models import ModelFactory | ||
from camel.types import ModelPlatformType, ModelType | ||
from camel.utils import print_text_animated | ||
from composio_camel import ComposioToolSet, App, Action | ||
|
||
# Load environment variables | ||
dotenv.load_dotenv() | ||
|
||
# Initialize the language model with OpenAI API key and model name | ||
api_key = os.environ["OPENAI_API_KEY"] | ||
|
||
# Setup tools using ComposioToolSet | ||
composio_toolset = ComposioToolSet() | ||
# tools = composio_toolset.get_tools(apps=[App.SERPAPI]) | ||
tools = composio_toolset.get_actions(actions=[Action.SERPAPI_SEARCH]) | ||
|
||
# Configure the assistant model | ||
assistant_model_config = ChatGPTConfig( | ||
temperature=0.0, | ||
tools=tools, | ||
) | ||
|
||
# Create the model | ||
model = ModelFactory.create( | ||
model_platform=ModelPlatformType.OPENAI, | ||
model_type=ModelType.GPT_4O, | ||
model_config_dict=assistant_model_config.__dict__ | ||
) | ||
|
||
# Define the system message for the assistant | ||
assistant_sys_msg = BaseMessage.make_assistant_message( | ||
role_name="Researcher", | ||
content=( | ||
"You are a researcher. Using the information in the task, you find out some of the most popular facts about the topic along with some of the trending aspects. " | ||
"You provide a lot of information thereby allowing a choice in the content selected for the final blog." | ||
), | ||
) | ||
|
||
# Initialize the agent | ||
agent = ChatAgent( | ||
assistant_sys_msg, | ||
model, | ||
tools=tools, | ||
) | ||
|
||
# Reset the agent to start fresh | ||
agent.reset() | ||
|
||
# Define the research task prompt | ||
prompt = """ | ||
Research about open source LLMs vs closed source LLMs. | ||
Your final answer MUST be a full analysis report. | ||
""" | ||
|
||
user_msg = BaseMessage.make_user_message(role_name="User", content=prompt) | ||
print(Fore.YELLOW + f"User prompt:\n{prompt}\n") | ||
|
||
# Get the response from the agent | ||
response = agent.step(user_msg) | ||
for msg in response.msgs: | ||
print_text_animated(Fore.GREEN + f"Agent response:\n{msg.content}\n") |
3 changes: 3 additions & 0 deletions
3
python/examples/research_assistant/research_assistant_camelai/requirements.txt
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,3 @@ | ||
camel-ai | ||
composio-camel | ||
python-dotenv |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
python/examples/research_assistant/research_assistant_crewai/setup.sh
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,35 @@ | ||
#!/bin/bash | ||
|
||
# Create a virtual environment | ||
echo "Creating virtual environment..." | ||
python3 -m venv ~/.venvs/research_assistant | ||
|
||
# Activate the virtual environment | ||
echo "Activating virtual environment..." | ||
source ~/.venvs/research_assistant/bin/activate | ||
|
||
# Install libraries from requirements.txt | ||
echo "Installing libraries from requirements.txt..." | ||
pip install -r requirements.txt | ||
|
||
# Login to your account | ||
echo "Login to your Composio acount" | ||
composio login | ||
|
||
# Add trello tool | ||
echo "Add serpapi tool. Finish the flow" | ||
composio add serpapi | ||
|
||
# Copy env backup to .env file | ||
if [ -f ".env.example" ]; then | ||
echo "Copying .env.example to .env..." | ||
cp .env.example .env | ||
else | ||
echo "No .env.example file found. Creating a new .env file..." | ||
touch .env | ||
fi | ||
|
||
# Prompt user to fill the .env file | ||
echo "Please fill in the .env file with the necessary environment variables." | ||
|
||
echo "Setup completed successfully!" |
1 change: 1 addition & 0 deletions
1
python/examples/research_assistant/research_assistant_praisonai/.env.example
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 @@ | ||
OPENAI_API_KEY = your_openai_api_key_here #api key for chatgpt |
48 changes: 48 additions & 0 deletions
48
python/examples/research_assistant/research_assistant_praisonai/main.py
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,48 @@ | ||
import os | ||
import yaml | ||
import dotenv | ||
from praisonai import PraisonAI | ||
from composio_praisonai import Action, ComposioToolSet,App | ||
from langchain_openai import ChatOpenAI | ||
# Load environment variables | ||
dotenv.load_dotenv() | ||
|
||
# Initialize the language model with OpenAI API key and model name | ||
llm = ChatOpenAI( | ||
api_key=os.environ["OPENAI_API_KEY"], | ||
model="gpt-4" | ||
) | ||
|
||
composio_toolset = ComposioToolSet() | ||
tools = composio_toolset.get_actions(actions=[Action.SERPAPI_SEARCH]) | ||
|
||
tool_section_str = composio_toolset.get_tools_section(tools) | ||
print(tool_section_str) | ||
|
||
|
||
# Define the agent YAML configuration | ||
agent_yaml = """ | ||
framework: "crewai" | ||
topic: "Research" | ||
roles: | ||
researcher: | ||
role: "Researcher" | ||
goal: "Search the internet for the information requested" | ||
backstory: "A researcher tasked with finding and analyzing information on various topics using available tools." | ||
tasks: | ||
research_task: | ||
description: "Research about open source LLMs vs closed source LLMs." | ||
expected_output: "A full analysis report on the topic." | ||
""" + tool_section_str | ||
|
||
print(agent_yaml) | ||
|
||
# Create a PraisonAI instance with the agent_yaml content | ||
praison_ai = PraisonAI(agent_yaml=agent_yaml) | ||
|
||
# Run PraisonAI | ||
result = praison_ai.main() | ||
|
||
# Print the result | ||
print(result) |
4 changes: 4 additions & 0 deletions
4
python/examples/research_assistant/research_assistant_praisonai/requirements.txt
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,4 @@ | ||
python-dotenv | ||
composio_praisonai | ||
langchain_openai | ||
praisonai |
35 changes: 35 additions & 0 deletions
35
python/examples/research_assistant/research_assistant_praisonai/setup.sh
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,35 @@ | ||
#!/bin/bash | ||
|
||
# Create a virtual environment | ||
echo "Creating virtual environment..." | ||
python3 -m venv ~/.venvs/research_assistant | ||
|
||
# Activate the virtual environment | ||
echo "Activating virtual environment..." | ||
source ~/.venvs/research_assistant/bin/activate | ||
|
||
# Install libraries from requirements.txt | ||
echo "Installing libraries from requirements.txt..." | ||
pip install -r requirements.txt | ||
|
||
# Login to your account | ||
echo "Login to your Composio acount" | ||
composio login | ||
|
||
# Add trello tool | ||
echo "Add serpapi tool. Finish the flow" | ||
composio add serpapi | ||
|
||
# Copy env backup to .env file | ||
if [ -f ".env.example" ]; then | ||
echo "Copying .env.example to .env..." | ||
cp .env.example .env | ||
else | ||
echo "No .env.example file found. Creating a new .env file..." | ||
touch .env | ||
fi | ||
|
||
# Prompt user to fill the .env file | ||
echo "Please fill in the .env file with the necessary environment variables." | ||
|
||
echo "Setup completed successfully!" |
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,22 @@ | ||
import typing as t | ||
from typing import Type | ||
from praisonai_tools import BaseTool | ||
from composio_praisonai import ComposioToolSet | ||
from langchain.pydantic_v1 import BaseModel, Field | ||
|
||
|
||
|
||
class SERPAPI_SEARCH_PARAMS(BaseModel): | ||
query: str = Field(description="The search query for the SERP API.") | ||
|
||
class SERPAPI_SEARCH_TOOL(BaseTool): | ||
name: str = "SERPAPI_SEARCH_TOOL" | ||
description: str = "Perform a Google search using the SERP API." | ||
args_schema: Type[BaseModel] = SERPAPI_SEARCH_PARAMS | ||
|
||
def _run(self, **kwargs: t.Any) -> t.Any: | ||
toolset = ComposioToolSet(entity_id='default') | ||
return toolset.execute_tool( | ||
tool_identifier="serpapi_search", | ||
params=kwargs, | ||
) |