Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
#	src/sayvai_tools/tools/audio/streaming.py
  • Loading branch information
srinick007 committed Nov 6, 2023
2 parents cb75295 + b19bfbb commit 105bb95
Show file tree
Hide file tree
Showing 70 changed files with 1,905 additions and 498 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: sayvai-tools

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
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
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest tests/
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ sayvai_tools.egg-info
engine.py
translation-396717-e2931c0fd933.json
.idea

src/sayvai_tools/utils/phrase_set.yaml
db.py
dist
sayvai.db
test.py
tests/__pycache__
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
clean:
rm -rf build
rm -rf dist
rm -rf *.egg-info
rm -rf src/sayvai_tools/__pycache__
rm -rf __pycache__
rm -rf src/sayvai_tools.egg-info

build:
apt-get update && apt-get install libasound-dev libportaudio2 libportaudiocpp0 portaudio19-dev -y

install:
pip install .

43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Sayvai-Tools

## How to use
---------------------------------------

## Installation
### Install via git clone

```bash
$git clone https://github.com/Sayvai-io/custom-tools.git
$cd sayvai-tools
```
and
```bash
$pip install .
```
### Install via pip
```bash
$pip install sayvai-tools
```
### Install via pipenv
```bash
$pipenv install sayvai-tools
```

## What is Sayvai-Tools?
---------------------------------------
Sayvai-Tools is a collection of tools that we use at Sayvai.io to help us build our products. We are making these tools available to the public in hopes that they will help you build your products as well. These tools are meant for langchain developers and are not meant to be used by end users.

# Documentation
---------------------------------------
Documentation is available at https://sayvai-io.github.io/custom-tools/


