Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

486 support for pydantic v2 v1 compatible #490

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- "3.10"
- "3.11"
poetry-version:
- "1.4.2"
- "1.7.1"

runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.8.0
hooks:
- id: mypy
args: [--ignore-missing-imports, ./]
Expand Down
31 changes: 19 additions & 12 deletions apps/telegram_bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import inspect
from collections import defaultdict
from pydantic import BaseModel
from pydantic.v1 import BaseModel
from typing import Tuple, Union, Optional, Dict, Type, List
from pydub import AudioSegment
from telegram import Update
Expand Down Expand Up @@ -76,33 +76,36 @@

# Define a Voice model with id, name and description fields
class Voice(BaseModel):
id: Optional[str] = None # Optional id for the voice
name: Optional[str] = None # Optional name for the voice
description: Optional[str] = None # Optional description for the voice
id: Optional[str] = None # Optional id for the voice
name: Optional[str] = None # Optional name for the voice
description: Optional[str] = None # Optional description for the voice


# Array of tuples (synthesizer's voice id, nickname, description if text to voice)
DEFAULT_VOICES: List[Voice] = [Voice(id=None, name="Coqui Default", description=None)]


# Define a Chat model with voices, current_voice and current_conversation fields
class Chat(BaseModel):
voices: List[Voice] = DEFAULT_VOICES # List of available voices for the chat
current_voice: Voice = DEFAULT_VOICES[0] # Current voice for the chat
current_conversation: Optional[bytes] = None # Current conversation as a pickled object
voices: List[Voice] = DEFAULT_VOICES # List of available voices for the chat
current_voice: Voice = DEFAULT_VOICES[0] # Current voice for the chat
current_conversation: Optional[
bytes
] = None # Current conversation as a pickled object


class VocodeBotResponder:
def __init__(
self,
transcriber: BaseTranscriber,
system_prompt: str,
synthesizer: BaseSynthesizer
synthesizer: BaseSynthesizer,
) -> None:
self.transcriber = transcriber
self.system_prompt = system_prompt
self.synthesizer = synthesizer
self.db: Dict[int, Chat] = defaultdict(Chat)


def get_agent(self, chat_id: int) -> ChatGPTAgent:
# Get current voice name and description from DB
user = self.db[chat_id]
Expand Down Expand Up @@ -142,7 +145,9 @@ async def get_response(
voice_description = user.current_voice.description

# If we have a Coqui voice prompt, use that. Otherwise, set ID as synthesizer expects.
if voice_description is not None and isinstance(self.synthesizer, CoquiSynthesizer):
if voice_description is not None and isinstance(
self.synthesizer, CoquiSynthesizer
):
self.synthesizer.voice_prompt = voice_description
elif voice_id is not None:
setattr(self.synthesizer, voice_attr_of[type(self.synthesizer)], voice_id)
Expand All @@ -162,7 +167,9 @@ async def handle_telegram_start(
start_text = """
I'm a voice chatbot, send a voice message to me and I'll send one back!" Use /help to see available commands.
"""
await context.bot.send_message(chat_id=update.effective_chat.id, text=start_text)
await context.bot.send_message(
chat_id=update.effective_chat.id, text=start_text
)

async def handle_telegram_message(
self, update: Update, context: ContextTypes.DEFAULT_TYPE
Expand Down Expand Up @@ -302,7 +309,7 @@ async def handle_telegram_help(
- Use /help to see this help message again.
"""
assert update.effective_chat, "Chat must be defined!"
if isinstance(self.synthesizer, CoquiSynthesizer):
if isinstance(self.synthesizer, CoquiSynthesizer):
help_text += "\n- Use /create <voice_description> to create a new Coqui voice from a text prompt and switch to it."
await context.bot.send_message(chat_id=update.effective_chat.id, text=help_text)

Expand Down
28 changes: 16 additions & 12 deletions apps/voice_rag/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from vocode.streaming.models.transcriber import (
DeepgramTranscriberConfig,
TimeEndpointingConfig
TimeEndpointingConfig,
)

from dotenv import load_dotenv
Expand All @@ -29,12 +29,15 @@
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

vector_db_config = PineconeConfig(
index=os.getenv('PINECONE_INDEX_NAME')
)
# Ensure that the environment variable 'PINECONE_INDEX_NAME' is not None
pinecone_index_name = os.getenv("PINECONE_INDEX_NAME")
if pinecone_index_name is None:
raise ValueError("Environment variable 'PINECONE_INDEX_NAME' is not set.")

vector_db_config = PineconeConfig(index=pinecone_index_name)

INITIAL_MESSAGE="Hello!"
PROMPT_PREAMBLE='''
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
Expand All @@ -48,14 +51,16 @@
- 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
AzureSynthesizerConfig.from_output_audio_config(
output_audio_config,
),
logger=logger,
)

DEEPGRAM_TRANSCRIBER_THUNK = lambda input_audio_config: DeepgramTranscriber(
Expand All @@ -64,7 +69,7 @@
endpointing_config=TIME_ENDPOINTING_CONFIG,
min_interrupt_confidence=0.9,
),
logger=logger
logger=logger,
)

conversation_router = ConversationRouter(
Expand All @@ -73,9 +78,8 @@
initial_message=BaseMessage(text=INITIAL_MESSAGE),
prompt_preamble=PROMPT_PREAMBLE,
vector_db_config=vector_db_config,
logger=logger,
),
logger=logger
logger=logger,
),
synthesizer_thunk=AZURE_SYNTHESIZER_THUNK,
transcriber_thunk=DEEPGRAM_TRANSCRIBER_THUNK,
Expand Down
2 changes: 1 addition & 1 deletion playground/streaming/agent/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing
from dotenv import load_dotenv
from playground.streaming.tracing_utils import make_parser_and_maybe_trace
from pydantic import BaseModel
from pydantic.v1 import BaseModel
from vocode.streaming.action.base_action import BaseAction
from vocode.streaming.action.factory import ActionFactory
from vocode.streaming.action.worker import ActionsWorker
Expand Down
Loading
Loading