-
Notifications
You must be signed in to change notification settings - Fork 508
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull Request for Issue #461: Introducing
/apps/voice_rag/
- A Demo …
…Application for RAG in Vocode OpenSource (#464) * Add Pinecone vector database configuration * Add RAG documentation and remove vectordb documentation * ADD colab Link * working version manual_pinecone_ingestor * Revert the changes in /apps/client_backend/main.py with the aim of creating a new app in /apps/rag/ * Fix issue #463: Add Content-Type Header for Pinecone API Integration * Add environment files and Docker configuration * Rename rag to voice-rag app * revert pinecone.py Refactor code and update dependencies * Working Version * Update pinecone ingestor script * Add voice_rag application files * Update Dockerfile and README.md in voice_rag app * Fix missing newline at end of file
- Loading branch information
Showing
8 changed files
with
485 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
OPENAI_API_KEY= | ||
DEEPGRAM_API_KEY= | ||
AZURE_SPEECH_KEY= | ||
AZURE_SPEECH_REGION= | ||
|
||
PINECONE_API_KEY= | ||
PINECONE_ENVIRONMENT= | ||
PINECONE_INDEX_NAME= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Use the official micromamba image as a base | ||
FROM docker.io/mambaorg/micromamba:1.5-jammy | ||
|
||
# Create a new user '$MAMBA_USER' and set the working directory | ||
COPY --chown=$MAMBA_USER:$MAMBA_USER environment.docker.yml /tmp/environment.yml | ||
|
||
# Install the specified packages using micromamba | ||
RUN micromamba install -y -n base -f /tmp/environment.yml && \ | ||
micromamba clean --all --yes | ||
|
||
USER root | ||
WORKDIR /usr/local/src | ||
|
||
ARG VOCODE_USER=vocode | ||
ARG VOCODE_UID=8476 | ||
ARG VOCODE_GID=8476 | ||
|
||
RUN groupadd --gid $VOCODE_GID $VOCODE_USER && \ | ||
useradd --uid $VOCODE_UID --gid $VOCODE_GID --shell /bin/bash --create-home $VOCODE_USER | ||
|
||
# COPY --chown=$VOCODE_USER:$VOCODE_USER ../../../ /vocode-python | ||
# WORKDIR /usr/local/src/vocode | ||
# RUN poetry install -E all | ||
|
||
# Copy the rest of your application files into the Docker image | ||
COPY --chown=$VOCODE_USER:$VOCODE_USER . /vocode | ||
WORKDIR /vocode | ||
|
||
#USER vocode | ||
USER root | ||
|
||
ENV DOCKER_ENV="docker" | ||
|
||
# # Expose the port your FastAPI app will run on | ||
EXPOSE 19002 | ||
|
||
# Set build arguments | ||
ARG BUILD_DATE | ||
ARG VCS_REF | ||
ARG VERSION | ||
|
||
# Set labels | ||
LABEL org.label-schema.build-date=$BUILD_DATE \ | ||
org.label-schema.name="vocode" \ | ||
org.label-schema.description="Vocode Docker Image" \ | ||
org.label-schema.url="https://vocode.dev/" \ | ||
org.label-schema.vcs-url="https://github.com/vocodedev" \ | ||
org.label-schema.maintainer="[email protected]" \ | ||
org.label-schema.vcs-ref=$VCS_REF \ | ||
org.label-schema.vendor="Vocode" \ | ||
org.label-schema.version=$VERSION | ||
|
||
# Start the FastAPI app using Uvicorn | ||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "19002"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# voice_rag | ||
|
||
## Docker | ||
|
||
1. Set up the configuration for your agent in `main.py`. | ||
2. Set up an .env file using the template | ||
|
||
``` | ||
cp .env.template .env | ||
``` | ||
|
||
Fill in your API keys into .env | ||
|
||
3. Build the Docker image | ||
|
||
```bash | ||
docker build --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ | ||
--build-arg VCS_REF=$(git rev-parse --short HEAD) \ | ||
--build-arg VERSION=0.1.0 \ | ||
-t vocode/vocode-voice-rag:0.1.0 . | ||
``` | ||
|
||
4. Run the image and forward the port. | ||
|
||
```bash | ||
docker run --env-file=.env -p 3000:3000 -t vocode/vocode-voice-rag | ||
``` | ||
|
||
Now you have a client backend hosted at localhost:3000 to pass into the Vocode React SDK. You'll likely need to tunnel port 3000 to ngrok / host your server in order to use it in the React SDK. | ||
|
||
## Non-docker setup | ||
|
||
`main.py` just sets up a FastAPI server, so you can just run it with uvicorn: | ||
|
||
``` | ||
uvicorn main:app | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: vocode-rag | ||
channels: | ||
- conda-forge | ||
- pytorch | ||
dependencies: | ||
- python=3.10 | ||
- openssl=1.1.1w | ||
- portaudio | ||
- ffmpeg | ||
- git | ||
- pip | ||
- pip: | ||
# Installing vocode from the git repository | ||
- git+https://github.com/ArtisanLabs/vocode-python/@461-VectorDB-OpenSource-Documentation#egg=vocode | ||
- azure-cognitiveservices-speech==1.31.0 | ||
- python-dotenv | ||
- ipython | ||
- deepgram-sdk | ||
- uvicorn | ||
- pinecone-client | ||
- poetry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import os | ||
import logging | ||
from fastapi import FastAPI | ||
|
||
from vocode.streaming.models.agent import ChatGPTAgentConfig | ||
from vocode.streaming.models.synthesizer import AzureSynthesizerConfig | ||
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer | ||
|
||
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent | ||
from vocode.streaming.client_backend.conversation import ConversationRouter | ||
from vocode.streaming.models.message import BaseMessage | ||
from vocode.streaming.vector_db.factory import VectorDBFactory | ||
from vocode.streaming.vector_db.pinecone import PineconeConfig | ||
from vocode.streaming.transcriber.deepgram_transcriber import DeepgramTranscriber | ||
|
||
|
||
from vocode.streaming.models.transcriber import ( | ||
DeepgramTranscriberConfig, | ||
TimeEndpointingConfig | ||
) | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
app = FastAPI(docs_url=None) | ||
|
||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
vector_db_config = PineconeConfig( | ||
index=os.getenv('PINECONE_INDEX_NAME') | ||
) | ||
|
||
INITIAL_MESSAGE="Hello!" | ||
PROMPT_PREAMBLE=''' | ||
I want you to act as an IT Architect. | ||
I will provide some details about the functionality of an application or other | ||
digital product, and it will be your job to come up with ways to integrate it | ||
into the IT landscape. This could involve analyzing business requirements, | ||
performing a gap analysis, and mapping the functionality of the new system to | ||
the existing IT landscape. The next steps are to create a solution design. | ||
You are an expert in these technologies: | ||
- Langchain | ||
- Supabase | ||
- Next.js | ||
- Fastapi | ||
- Vocode. | ||
''' | ||
|
||
TIME_ENDPOINTING_CONFIG = TimeEndpointingConfig() | ||
TIME_ENDPOINTING_CONFIG.time_cutoff_seconds = 2 | ||
|
||
AZURE_SYNTHESIZER_THUNK = lambda output_audio_config: AzureSynthesizer( | ||
AzureSynthesizerConfig.from_output_audio_config(output_audio_config, ), | ||
logger=logger | ||
) | ||
|
||
DEEPGRAM_TRANSCRIBER_THUNK = lambda input_audio_config: DeepgramTranscriber( | ||
DeepgramTranscriberConfig.from_input_audio_config( | ||
input_audio_config=input_audio_config, | ||
endpointing_config=TIME_ENDPOINTING_CONFIG, | ||
min_interrupt_confidence=0.9, | ||
), | ||
logger=logger | ||
) | ||
|
||
conversation_router = ConversationRouter( | ||
agent_thunk=lambda: ChatGPTAgent( | ||
ChatGPTAgentConfig( | ||
initial_message=BaseMessage(text=INITIAL_MESSAGE), | ||
prompt_preamble=PROMPT_PREAMBLE, | ||
vector_db_config=vector_db_config, | ||
logger=logger, | ||
), | ||
logger=logger | ||
), | ||
synthesizer_thunk=AZURE_SYNTHESIZER_THUNK, | ||
transcriber_thunk=DEEPGRAM_TRANSCRIBER_THUNK, | ||
logger=logger, | ||
) | ||
|
||
app.include_router(conversation_router.get_router()) |
Oops, something went wrong.