1. [Sayvai-Tools](#sayvai-tools)
2. [How to use](#how-to-use)
3. [What is Sayvai-Tools?](#what-is-sayvai-tools)
4. [Documentation](#documentation)
5. [Installation](#installation)
1. [Install via git clone](#install-via-git-clone)
2. [Install via pip](#install-via-pip)
3. [Install via pipenv](#install-via-pipenv)

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#config file
name = "sayvai_tools"
version = "0.0.1"
13 changes: 13 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
elevenlabs~=0.2.24
langchain~=0.0.292
typing~=3.7.4.3
SQLAlchemy~=2.0.20
PyYAML~=6.0
google~=3.0.0
numpy~=1.23.3
pydub~=0.25.1
setuptools~=58.2.0
pre-commit~=3.5.0
pytest
pyaudio
pydub
54 changes: 31 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

core_requirements = [
'langchain',
'langchain_experimental',
'google-api-python-client',
'openai',
'SQLAlchemy',
'elevenlabs==0.2.24',
'google_auth_oauthlib',
'google-auth-httplib2',
'pyaudio',
'pydub',
'numpy',
'google',
'google-cloud-speech'
"langchain",
"langchain_experimental",
"google-api-python-client",
"openai",
"tiktoken",
"SQLAlchemy",
"elevenlabs==0.2.24",
"google_auth_oauthlib",
"google-auth-httplib2",
"numpy",
"google",
"google-cloud-speech",
"cloud-sql-python-connector",
"pg8000",
"pinecone-client",
"pgvector",
"pandas",
"openpyxl",
"gspread==5.11.3",
"pyaudio",
"pydub",
"oauth2client"
]

setup(
name='sayvai_tools',
version='0.0.1',
description='Tools for the assistant',
author='sayvai-io',
name="sayvai_tools",
version="0.0.1",
description="Tools for the assistant",
author="sayvai-io",
package_dir={"": "src"},
packages=find_packages(where="src"),
install_requires=core_requirements,
extras_require={
'dev': [
'pytest',
'pylint',
"dev": [
"pytest",
"pylint",
],
},
zip_safe=False
zip_safe=False,
)

4 changes: 3 additions & 1 deletion src/sayvai_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.0.2"
__version__ = "0.0.1"
__author__ = "sayvai-io"
__author_email__ = "sanjaypranav@sayvai.io"
2 changes: 1 addition & 1 deletion src/sayvai_tools/tools/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from sayvai_tools.tools.audio.streaming import VoiceOutputRun

__all__ = [ "VoiceOutputRun"]
__all__ = ["VoiceOutputRun"]
27 changes: 15 additions & 12 deletions src/sayvai_tools/tools/audio/streaming.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""base tool for IO"""
from typing import Callable

from elevenlabs import play
from sayvai_tools.utils.tts import ElevenlabsAudioStreaming
from langchain.pydantic_v1 import Field
from typing import Callable
from sayvai_tools.utils.voice.tts import ElevenlabsAudioStreaming


class VoiceOutputRun:
Expand All @@ -21,17 +22,19 @@ def __init__(self, api_key: str) -> None:
pass

def _run(
self,
query: str,
self,
query: str,
):
"""Use the Human input tool."""
# input_func: Callable = Field(default_factory=lambda: input)
tts = ElevenlabsAudioStreaming(self.api_key)
inputbytes = tts.audio_streaming(query,
model="eleven_multilingual_v1",
voice="Adam",
audio_streaming=True,
stability=0.5,
similarity=0.5
)
tts = ElevenlabsAudioStreaming()
inputbytes = 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)
5 changes: 3 additions & 2 deletions src/sayvai_tools/tools/calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from sayvai_tools.tools.calendar.tool import Calendar
from sayvai_tools.tools.calendar.calendar_sql.tool import CalendarSql
from sayvai_tools.tools.calendar.calendar import Calendar

__all__ = ['Calendar']
__all__ = ["Calendar", "CalendarSql"]
3 changes: 3 additions & 0 deletions src/sayvai_tools/tools/calendar/calendar/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sayvai_tools.tools.calendar.calendar.tool import Calendar

__all__ = ["Calendar"]
18 changes: 18 additions & 0 deletions src/sayvai_tools/tools/calendar/calendar/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sayvai_tools.utils.google.gcalendar import GCalendar


class Calendar:
name = "calendar"
description = "You can ask calendar tool to create an event for you."

def __init__(self, scope: str, email: str, summary: str):
self.scope = scope
self.email = email
self.summary = summary
self.cal = GCalendar(scope=self.scope, email=self.email, summary=self.summary)

def _run(self, date: str):
return self.cal.book_slots(date)

async def _arun(self, date: str):
raise NotImplementedError("Calendar async not implemented")
3 changes: 3 additions & 0 deletions src/sayvai_tools/tools/calendar/calendar_sql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sayvai_tools.tools.calendar.calendar_sql.tool import CalendarSql

__all__ = ["CalendarSql"]
52 changes: 52 additions & 0 deletions src/sayvai_tools/tools/calendar/calendar_sql/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from sayvai_tools.utils.google.gcalendar import GCalendar
from sqlalchemy import text


class CalendarSql:
name = "calendar_sql"
description = "You can ask calendar_sql tool to create an event for you."

def __init__(self, pool, scope: str, email: str, summary: str):
self.pool = pool
self.cursor = self.pool.connect()
self.scope = scope
self.email = email
self.summary = summary
self.cal = GCalendar(self.scope, email=self.email, summary=self.summary)

def _run(self, details: str):
start_time, end_time, phone, name = details.split("/")
start_time = self.cal.parse_date(start_time)
end_time = self.cal.parse_date(end_time)

specific_date = start_time.date()
date_string = specific_date.strftime("%Y-%m-%d")

query = self.cursor.execute(text(f"""SELECT phone_number FROM patient_info;"""))
phone_number = query.fetchall()
phone_number = [i[0] for i in phone_number]
result = self.cal.book_slots(details)
if len(result) == 2 and result[0] == "Event created":
msg, event_id = result[0], result[1]
if details.split("/")[2] not in phone_number:
query = self.cursor.execute(
text(
f"""INSERT INTO patient_info (name, phone_number, start_time, end_time, event_id, appointment_date) VALUES ('{name}', '{phone}'
, '{start_time}', '{end_time}','{event_id}','{date_string}');"""
)
)
# query.commit()
else:
query = self.cursor.execute(
text(
f"""UPDATE patient_info SET start_time = '{start_time}', end_time = '{end_time}', event_id = '{event_id}', appointment_date = '{date_string}' WHERE phone_number = '{phone}';"""
)
)
# query.commit()

return msg
else:
return result

async def _arun(self, date: str):
raise NotImplementedError("Calendar async not implemented")
25 changes: 10 additions & 15 deletions src/sayvai_tools/tools/calendar/tool.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import datetime
from sayvai_tools.utils.google.gcalendar import GCalendar

from langchain.tools.base import BaseTool

from sayvai_tools.utils.gcalendar import GCalendar


class Calendar():

class Calendar:
name = "calendar"
description = (
"You can ask calendar tool to create an event for you."
)
description = "You can ask calendar tool to create an event for you."

def __init__(self, scope: str):
self.scope = scope
self.cal = GCalendar(self.scope)

def _run(self, date: str):
cal = GCalendar()
return cal.check_is_slot_available(date)

async def _arun(self, date: str):
return self.cal.book_slots(date)

raise NotImplementedError("Calendar async not implemented")
async def _arun(self, date: str):
raise NotImplementedError("Calendar async not implemented")
3 changes: 3 additions & 0 deletions src/sayvai_tools/tools/calendar_block/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from sayvai_tools.tools.calendar_block.tool import Block

__all__ = ["Block"]
Loading

0 comments on commit 105bb95

Please sign in to comment.