Skip to content

Commit

Permalink
Rishabh/research assistant (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhraj36 authored Aug 4, 2024
1 parent a3a9421 commit c9c15ee
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 2 deletions.
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")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
camel-ai
composio-camel
python-dotenv
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
dotenv.load_dotenv()

# Initialize the language model with OpenAI API key and model name
llm = ChatOpenAI(model="gpt-4o")
llm = ChatOpenAI(
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o"
)

# Setup tools using ComposioToolSet
composio_toolset = ComposioToolSet()
Expand Down Expand Up @@ -47,4 +50,4 @@
result = crew.kickoff()

# Print the result of the task execution
print(result)
print(task.output)
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!"
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
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-dotenv
composio_praisonai
langchain_openai
praisonai
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!"
22 changes: 22 additions & 0 deletions tools.py
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,
)

0 comments on commit c9c15ee

Please sign in to comment.