Skip to content

Commit

Permalink
Delete current time from prompt and make it a Tool
Browse files Browse the repository at this point in the history
  • Loading branch information
DEENUU1 committed Jan 24, 2024
1 parent e6691d3 commit 8c3d6d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
20 changes: 13 additions & 7 deletions app/ai/agent.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import langchain
from langchain.agents import AgentExecutor, OpenAIFunctionsAgent
from langchain.chains import RetrievalQA
from langchain.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from langchain_community.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
from langchain_core.messages import SystemMessage
from langchain_core.prompts import MessagesPlaceholder
from langchain_core.tools import Tool

from config.settings import settings
from .llm import get_chat_openai
from .memory import setup_memory
from .prompt import prompt
from langchain.chains import RetrievalQA
from .tools import news, today # , google_calendar
from .vector import get_pinecone
import langchain
from config.settings import settings
from langchain_community.utilities.openweathermap import OpenWeatherMapAPIWrapper
from langchain.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from .tools import news #, google_calendar

langchain.debug = True

Expand Down Expand Up @@ -65,13 +65,19 @@ def setup_agent(session_id: str, model: str) -> AgentExecutor:
wikipedia = WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())
news_tool = news.NewsTool()
# google_calendar_list_event = google_calendar.GoogleCalendarListEventTool()
current_time = today.CurrentTimeTool()

tools = [
# Tool(
# name="GoogleCalendarListEvent",
# func=google_calendar_list_event.run,
# description="Useful for when you need to answer questions about events from Google calendar"
# ),
Tool(
name="CurrentTime",
func=current_time.run,
description="Useful for when you need to answer questions about current time"
),
Tool(
name="News",
func=news_tool.run,
Expand Down
9 changes: 1 addition & 8 deletions app/ai/prompt.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
from langchain.prompts import PromptTemplate
from .tools.today import get_current_time
from schemas.user import User


template = PromptTemplate.from_template(
"You are Jarvis an AI assistant which helps me in every day tasks. "
"You always need to tell the truth, if you don't know the answer you can use tools. "
"You follow the instructions you receive from the user as best as you can. "
"Feel free to use any tools available to look up. "
"User data: {user} "
""
"Current time: {datetime} "
""
)

current_time = get_current_time()
user = User()
prompt = template.format(
user=f"first name: {user.first_name} last name: {user.last_name} location: {user.location}",
datetime=current_time
user=f"first name: {user.first_name} last name: {user.last_name} location: {user.location}"
)

17 changes: 17 additions & 0 deletions app/ai/tools/today.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import datetime
from typing import Union, Dict, Tuple
from langchain_core.tools import BaseTool


def get_current_time():
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")


class CurrentTimeTool(BaseTool):
name = "current_time_tool"
description = "Useful for when you need to answer questions about current time"

def _to_args_and_kwargs(self, tool_input: Union[str, Dict]) -> Tuple[Tuple, Dict]:
return (), {}

def _run(self) -> str:
return get_current_time()

async def _arun(self) -> str:
"""Use the tool asynchronously."""
raise NotImplementedError("custom_search does not support async")

0 comments on commit 8c3d6d0

Please sign in to comment.