streaming conversation takes instances not configs
This commit is contained in:
parent
609de1f4a4
commit
a9424ffaeb
5 changed files with 40 additions and 36 deletions
|
|
@ -46,17 +46,23 @@ async def main():
|
||||||
|
|
||||||
conversation = StreamingConversation(
|
conversation = StreamingConversation(
|
||||||
output_device=speaker_output,
|
output_device=speaker_output,
|
||||||
transcriber_config=DeepgramTranscriberConfig.from_input_device(
|
transcriber=DeepgramTranscriber(
|
||||||
microphone_input, endpointing_config=PunctuationEndpointingConfig()
|
DeepgramTranscriberConfig.from_input_device(
|
||||||
|
microphone_input, endpointing_config=PunctuationEndpointingConfig()
|
||||||
|
)
|
||||||
),
|
),
|
||||||
agent_config=ChatGPTAgentConfig(
|
agent=ChatGPTAgent(
|
||||||
initial_message=BaseMessage(text="What up"),
|
ChatGPTAgentConfig(
|
||||||
prompt_preamble="""You are a helpful gen Z AI assistant. You use slang like um, but, and like a LOT. All of your responses are 10 words or less. Be super chill, use slang like
|
initial_message=BaseMessage(text="What up"),
|
||||||
|
prompt_preamble="""You are a helpful gen Z AI assistant. You use slang like um, but, and like a LOT. All of your responses are 10 words or less. Be super chill, use slang like
|
||||||
hella, down, fire, totally, but like, slay, vibing, queen, go off, bet, sus, simp, cap, big yikes, main character, dank""",
|
hella, down, fire, totally, but like, slay, vibing, queen, go off, bet, sus, simp, cap, big yikes, main character, dank""",
|
||||||
generate_responses=True,
|
generate_responses=True,
|
||||||
cut_off_response=CutOffResponse(),
|
cut_off_response=CutOffResponse(),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
synthesizer=AzureSynthesizer(
|
||||||
|
AzureSynthesizerConfig.from_output_device(speaker_output)
|
||||||
),
|
),
|
||||||
synthesizer_config=AzureSynthesizerConfig.from_output_device(speaker_output),
|
|
||||||
logger=logger,
|
logger=logger,
|
||||||
)
|
)
|
||||||
await conversation.start()
|
await conversation.start()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from vocode import getenv
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
|
from vocode.streaming.agent.chat_gpt_agent import ChatGPTAgent
|
||||||
from vocode.streaming.models.agent import ChatGPTAgentConfig
|
from vocode.streaming.models.agent import ChatGPTAgentConfig, EchoAgentConfig
|
||||||
from vocode.streaming.models.message import BaseMessage
|
from vocode.streaming.models.message import BaseMessage
|
||||||
from vocode.streaming.models.telephony import TwilioConfig
|
from vocode.streaming.models.telephony import TwilioConfig
|
||||||
from vocode.streaming.telephony.config_manager.redis_config_manager import (
|
from vocode.streaming.telephony.config_manager.redis_config_manager import (
|
||||||
|
|
|
||||||
|
|
@ -142,14 +142,17 @@ class ChatGPTAgent(BaseAgent):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
agent = ChatGPTAgent(
|
agent = ChatGPTAgent(
|
||||||
ChatGPTAgentConfig(
|
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'",
|
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:
|
while True:
|
||||||
# response = agent.respond(input("Human: "))[0]
|
response = agent.respond(input("Human: "))[0]
|
||||||
# print(f"AI: {response}")
|
print(f"AI: {response}")
|
||||||
for response in agent.generate_response(input("Human: ")):
|
# for response in agent.generate_response(input("Human: ")):
|
||||||
print(f"AI: {response}")
|
# print(f"AI: {response}")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from asyncio import Future
|
from asyncio import Future
|
||||||
|
from ctypes import Union
|
||||||
import queue
|
import queue
|
||||||
from typing import Callable, Awaitable, Optional, Any
|
from typing import Callable, Awaitable, Optional, Any
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -66,9 +67,9 @@ class StreamingConversation:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
output_device: BaseOutputDevice,
|
output_device: BaseOutputDevice,
|
||||||
transcriber_config: TranscriberConfig,
|
transcriber: BaseTranscriber,
|
||||||
agent_config: AgentConfig,
|
agent: BaseAgent,
|
||||||
synthesizer_config: SynthesizerConfig,
|
synthesizer: BaseSynthesizer,
|
||||||
conversation_id: str = None,
|
conversation_id: str = None,
|
||||||
per_chunk_allowance_seconds: int = PER_CHUNK_ALLOWANCE_SECONDS,
|
per_chunk_allowance_seconds: int = PER_CHUNK_ALLOWANCE_SECONDS,
|
||||||
logger: Optional[logging.Logger] = None,
|
logger: Optional[logging.Logger] = None,
|
||||||
|
|
@ -76,11 +77,11 @@ class StreamingConversation:
|
||||||
self.id = conversation_id or create_conversation_id()
|
self.id = conversation_id or create_conversation_id()
|
||||||
self.logger = logger or logging.getLogger(__name__)
|
self.logger = logger or logging.getLogger(__name__)
|
||||||
self.output_device = output_device
|
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.set_on_response(self.on_transcription_response)
|
||||||
self.transcriber_task = None
|
self.transcriber_task = None
|
||||||
self.agent = create_agent(agent_config)
|
self.agent = agent
|
||||||
self.synthesizer = create_synthesizer(synthesizer_config)
|
self.synthesizer = synthesizer
|
||||||
self.synthesizer_event_loop = asyncio.new_event_loop()
|
self.synthesizer_event_loop = asyncio.new_event_loop()
|
||||||
self.synthesizer_thread = threading.Thread(
|
self.synthesizer_thread = threading.Thread(
|
||||||
name="synthesizer",
|
name="synthesizer",
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,26 @@ from vocode.streaming.factory import (
|
||||||
create_synthesizer,
|
create_synthesizer,
|
||||||
create_transcriber,
|
create_transcriber,
|
||||||
)
|
)
|
||||||
|
from vocode.streaming.models.agent import AgentConfig
|
||||||
|
|
||||||
from vocode.streaming.streaming_conversation import StreamingConversation
|
from vocode.streaming.streaming_conversation import StreamingConversation
|
||||||
from vocode.streaming.models.telephony import CallConfig, TwilioConfig
|
from vocode.streaming.models.telephony import CallConfig, TwilioConfig
|
||||||
from vocode.streaming.output_device.twilio_output_device import TwilioOutputDevice
|
from vocode.streaming.output_device.twilio_output_device import TwilioOutputDevice
|
||||||
from vocode.streaming.models.synthesizer import (
|
from vocode.streaming.models.synthesizer import (
|
||||||
AzureSynthesizerConfig,
|
AzureSynthesizerConfig,
|
||||||
|
SynthesizerConfig,
|
||||||
)
|
)
|
||||||
from vocode.streaming.models.transcriber import (
|
from vocode.streaming.models.transcriber import (
|
||||||
DeepgramTranscriberConfig,
|
DeepgramTranscriberConfig,
|
||||||
PunctuationEndpointingConfig,
|
PunctuationEndpointingConfig,
|
||||||
|
TranscriberConfig,
|
||||||
)
|
)
|
||||||
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer
|
from vocode.streaming.synthesizer.azure_synthesizer import AzureSynthesizer
|
||||||
from vocode.streaming.synthesizer.base_synthesizer import BaseSynthesizer
|
from vocode.streaming.synthesizer.base_synthesizer import BaseSynthesizer
|
||||||
from vocode.streaming.telephony.config_manager.base_config_manager import (
|
from vocode.streaming.telephony.config_manager.base_config_manager import (
|
||||||
BaseConfigManager,
|
BaseConfigManager,
|
||||||
)
|
)
|
||||||
|
from vocode.streaming.telephony.constants import DEFAULT_SAMPLING_RATE
|
||||||
from vocode.streaming.telephony.twilio import create_twilio_client
|
from vocode.streaming.telephony.twilio import create_twilio_client
|
||||||
from vocode.streaming.models.audio_encoding import AudioEncoding
|
from vocode.streaming.models.audio_encoding import AudioEncoding
|
||||||
from vocode.streaming.streaming_conversation import StreamingConversation
|
from vocode.streaming.streaming_conversation import StreamingConversation
|
||||||
|
|
@ -43,9 +47,9 @@ class Call(StreamingConversation):
|
||||||
self,
|
self,
|
||||||
base_url: str,
|
base_url: str,
|
||||||
config_manager: BaseConfigManager,
|
config_manager: BaseConfigManager,
|
||||||
agent_config: BaseAgent,
|
agent_config: AgentConfig,
|
||||||
transcriber_config: Optional[BaseTranscriber] = None,
|
transcriber_config: TranscriberConfig,
|
||||||
synthesizer_config: Optional[BaseSynthesizer] = None,
|
synthesizer_config: SynthesizerConfig,
|
||||||
twilio_config: Optional[TwilioConfig] = None,
|
twilio_config: Optional[TwilioConfig] = None,
|
||||||
twilio_sid: Optional[str] = None,
|
twilio_sid: Optional[str] = None,
|
||||||
conversation_id: Optional[str] = None,
|
conversation_id: Optional[str] = None,
|
||||||
|
|
@ -61,19 +65,9 @@ class Call(StreamingConversation):
|
||||||
self.twilio_client = create_twilio_client(twilio_config)
|
self.twilio_client = create_twilio_client(twilio_config)
|
||||||
super().__init__(
|
super().__init__(
|
||||||
self.output_device,
|
self.output_device,
|
||||||
transcriber_config
|
create_transcriber(transcriber_config),
|
||||||
or DeepgramTranscriberConfig(
|
create_agent(agent_config),
|
||||||
sampling_rate=8000,
|
create_synthesizer(synthesizer_config),
|
||||||
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
|
|
||||||
),
|
|
||||||
conversation_id=conversation_id,
|
conversation_id=conversation_id,
|
||||||
per_chunk_allowance_seconds=0.01,
|
per_chunk_allowance_seconds=0.01,
|
||||||
logger=logger,
|
logger=logger,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue