Skip to content

Commit

Permalink
Merge pull request #11 from ttpss930141011/development
Browse files Browse the repository at this point in the history
feat: add google calendar tool
  • Loading branch information
ttpss930141011 authored Oct 8, 2023
2 parents fd03fe5 + 9412b84 commit 01c420c
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ psycopg2==2.9.7
openai==0.27.8
tiktoken==0.4.0
google-search-results==2.4.2
flake8==6.1.0
flake8==6.1.0
2 changes: 1 addition & 1 deletion src/app/flask_postgresql/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Config(object):
SERVICE_PREFIX = os.environ.get("SERVICE_PREFIX", "")
CHANNEL_SECRET = os.getenv("CHANNEL_SECRET", "")
CHANNEL_ACCESS_TOKEN = os.getenv("CHANNEL_ACCESS_TOKEN", "")
PORT = os.getenv("PORT", 5000)
PORT = int(os.getenv("PORT", 5000))
SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY", "")
CHATBOT_DESCRIPTION = os.getenv("CHATBOT_DESCRIPTION", "")
CHATBOT_LANGUAGE = os.getenv("CHATBOT_LANGUAGE", "")
Expand Down
2 changes: 2 additions & 0 deletions src/infrastructure/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from src.app.flask_postgresql.configs import Config

from .google_calendar import GoogleCalendarTool
from .stock import CurrentStockPriceTool, StockPerformanceTool

# initialize LangChain services
Expand All @@ -16,4 +17,5 @@
),
CurrentStockPriceTool(),
StockPerformanceTool(),
GoogleCalendarTool(),
]
70 changes: 70 additions & 0 deletions src/infrastructure/tools/google_calendar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import datetime
import urllib
from typing import Optional, Type

from langchain.tools import BaseTool
from pydantic import BaseModel, Field


def create_gcal_url(
title="What?", date="20230524T180000/20230524T220000", location="Where?", description=""
):
"""
Generate a Google Calendar URL for creating a new event.
Args:
title (str): The title of the event. Defaults to "What?".
date (str): The date and time of the event in the format "yyyyMMddTHHmmss/yyyyMMddTHHmmss".
Defaults to "20230524T180000/20230524T220000".
location (str): The location of the event. Defaults to "Where?".
description (str): The description of the event. Defaults to an empty string.
Returns:
str: The URL for creating a new event in Google Calendar.
"""

base_url = "https://www.google.com/calendar/render?action=TEMPLATE"
event_url = f"{base_url}&text={urllib.parse.quote(title)}&dates={date}\
&location={urllib.parse.quote(location)}&details={urllib.parse.quote(description)}"

return event_url + "&openExternalBrowser=1"


class GoogleCalendarGeneratorInput(BaseModel):
"""Input for Google Calendar Generator."""

dates: str = Field(
...,
description=f"Datetime symbol if text contained. format should be \
'YYYYMMDDTHHMMSS/YYYYMMDDTHHMMSS'. Current time is {datetime.date.today()}",
)
title: str = Field(..., description="Calendar Title symbol for reserve schedule.")
description: str = Field(
..., description="Calendar Summary text symbol for schedule description."
)
location: str = Field(..., description="Calendar location symbol for reservation.")


class GoogleCalendarTool(BaseTool):
name = "google_calendar_reservation"
description = "Generate Google Calendar url from user text first when containing time, date."
args_schema: Optional[Type[BaseModel]] = GoogleCalendarGeneratorInput

def _run(self, dates: str, title: str, description: str, location: str):
"""
Generates a Google Calendar URL based on the given parameters.
Args:
dates (str): The dates of the event.
title (str): The title of the event.
description (str): The description of the event.
location (str): The location of the event.
Returns:
str: The generated Google Calendar URL.
"""

result = create_gcal_url(title, dates, location, description)

return result

0 comments on commit 01c420c

Please sign in to comment.