streaming conversation takes instances not configs

This commit is contained in:
Ajay Raj 2023-03-28 12:39:49 -07:00
commit a9424ffaeb
5 changed files with 40 additions and 36 deletions

View file

@ -142,14 +142,17 @@ class ChatGPTAgent(BaseAgent):
if __name__ == "__main__":
from dotenv import load_dotenv
load_dotenv()
agent = ChatGPTAgent(
ChatGPTAgentConfig(
model_name="gpt-4",
prompt_preamble="The assistant is having a pleasant conversation about life. If the user hasn't completed their thought, the assistant responds with 'PASS'",
)
)
while True:
# response = agent.respond(input("Human: "))[0]
# print(f"AI: {response}")
for response in agent.generate_response(input("Human: ")):
print(f"AI: {response}")
response = agent.respond(input("Human: "))[0]
print(f"AI: {response}")
# for response in agent.generate_response(input("Human: ")):
# print(f"AI: {response}")

View file

@ -1,5 +1,6 @@
import asyncio
from asyncio import Future
from ctypes import Union
import queue
from typing import Callable, Awaitable, Optional, Any
import logging
@ -66,9 +67,9 @@ class StreamingConversation:
def __init__(
self,
output_device: BaseOutputDevice,
transcriber_config: TranscriberConfig,
agent_config: AgentConfig,
synthesizer_config: SynthesizerConfig,
transcriber: BaseTranscriber,
agent: BaseAgent,
synthesizer: BaseSynthesizer,
conversation_id: str = None,
per_chunk_allowance_seconds: int = PER_CHUNK_ALLOWANCE_SECONDS,
logger: Optional[logging.Logger] = None,
@ -76,11 +77,11 @@ class StreamingConversation:
self.id = conversation_id or create_conversation_id()
self.logger = logger or logging.getLogger(__name__)
self.output_device = output_device
self.transcriber = create_transcriber(transcriber_config)
self.transcriber = transcriber
self.transcriber.set_on_response(self.on_transcription_response)
self.transcriber_task = None
self.agent = create_agent(agent_config)
self.synthesizer = create_synthesizer(synthesizer_config)
self.agent = agent
self.synthesizer = synthesizer
self.synthesizer_event_loop = asyncio.new_event_loop()
self.synthesizer_thread = threading.Thread(
name="synthesizer",

View file

@ -11,22 +11,26 @@ from vocode.streaming.factory import (
create_synthesizer,
create_transcriber,
)
from vocode.streaming.models.agent import AgentConfig
from vocode.streaming.streaming_conversation import StreamingConversation
from vocode.streaming.models.telephony import CallConfig, TwilioConfig
from vocode.streaming.output_device.twilio_output_device import TwilioOutputDevice
from vocode.streaming.models.synthesizer import (
AzureSynthesizerConfig,
SynthesizerConfig,
)
from vocode.streaming.models.transcriber import (
DeepgramTranscriberConfig,
PunctuationEndpointingConfig,
TranscriberConfig,
)
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer
from vocode.streaming.synthesizer.base_synthesizer import BaseSynthesizer
from vocode.streaming.telephony.config_manager.base_config_manager import (
BaseConfigManager,
)
from vocode.streaming.telephony.constants import DEFAULT_SAMPLING_RATE
from vocode.streaming.telephony.twilio import create_twilio_client
from vocode.streaming.models.audio_encoding import AudioEncoding
from vocode.streaming.streaming_conversation import StreamingConversation
@ -43,9 +47,9 @@ class Call(StreamingConversation):
self,
base_url: str,
config_manager: BaseConfigManager,
agent_config: BaseAgent,
transcriber_config: Optional[BaseTranscriber] = None,
synthesizer_config: Optional[BaseSynthesizer] = None,
agent_config: AgentConfig,
transcriber_config: TranscriberConfig,
synthesizer_config: SynthesizerConfig,
twilio_config: Optional[TwilioConfig] = None,
twilio_sid: Optional[str] = None,
conversation_id: Optional[str] = None,
@ -61,19 +65,9 @@ class Call(StreamingConversation):
self.twilio_client = create_twilio_client(twilio_config)
super().__init__(
self.output_device,
transcriber_config
or DeepgramTranscriberConfig(
sampling_rate=8000,
audio_encoding=AudioEncoding.MULAW,
chunk_size=self.CHUNK_SIZE,
model="voicemail",
endpointing_config=PunctuationEndpointingConfig(),
),
agent_config,
synthesizer_config
or AzureSynthesizerConfig(
sampling_rate=8000, audio_encoding=AudioEncoding.MULAW
),
create_transcriber(transcriber_config),
create_agent(agent_config),
create_synthesizer(synthesizer_config),
conversation_id=conversation_id,
per_chunk_allowance_seconds=0.01,
logger=logger,