Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-cartesia-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ajar98 committed Jul 3, 2024
2 parents c2c68e6 + 60d2187 commit 9b5d5ca
Show file tree
Hide file tree
Showing 67 changed files with 1,228 additions and 644 deletions.
74 changes: 55 additions & 19 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,87 @@ on:
pull_request:
branches: [main, vocode-core-0.1.0]

env:
poetry-version: "1.8.3"

jobs:
build:
lint:
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
poetry-version:
- "1.7.1"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install ffmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Set up Poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ env.poetry-version }}

- name: Install dependencies
run: poetry install -E all

- name: Run mypy
run: |
poetry run mypy -p vocode
poetry run mypy -p quickstarts
poetry run mypy -p playground
- name: Run black
if: success() || failure()
run: poetry run black --check .

- name: Run isort
shell: bash
if: success() || failure()
run: poetry run isort --check .

pytest:
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install ffmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Install poetry ${{ matrix.poetry-version }}
run: |
python -m ensurepip
python -m pip install --upgrade pip
python -m pip install poetry==${{ matrix.poetry-version }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: View poetry --help
run: poetry --help
- name: Set up Poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ env.poetry-version }}

- name: Install dependencies
shell: bash
run: python -m poetry install -E all

- name: Lint with mypy
run: |
python -m poetry run mypy -p vocode
python -m poetry run mypy -p quickstarts
python -m poetry run mypy -p playground
run: poetry install -E all

- name: Test with pytest
run: |
python -m poetry run python -m pytest -v tests
poetry run pytest -v tests
52 changes: 40 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
default_language_version:
python: python3.10

repos:
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
args: [--ignore-missing-imports, ./]
language: system
pass_filenames: false
stages: [pre-push]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-ast
- id: trailing-whitespace
- id: check-toml
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: detect-private-key
- id: mixed-line-ending
args:
- --fix=lf

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-yaml
args:
- --autofix
- --preserve-quotes
- --indent=2

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args:
- --settings-path=./pyproject.toml

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
args:
- --config=./pyproject.toml
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-python.black-formatter",
"ms-python.isort",
"ms-python.python",
"ms-python.vscode-pylance"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"black-formatter.args": ["--config", "./pyproject.toml"],
"isort.args": ["--settings-path", "./pyproject.toml"],
"rewrap.autoWrap.enabled": true,
"rewrap.wrappingColumn": 100,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"isort.check": true
}
12 changes: 3 additions & 9 deletions apps/langchain_agent/call_transcript_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@


def add_transcript(conversation_id: str, transcript: str) -> None:
transcript_path = os.path.join(
CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id)
)
transcript_path = os.path.join(CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id))
with open(transcript_path, "a") as f:
f.write(transcript)


def get_transcript(conversation_id: str) -> Optional[str]:
transcript_path = os.path.join(
CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id)
)
transcript_path = os.path.join(CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id))
if os.path.exists(transcript_path):
with open(transcript_path, "r") as f:
return f.read()
return None


def delete_transcript(conversation_id: str) -> bool:
transcript_path = os.path.join(
CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id)
)
transcript_path = os.path.join(CALL_TRANSCRIPTS_DIR, "{}.txt".format(conversation_id))
if os.path.exists(transcript_path):
os.remove(transcript_path)
return True
Expand Down
17 changes: 6 additions & 11 deletions apps/langchain_agent/main.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import os
import sys
import typing
from dotenv import load_dotenv

from dotenv import load_dotenv
from langchain.memory import ConversationBufferMemory
from stdout_filterer import RedactPhoneNumbers
from tools.contacts import get_all_contacts
from tools.vocode import call_phone_number
from tools.word_of_the_day import word_of_the_day

from vocode.turn_based.synthesizer.azure_synthesizer import AzureSynthesizer
from vocode.turn_based.synthesizer.gtts_synthesizer import GTTSSynthesizer
from langchain.memory import ConversationBufferMemory


from stdout_filterer import RedactPhoneNumbers

load_dotenv()

from langchain.agents import AgentType, initialize_agent
from langchain.chat_models import ChatOpenAI
from langchain.agents import initialize_agent
from langchain.agents import AgentType

if __name__ == "__main__":
# Redirect stdout to our custom class
sys.stdout = typing.cast(typing.TextIO, RedactPhoneNumbers(sys.stdout))

OBJECTIVE = (
input("Objective: ")
or "Find a random person in my contacts and tell them a joke"
)
OBJECTIVE = input("Objective: ") or "Find a random person in my contacts and tell them a joke"
llm = ChatOpenAI(temperature=0, model_name="gpt-4") # type: ignore
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
# Logging of LLMChains
Expand Down
15 changes: 6 additions & 9 deletions apps/langchain_agent/telephony_app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import logging
import os
import typing

from call_transcript_utils import add_transcript
from dotenv import load_dotenv
from fastapi import FastAPI

from vocode.streaming.models.events import Event, EventType
from vocode.streaming.models.transcript import TranscriptCompleteEvent
from vocode.streaming.utils import events_manager

from vocode.streaming.telephony.config_manager.redis_config_manager import (
RedisConfigManager,
)
from vocode.streaming.telephony.config_manager.redis_config_manager import RedisConfigManager
from vocode.streaming.telephony.server.base import TelephonyServer

from call_transcript_utils import add_transcript

from dotenv import load_dotenv
from vocode.streaming.utils import events_manager

load_dotenv()

Expand Down
1 change: 1 addition & 0 deletions apps/langchain_agent/tools/contacts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List

from langchain.agents import tool

CONTACTS = [{"name": "Ajay", "phone": "+15555555555"}]
Expand Down
17 changes: 9 additions & 8 deletions apps/langchain_agent/tools/vocode.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import logging
import asyncio
import logging
import os
from langchain.agents import tool

from call_transcript_utils import delete_transcript, get_transcript
from dotenv import load_dotenv
from langchain.agents import tool

from vocode.streaming.models.message import BaseMessage
from call_transcript_utils import delete_transcript, get_transcript

load_dotenv()

from vocode.streaming.telephony.conversation.outbound_call import OutboundCall
from vocode.streaming.telephony.config_manager.redis_config_manager import (
RedisConfigManager,
)
from vocode.streaming.models.agent import ChatGPTAgentConfig
import time

from vocode.streaming.models.agent import ChatGPTAgentConfig
from vocode.streaming.telephony.config_manager.redis_config_manager import RedisConfigManager
from vocode.streaming.telephony.conversation.outbound_call import OutboundCall

LOOP = asyncio.new_event_loop()
asyncio.set_event_loop(LOOP)


@tool("call phone number")
def call_phone_number(input: str) -> str:
"""calls a phone number as a bot and returns a transcript of the conversation.
Expand Down
3 changes: 2 additions & 1 deletion apps/langchain_agent/tools/word_of_the_day.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List
from langchain.agents import tool

import requests
from langchain.agents import tool

WORDNIK_URL_WITH_KEY = "https://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=d52b63b6880f17811310d0fbd3b0d3a8ef163a248f58dc831"

Expand Down
Loading

0 comments on commit 9b5d5ca

Please sign in to comment.