Skip to content

Commit

Permalink
move apps to poetry (#342)
Browse files Browse the repository at this point in the history
* move telephony app to poetry

* add client_backend to poetry

* langchain agent

* move docs to poetry

* telephony app prerelease

* prelease client-backend

* langchain-agent prerelease
  • Loading branch information
ajar98 authored Aug 7, 2023
1 parent 939a68c commit 1e8d237
Show file tree
Hide file tree
Showing 17 changed files with 7,324 additions and 45 deletions.
7 changes: 5 additions & 2 deletions apps/client_backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY ./pyproject.toml /code/pyproject.toml
COPY ./poetry.lock /code/poetry.lock
RUN pip install --no-cache-dir --upgrade poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev --no-interaction --no-ansi
COPY main.py /code/main.py

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000"]
2 changes: 1 addition & 1 deletion apps/client_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger.setLevel(logging.DEBUG)

conversation_router = ConversationRouter(
agent=ChatGPTAgent(
agent_thunk=lambda: ChatGPTAgent(
ChatGPTAgentConfig(
initial_message=BaseMessage(text="Hello!"),
prompt_preamble="Have a pleasant conversation about life",
Expand Down
2,210 changes: 2,210 additions & 0 deletions apps/client_backend/poetry.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions apps/client_backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tool.poetry]
name = "client-backend"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
python-dotenv = "^1.0.0"
vocode = "0.1.111a3"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 0 additions & 2 deletions apps/client_backend/requirements.txt

This file was deleted.

7 changes: 5 additions & 2 deletions apps/langchain_agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY ./pyproject.toml /code/pyproject.toml
COPY ./poetry.lock /code/poetry.lock
RUN pip install --no-cache-dir --upgrade poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev --no-interaction --no-ansi
COPY call_transcript_utils.py /code/call_transcript_utils.py
COPY telephony_app.py /code/telephony_app.py
RUN mkdir /code/call_transcripts
Expand Down
2 changes: 1 addition & 1 deletion apps/langchain_agent/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import sys
import typing
from dotenv import load_dotenv
from apps.langchain_agent.tools.word_of_the_day import word_of_the_day

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
Expand Down
2,640 changes: 2,640 additions & 0 deletions apps/langchain_agent/poetry.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions apps/langchain_agent/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "langchain-agent"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
redis = "^4.5.4"
twilio = "^8.1.0"
vonage = "^3.5.1"
python-dotenv = "^1.0.0"
vocode = "0.1.111a3"
google-cloud-texttospeech = "^2.14.1"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
6 changes: 0 additions & 6 deletions apps/langchain_agent/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion apps/langchain_agent/telephony_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EventsManager(events_manager.EventsManager):
def __init__(self):
super().__init__(subscriptions=[EventType.TRANSCRIPT_COMPLETE])

def handle_event(self, event: Event):
async def handle_event(self, event: Event):
if event.type == EventType.TRANSCRIPT_COMPLETE:
transcript_complete_event = typing.cast(TranscriptCompleteEvent, event)
add_transcript(
Expand Down
7 changes: 5 additions & 2 deletions apps/telephony_app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ RUN apt-get -y upgrade
RUN apt-get install -y ffmpeg

WORKDIR /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt
COPY ./pyproject.toml /code/pyproject.toml
COPY ./poetry.lock /code/poetry.lock
RUN pip install --no-cache-dir --upgrade poetry
RUN poetry config virtualenvs.create false
RUN poetry install --no-dev --no-interaction --no-ansi
COPY main.py /code/main.py
COPY speller_agent.py /code/speller_agent.py

Expand Down
2,390 changes: 2,390 additions & 0 deletions apps/telephony_app/poetry.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions apps/telephony_app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "telephony-app"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
redis = "^4.5.4"
twilio = "^8.1.0"
vonage = "^3.5.1"
pyngrok = "^6.0.0"
python-dotenv = "^1.0.0"
vocode = "0.1.111a3"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
6 changes: 0 additions & 6 deletions apps/telephony_app/requirements.txt

This file was deleted.

15 changes: 5 additions & 10 deletions docs/langchain-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ appropriate call.

1. Install [Ngrok](https://ngrok.com/)
2. Install [Redis](https://redis.com/)
3. Install [Poetry](https://python-poetry.org/)

## Run the example

Expand Down Expand Up @@ -100,7 +101,7 @@ source venv/bin/activate
2. Install requirements

```bash
pip install -r requirements.txt
poetry install
```

3. Run an instance of Redis at http://localhost:6379. With Docker, this can be done with:
Expand All @@ -125,17 +126,11 @@ With the self-hosted telephony server running:
CONTACTS = [{"name": "Kian", "phone": "+123456789"}]
```

2. Install `python-dotenv` to use the environment variables we set up earlier.

```
pip3 install python-dotenv
```

3. Run `main.py`
2. Run `main.py`

```bash
pip3 install -r requirements.txt
python3 main.py
poetry install
poetry run python main.py
```

# Code explanation
Expand Down
17 changes: 5 additions & 12 deletions docs/telephony.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ docker-compose up

Run the following steps from the `telephony_app` directory.

1. Create a Python environment (we recommend using `virtualenv` by running `python3 -m venv venv`) and install dependencies via `pip`
1. Install [Poetry](https://python-poetry.org/) and install dependencies.

```
pip install -r requirements.txt
poetry install
```

2. Run Redis with the default port of 6379.
Expand All @@ -102,7 +102,7 @@ docker run -dp 6379:6379 -it redis/redis-stack:latest
3. Run the server with `uvicorn` (should be already installed in step 1).

```
uvicorn main:app --port 3000
poetry run uvicorn main:app --port 3000
```

### Setting up an inbound number
Expand All @@ -120,18 +120,11 @@ uvicorn main:app --port 3000

Make sure the server we just set up is already running. Then, in `outbound_call.py`

1. Replace the `to_phone` with the number you want to call and the `from_phone` with the number you want to call from.
In order to make a call from the `from_phone`, you must have access to it via Twilio (either a number purchased via Twilio or verify the caller ID).
Replace the `to_phone` with the number you want to call and the `from_phone` with the number you want to call from. In order to make a call from the `from_phone`, you must have access to it via Twilio (either a number purchased via Twilio or verify the caller ID).

> Note: To ensure legal compliance with robocall regulations in California, the following code snippet from the [Vocode library](https://github.com/vocodedev/vocode-python/blob/main/vocode/streaming/telephony/conversation/outbound_call.py#L83-L96) utilizes Twilio Line Intelligence to check if calls are made to mobile phones: For Canadian phone numbers, the Twilio Lookup API may not return carrier data due to the Canadian Local Number Portability Consortium (CLNPC) requirements. More information on this issue can be found in the [Twilio Support Article](https://support.twilio.com/hc/en-us/articles/360004563433-Twilio-Lookup-API-is-Not-Returning-Carrier-Data-for-Canadian-Phone-Numbers).
2. Install `python-dotenv` to use the environment variables we set up earlier.

```
pip3 install python-dotenv
```

Run the script with `python3 outbound_call.py`.
Run the script with `poetry run python outbound_call.py`.

### Configuration

Expand Down

0 comments on commit 1e8d237

Please sign in to comment.