Skip to content

Commit

Permalink
Merge pull request #48 from Sayvai-io/version
Browse files Browse the repository at this point in the history
Version
  • Loading branch information
Nandhini25S authored Jan 10, 2024
2 parents 256c841 + d82447e commit 1d4c843
Show file tree
Hide file tree
Showing 32 changed files with 3,594 additions and 534 deletions.
1 change: 0 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
sudo make build
pip install .
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ tests/__pycache__
.pytest_cache/*
client_secrets.json
credentials (1).json
.env
.env
docs.txt
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ build:

install:
pip install .

format:
black src/

3,017 changes: 3,017 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
[tool.poetry]
name = "sayvai-tools"
version = "0.0.2"
version = "0.0.3"
description = "A python framwork for customising langchain assiatants."
authors = ["sayvai <[email protected]>"]
license = "MIT"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.11"
pyaudio = "0.2.11"
openai = "0.28.0"
rich = "13.7.0"
pinecone-client = "2.2.4"
langchain = "0.0.292"
llama-index = "0.8.22"
transformers = "^4.36.2"
sqlalchemy = "2.0.20"
elevenlabs = "0.2.24"
google-auth-oauthlib = "^1.2.0"
google-auth-httplib2 = "^0.2.0"
numpy = "^1.26.3"
google = "^3.0.0"
google-cloud-speech = "^2.23.0"
cloud-sql-python-connector = "^1.5.0"
pg8000 = "^1.30.4"
pgvector = "^0.2.4"
pandas = "^2.1.4"
openpyxl = "^3.1.2"
gspread = "5.11.3"
pydub = "^0.25.1"
oauth2client = "^4.1.3"
pytest = "^7.4.4"
python-dotenv = "^1.0.0"


[build-system]
Expand Down
44 changes: 0 additions & 44 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/sayvai_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.0.2"
__version__ = "0.0.3"
__author__ = "sayvai-io"
__author_email__ = "[email protected]"
93 changes: 48 additions & 45 deletions src/sayvai_tools/tools/conversational_human/iohuman.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
"""Conversational Human """
import os
from typing import Callable, Optional
# """Conversational Human """
# import os
# from typing import Callable, Optional

from elevenlabs import play
from langchain.callbacks.manager import CallbackManagerForToolRun
from langchain.pydantic_v1 import Field
# from elevenlabs import play
# from langchain.callbacks.manager import CallbackManagerForToolRun
# from langchain.pydantic_v1 import Field

from sayvai_tools.utils.voice.stt import STT
from sayvai_tools.utils.voice.tts import ElevenlabsAudioStreaming
# from sayvai_tools.utils.voice.stt import STT
# from sayvai_tools.utils.voice.tts import ElevenlabsAudioStreaming


class ConversationalHuman:
"""Tool that asks user for input."""

name: str = "human"
description: str = (
"You can ask a human for guidance when you think you "
"got stuck or you are not sure what to do next. "
"The input should be a question for the human."
)
# prompt_func: Callable[[str], None] = Field(default_factory=lambda: _print_func)
# input_func: Callable = Field(default_factory=lambda: input)

def __init__(self, api_key: str, g_api_key: str, phrase_set_path: str) -> None:
self.stt = STT(audio_format="mp3", speech_context_path=phrase_set_path)
self.tts = ElevenlabsAudioStreaming(api_key=api_key)
self.g_api_key = g_api_key

def _run(
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
"""Use the Human input tool."""
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.g_api_key
inputbytes = self.tts.audio_streaming(
query,
model="eleven_multilingual_v1",
voice="Adam",
audio_streaming=True,
stability=0.5,
similarity=0.5,
# api_key= self.api_key
)
play(inputbytes)

# self.prompt_func(query)
# return self.input_func()
return self.stt.generate_text()
raise "NotImplementedError"


# """Tool that asks user for input."""

# name: str = "human"
# description: str = (
# "You can ask a human for guidance when you think you "
# "got stuck or you are not sure what to do next. "
# "The input should be a question for the human."
# )
# # prompt_func: Callable[[str], None] = Field(default_factory=lambda: _print_func)
# # input_func: Callable = Field(default_factory=lambda: input)

# def __init__(self, api_key: str, g_api_key: str, phrase_set_path: str) -> None:
# self.stt = STT(audio_format="mp3", speech_context_path=phrase_set_path)
# self.tts = ElevenlabsAudioStreaming(api_key=api_key)
# self.g_api_key = g_api_key

# def _run(
# self,
# query: str,
# run_manager: Optional[CallbackManagerForToolRun] = None,
# ) -> str:
# """Use the Human input tool."""
# os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = self.g_api_key
# inputbytes = self.tts.audio_streaming(
# query,
# model="eleven_multilingual_v1",
# voice="Adam",
# audio_streaming=True,
# stability=0.5,
# similarity=0.5,
# # api_key= self.api_key
# )
# play(inputbytes)

# # self.prompt_func(query)
# # return self.input_func()
# return self.stt.generate_text()
2 changes: 1 addition & 1 deletion src/sayvai_tools/tools/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""init file for forms"""
"""init file for forms"""
3 changes: 1 addition & 2 deletions src/sayvai_tools/tools/retrive_details/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from sayvai_tools.tools.retrive_details.retrive_email.tool import RetrieveEmail
from sayvai_tools.tools.retrive_details.retrive_phone.tool import RetrievePhone

__all__ = ["RetrieveEmail",
"RetrievePhone"]
__all__ = ["RetrieveEmail", "RetrievePhone"]
2 changes: 1 addition & 1 deletion src/sayvai_tools/tools/send_mail/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
## init file for send mail
## init file for send mail
2 changes: 1 addition & 1 deletion src/sayvai_tools/tools/send_mail/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def _run(self, content: str):
return "Mail sent successfully"

async def _arun(self, content: str):
raise NotImplementedError("Send mail via async not implemented")
raise NotImplementedError("Send mail via async not implemented")
1 change: 0 additions & 1 deletion src/sayvai_tools/tools/spreadsheets/gsheets/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Sheets:

name = "sheets"
description = (
"Useful for creating and updating sheets."
Expand Down
20 changes: 13 additions & 7 deletions src/sayvai_tools/tools/spreadsheets/sql_sheets/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
from langchain.schema.language_model import BaseLanguageModel
from sayvai_tools.tools.sql_database.prompt import PROMPT, SQL_PROMPTS


class SQLSheet:
NotImplementedError


# name = "sqlsheet"
# description = (
# "Useful for exporting SQL query results to a spreadsheet."
Expand All @@ -33,7 +36,13 @@ class SQLGSheet:
"You can use this to generate reports."
)

def __init__(self, uri: str, llm: BaseLanguageModel, prompt: Optional[BasePromptTemplate] = None, verbose: bool = False):
def __init__(
self,
uri: str,
llm: BaseLanguageModel,
prompt: Optional[BasePromptTemplate] = None,
verbose: bool = False,
):
self.gs = GSheets()
self.connection = create_engine(uri).connect()
self.db = SQLDatabaseSheetsBase(engine=self.connection)
Expand All @@ -42,7 +51,7 @@ def __init__(self, uri: str, llm: BaseLanguageModel, prompt: Optional[BasePrompt
self.verbose = verbose

# sample input save past 30 days data to google sheet from record table
# table fetched from sql query
# table fetched from sql query

def _run(self, query: str):
if self.prompt is not None:
Expand All @@ -68,14 +77,11 @@ def _run(self, query: str):
return sql_db_chain.run(query)





# chain_ouput : str = self.chain.run(query)
# rprint(f"[bold purple]{chain_ouput}[/bold purple]")
# return "Data has been exported to Google Sheets"


# df = pd.read_sql_query(text(chain_ouput), self.connection)
# data_dict = df.to_dict("split")
# columns = data_dict["columns"]
Expand Down
1 change: 0 additions & 1 deletion src/sayvai_tools/tools/sql_database/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,4 @@ def _run(self, query: str) -> str:
return sql_db_chain.run(query)

async def _arun(self, query: str):

raise NotImplementedError("SQL database async not implemented")
3 changes: 2 additions & 1 deletion src/sayvai_tools/tools/vectordb/pgvector/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async def _arun(self, query: str):

class LoadDocs:
"""The PGVector Module will try to create a table with the name of the collection.
So, make sure that the collection name is unique and the user has the permission to create a table."""
So, make sure that the collection name is unique and the user has the permission to create a table.
"""

def __init__(
self, directory, embeddings: Any, collection_name: str, connection_string: str
Expand Down
4 changes: 2 additions & 2 deletions src/sayvai_tools/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from sayvai_tools.utils.google.mail import EmailSender
from sayvai_tools.utils.google.sheets import GSheets
from sayvai_tools.utils.google.forms import GForms
from sayvai_tools.utils.voice.stt import STT

# from sayvai_tools.utils.voice.stt import STT
from sayvai_tools.utils.voice.tts import ElevenlabsAudioStreaming
from sayvai_tools.utils.microsoft.excel import Excel

Expand All @@ -15,7 +16,6 @@
"ElevenlabsAudioStreaming",
"EmailSender",
"GSheets",
"STT",
"GForms",
"Excel",
]
5 changes: 2 additions & 3 deletions src/sayvai_tools/utils/database/dbsheetsbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SQLDatabaseSheetsBase:
def __init__(
self,
engine: Engine,
sheets : GSheets,
sheets: GSheets,
schema: Optional[str] = None,
metadata: Optional[MetaData] = None,
ignore_tables: Optional[List[str]] = None,
Expand Down Expand Up @@ -383,7 +383,6 @@ def _execute(self, command: str, fetch: Optional[str] = "all") -> str:
# for c in commands
# if c.strip() and not c.strip().startswith(("Response:", "Answer:"))
# ]


with self._engine.begin() as connection:
if self._schema is not None:
Expand All @@ -396,7 +395,7 @@ def _execute(self, command: str, fetch: Optional[str] = "all") -> str:
elif self.dialect == "mssql":
pass
else: # postgresql and compatible dialects
connection.exec_driver_sql(f"SET search_path TO {self._schema}")
connection.exec_driver_sql(f"SET search_path TO {self._schema}")
df = pd.read_sql_query(text(command), self._engine)
data_dict = df.to_dict("split")
columns = data_dict["columns"]
Expand Down
2 changes: 1 addition & 1 deletion src/sayvai_tools/utils/google/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# init file for google
# init file for google
Loading

0 comments on commit 1d4c843

Please sign in to comment.