From adcc622f8b1ff38fa8f8757583bee185be773d4f Mon Sep 17 00:00:00 2001 From: William M Schmidt Date: Tue, 12 Nov 2024 00:39:57 +0100 Subject: [PATCH] feat: works now without tavily api key --- core/Agents/neo_agent.py | 17 +++++++++++------ core/main.py | 5 ++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/Agents/neo_agent.py b/core/Agents/neo_agent.py index 39e42c8..6bf36d5 100644 --- a/core/Agents/neo_agent.py +++ b/core/Agents/neo_agent.py @@ -1,5 +1,6 @@ from typing import Annotated from typing_extensions import TypedDict +import os from langgraph.graph.message import add_messages from langchain_openai import ChatOpenAI @@ -41,12 +42,16 @@ def __init__(self): ) # Using ChatGPT hardcoded (TODO: Make this dynamic) # Defining the checkpoint memory saver. memory = MemorySaver() - - # Defining the tavily web-search tool - tavily = TavilySearchResults(max_results=2) - - # Adding tools and creating the tool node. - tools = [add, tavily] + # Tools list + tools = [add] + + if os.getenv("TAVILY_API_KEY"): + # Defining the tavily web-search tool + tavily = TavilySearchResults(max_results=2) + tools = [add, tavily] + else: + print("TAVILY_API_KEY does not exist.") + tool_node = ToolNode(tools) llm_with_tools = model.bind_tools(tools) diff --git a/core/main.py b/core/main.py index fcf54f1..9669a96 100644 --- a/core/main.py +++ b/core/main.py @@ -14,7 +14,6 @@ import logging log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) -from time import sleep from collections import defaultdict # @@ -34,8 +33,8 @@ # Agent instantiation # Graph() contains all complex tools # NeoAgent() is a simple ReAct agent that only has websearch and the add tool. For testing purposes. -jarvis = Graph() # API key is configured in agent.py -#jarvis = NeoAgent() +#jarvis = Graph() # API key is configured in agent.py +jarvis = NeoAgent() # Initialize active_chats with the correct format active_chats = defaultdict(lambda: {"chat_history": []})