diff --git a/deepseek_example.py b/deepseek_example.py new file mode 100644 index 000000000..f1f34e7a2 --- /dev/null +++ b/deepseek_example.py @@ -0,0 +1,70 @@ +import os + +from dotenv import load_dotenv +from openai import OpenAI + +from swarms import Agent +from swarms.prompts.finance_agent_sys_prompt import ( + FINANCIAL_AGENT_SYS_PROMPT, +) + +load_dotenv() + + +class DeepSeekChat: + def __init__( + self, + api_key: str = os.getenv("DEEPSEEK_API_KEY"), + system_prompt: str = None, + ): + self.api_key = api_key + + self.client = OpenAI( + api_key=api_key, base_url="https://api.deepseek.com" + ) + + def run(self, task: str): + response = self.client.chat.completions.create( + model="deepseek-chat", + messages=[ + { + "role": "system", + "content": "You are a helpful assistant", + }, + {"role": "user", "content": task}, + ], + stream=False, + ) + + print(response) + + out = response.choices[0].message.content + print(out) + + return out + + +model = DeepSeekChat() + +# Initialize the agent +agent = Agent( + agent_name="Financial-Analysis-Agent", + agent_description="Personal finance advisor agent", + system_prompt=FINANCIAL_AGENT_SYS_PROMPT, + max_loops=1, + llm=model, + dynamic_temperature_enabled=True, + user_name="swarms_corp", + retry_attempts=3, + context_length=8192, + return_step_meta=False, + output_type="str", # "json", "dict", "csv" OR "string" "yaml" and + auto_generate_prompt=False, # Auto generate prompt for the agent based on name, description, and system prompt, task + max_tokens=4000, # max output tokens +) + +print( + agent.run( + "Create a table of super high growth opportunities for AI. I have $40k to invest in ETFs, index funds, and more. Please create a table in markdown.", + ) +) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 119fdeb78..0d608eaf4 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -199,6 +199,10 @@ nav: - Full API Reference: "swarms/framework/reference.md" - Examples: - Unique Swarms: "swarms/examples/unique_swarms.md" + - Various Model Providers: + - OpenAI: "swarms/examples/openai_example.md" + - Anthropic: "swarms/examples/claude.md" + - Groq: "swarms/examples/groq.md" - Swarm Models: - Overview: "swarms/models/index.md" # - Models Available: "swarms/models/index.md" diff --git a/docs/swarms/examples/claude.md b/docs/swarms/examples/claude.md new file mode 100644 index 000000000..5890c4fc6 --- /dev/null +++ b/docs/swarms/examples/claude.md @@ -0,0 +1,26 @@ +# Agent with Anthropic/Claude + +- Get their api keys and put it in the `.env` +- Select your model_name like `claude-3-sonnet-20240229` follows LiteLLM conventions + + +```python +from swarms import Agent +import os +from dotenv import load_dotenv + +load_dotenv() + +# Initialize the agent with ChromaDB memory +agent = Agent( + agent_name="Financial-Analysis-Agent", + model_name="claude-3-sonnet-20240229", + system_prompt="Agent system prompt here", + agent_description="Agent performs financial analysis.", + llm=model, + long_term_memory=chromadb_memory, +) + +# Run a query +agent.run("What are the components of a startup's stock incentive equity plan?") +``` \ No newline at end of file diff --git a/docs/swarms/examples/groq.md b/docs/swarms/examples/groq.md new file mode 100644 index 000000000..928a92903 --- /dev/null +++ b/docs/swarms/examples/groq.md @@ -0,0 +1,47 @@ +# Agent with Groq + + +```python +import os + +from swarm_models import OpenAIChat + +from swarms import Agent + +company = "NVDA" + +# Get the OpenAI API key from the environment variable +api_key = os.getenv("GROQ_API_KEY") + +# Model +model = OpenAIChat( + openai_api_base="https://api.groq.com/openai/v1", + openai_api_key=api_key, + model_name="llama-3.1-70b-versatile", + temperature=0.1, +) + + +# Initialize the Managing Director agent +managing_director = Agent( + agent_name="Managing-Director", + system_prompt=f""" + As the Managing Director at Blackstone, your role is to oversee the entire investment analysis process for potential acquisitions. + Your responsibilities include: + 1. Setting the overall strategy and direction for the analysis + 2. Coordinating the efforts of the various team members and ensuring a comprehensive evaluation + 3. Reviewing the findings and recommendations from each team member + 4. Making the final decision on whether to proceed with the acquisition + + For the current potential acquisition of {company}, direct the tasks for the team to thoroughly analyze all aspects of the company, including its financials, industry position, technology, market potential, and regulatory compliance. Provide guidance and feedback as needed to ensure a rigorous and unbiased assessment. + """, + llm=model, + max_loops=1, + dashboard=False, + streaming_on=True, + verbose=True, + stopping_token="", + state_save_file_type="json", + saved_state_path="managing-director.json", +) +``` \ No newline at end of file diff --git a/docs/swarms/examples/openai_example.md b/docs/swarms/examples/openai_example.md new file mode 100644 index 000000000..0741a1203 --- /dev/null +++ b/docs/swarms/examples/openai_example.md @@ -0,0 +1,13 @@ +# Agent with GPT-4o-Mini + +```python +from swarms import Agent + +Agent( + agent_name="Stock-Analysis-Agent", + model_name="gpt-4o-mini", + max_loops="auto", + interactive=True, + streaming_on=True, +).run("What are 5 hft algorithms") +``` \ No newline at end of file diff --git a/new_features_examples/csvagent_example.py b/new_features_examples/csvagent_example.py index e781335a1..f47ae9057 100644 --- a/new_features_examples/csvagent_example.py +++ b/new_features_examples/csvagent_example.py @@ -1,6 +1,9 @@ # Example usage from pathlib import Path -from swarms.structs.csv_to_agent import AgentLoader, AgentValidationError +from swarms.structs.csv_to_agent import ( + AgentLoader, + AgentValidationError, +) if __name__ == "__main__": diff --git a/swarms/structs/csv_to_agent.py b/swarms/structs/csv_to_agent.py index aa6fdf73c..624e35774 100644 --- a/swarms/structs/csv_to_agent.py +++ b/swarms/structs/csv_to_agent.py @@ -136,6 +136,7 @@ def validate_config(config: Dict[str, Any]) -> AgentConfigDict: str(e), str(e.__class__.__name__), str(config) ) + class AgentLoader: """Class to manage agents through CSV with type safety""" @@ -202,7 +203,9 @@ def load_agents(self, file_type: str = "csv") -> List[Agent]: elif file_type == "json": return self._load_agents_from_json() else: - raise ValueError("Unsupported file type. Use 'csv' or 'json'.") + raise ValueError( + "Unsupported file type. Use 'csv' or 'json'." + ) def _load_agents_from_csv(self) -> List[Agent]: """Load agents from a CSV file""" @@ -229,13 +232,13 @@ def _load_agents_from_json(self) -> List[Agent]: """Load agents from a JSON file""" import json - if not self.csv_path.with_suffix('.json').exists(): + if not self.csv_path.with_suffix(".json").exists(): raise FileNotFoundError( f"JSON file not found at {self.csv_path.with_suffix('.json')}" ) agents: List[Agent] = [] - with open(self.csv_path.with_suffix('.json'), "r") as f: + with open(self.csv_path.with_suffix(".json"), "r") as f: agents_data = json.load(f) for agent in agents_data: try: @@ -250,10 +253,14 @@ def _load_agents_from_json(self) -> List[Agent]: ) continue - print(f"Loaded {len(agents)} agents from {self.csv_path.with_suffix('.json')}") + print( + f"Loaded {len(agents)} agents from {self.csv_path.with_suffix('.json')}" + ) return agents - def _create_agent(self, validated_config: AgentConfigDict) -> Agent: + def _create_agent( + self, validated_config: AgentConfigDict + ) -> Agent: """Create an Agent instance from validated configuration""" return Agent( agent_name=validated_config["agent_name"], @@ -263,7 +270,9 @@ def _create_agent(self, validated_config: AgentConfigDict) -> Agent: autosave=validated_config["autosave"], dashboard=validated_config["dashboard"], verbose=validated_config["verbose"], - dynamic_temperature_enabled=validated_config["dynamic_temperature"], + dynamic_temperature_enabled=validated_config[ + "dynamic_temperature" + ], saved_state_path=validated_config["saved_state_path"], user_name=validated_config["user_name"], retry_attempts=validated_config["retry_attempts"], @@ -271,4 +280,4 @@ def _create_agent(self, validated_config: AgentConfigDict) -> Agent: return_step_meta=validated_config["return_step_meta"], output_type=validated_config["output_type"], streaming_on=validated_config["streaming"], - ) \ No newline at end of file + ) diff --git a/swarms/structs/graph_swarm.py b/swarms/structs/graph_swarm.py index 70f2323eb..e67add52f 100644 --- a/swarms/structs/graph_swarm.py +++ b/swarms/structs/graph_swarm.py @@ -190,7 +190,7 @@ class GraphSwarm: def __init__( self, name: str = "graph-swarm-01", - description: str = "Graph swarm : build your own graph of agents", + description: str = "Graph swarm : build your own graph of agents", agents: Union[ List[Agent], List[Tuple[Agent, List[str]]], List[Callable] ] = None, diff --git a/swarms/telemetry/bootup.py b/swarms/telemetry/bootup.py index 1f2acd5aa..edb491335 100644 --- a/swarms/telemetry/bootup.py +++ b/swarms/telemetry/bootup.py @@ -54,7 +54,3 @@ def bootup(): except Exception as e: logger.error(f"Error during bootup: {str(e)}") raise - - -# Run bootup -bootup()