Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs #83

Merged
merged 6 commits into from
Apr 2, 2024
Merged

Docs #83

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 30 additions & 54 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ google-api-python-client = "^2.116.0"
pymupdf = "^1.23.21"
google-auth-oauthlib = "^1.2.0"
google-auth-httplib2 = "^0.2.0"
langchain = "^0.1.11"
langchain = "^0.1.14"
langchain-core = "^0.1.25"
langchain-community = "^0.0.27"
langchain-openai = "^0.0.8"
langchain-community = "^0.0.31"
langchain-openai = "^0.1.1"
pydantic = "2.6.1"
langchain-pinecone = "^0.0.3"

Expand Down
2 changes: 2 additions & 0 deletions src/sayvai_tools/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from sayvai_tools.tools.loader import load_tools
from sayvai_tools.tools.pdfreader import (ReadPagesTool, ReadPageTool,
ReadPDFTool)
from sayvai_tools.tools.pincone import PineconeTool
from sayvai_tools.tools.retrive_details import RetrieveEmail, RetrievePhone
from sayvai_tools.tools.send_mail import SendMail
from sayvai_tools.tools.sql_database import Database
Expand Down Expand Up @@ -53,6 +54,7 @@
"InsertCommentTool",
"ListCommentRepliesTool",
"ReplyToCommentTool",
"PineconeTool",
"load_tools",
]

Expand Down
6 changes: 4 additions & 2 deletions src/sayvai_tools/tools/google_calendar/display_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ def _run(
**kwargs,
) -> List[dict]:
try:
events = self._display_events(calendar_id=kwargs.get("calendar_id", "primary"),
max_results=kwargs.get("max_results", 10))
events = self._display_events(
calendar_id=kwargs.get("calendar_id", "primary"),
max_results=kwargs.get("max_results", 10),
)
return events
except Exception as e:
raise Exception(f"An error occurred: {e}")
2 changes: 2 additions & 0 deletions src/sayvai_tools/tools/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_sheets_credentials)
from sayvai_tools.tools.pdfreader import (ReadPagesTool, ReadPageTool,
ReadPDFTool)
from sayvai_tools.tools.pincone import PineconeTool
from sayvai_tools.tools.retrive_details import RetrieveEmail, RetrievePhone
from sayvai_tools.tools.send_mail import SendMail
from sayvai_tools.tools.sql_database import Database
Expand Down Expand Up @@ -49,6 +50,7 @@
"RetrieveEmail": RetrieveEmail,
"RetrievePhone": RetrievePhone,
"Database": Database,
"PineconeTool": PineconeTool,
}


Expand Down
5 changes: 5 additions & 0 deletions src/sayvai_tools/tools/pinecone/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Pinecone tool for searching from vector database"""

from sayvai_tools.tools.pincone.tool import PineconeTool

__all__ = ["PineconeTool"]
47 changes: 47 additions & 0 deletions src/sayvai_tools/tools/pinecone/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Pinceone as a Tool
import os
from typing import Optional

from langchain_core.callbacks import (AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun)
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
from langchain_core.tools import BaseTool
from langchain_openai import OpenAIEmbeddings
from langchain_pinecone import PineconeVectorStore


class BasePineconeTool(BaseModel):
"""Base tool for interacting with a pinecone vector database."""

class _QueryPinconeBaseToolInput(BaseModel):
query: str = Field(..., description="A natural language question")


class PineconeTool(BasePineconeTool, BaseTool):
"""Tool that queries the Pinecone API."""

name: str = "pinecone-search"
description: str = (
"pinecone-search searches from vector database"
"This tool is will search answer for user's query from Pincone"
"Input should be a search query."
)

vectorstore: PineconeVectorStore = Field(
default_factory=lambda: PineconeVectorStore.from_existing_index(
index_name=os.environ["PINECONE_INDEX"], embedding=OpenAIEmbeddings()
),
description="The Pinecone vector store",
)

@classmethod
def create(cls, **kwargs) -> "PineconeTool":
return cls()

def _run(
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the tool."""
return self.vectorstore.similarity_search(query=query)[0].page_content
4 changes: 3 additions & 1 deletion src/sayvai_tools/tools/sql_database/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
# )


@deprecated(message="Use langchain tool instead, Database will be removed from sayvai-tools 0.0.5")
@deprecated(
message="Use langchain tool instead, Database will be removed from sayvai-tools 0.0.5"
)
class Database:
"""Tool that queries vector database."""

Expand Down
Loading