-
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.
Delete current time from prompt and make it a Tool
- Loading branch information
Showing
3 changed files
with
31 additions
and
15 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -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}" | ||
) | ||
|
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 |
---|---|---|
@@ -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") |