forked from vocodedev/vocode-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from m5a0r7/better-interruptions
Better interruptions
- Loading branch information
Showing
24 changed files
with
416 additions
and
102 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
File renamed without changes.
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,27 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
import requests | ||
|
||
from vocode.streaming.models.transcript import Transcript | ||
from vocode.streaming.report.base_call_report import BaseCallReporter, CallReporterType, CallReporterConfig | ||
|
||
|
||
class ApiCallReporterConfig(CallReporterConfig, type=CallReporterType.API.value): | ||
url: str | ||
|
||
|
||
class ApiCallReporter(BaseCallReporter[ApiCallReporterConfig]): | ||
def __init__(self, config: ApiCallReporterConfig, logger: Optional[logging.Logger] = None): | ||
super().__init__(config, logger) | ||
|
||
def report(self, conversation_id: str, transcript: Transcript): | ||
logs = self.get_event_logs(transcript) | ||
data = { | ||
"conversation_id": conversation_id, | ||
"logs": logs, | ||
"start_time": transcript.start_time, | ||
} | ||
self.logger.debug(f"Data to call reporter: {data}") | ||
response = requests.post(self.config.url, json=data) | ||
self.logger.debug(f"Response from call reporter: {response}") |
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,44 @@ | ||
import logging | ||
from enum import Enum | ||
from typing import TypeVar, Generic, Optional | ||
|
||
from vocode.streaming.models.model import TypedModel | ||
from vocode.streaming.models.transcript import Transcript, Message | ||
|
||
|
||
class CallReporterType(str, Enum): | ||
BASE = "base_call_report" | ||
API = "api_call_report" | ||
|
||
|
||
class CallReporterConfig(TypedModel, type=CallReporterType.BASE.value): | ||
pass | ||
|
||
|
||
CallReporterConfigType = TypeVar("CallReporterConfigType", bound=CallReporterConfig) | ||
|
||
|
||
class BaseCallReporter(Generic[CallReporterConfigType]): | ||
def __init__(self, config: CallReporterConfigType, logger: Optional[logging.Logger] = None): | ||
self.logger: logging.Logger = logger or logging.getLogger(__name__) | ||
self.config = config | ||
|
||
def get_config(self) -> CallReporterConfig: | ||
return self.config | ||
|
||
def report(self, conversation_id: str, transcript: Transcript): | ||
raise NotImplementedError | ||
|
||
@staticmethod | ||
def get_event_logs(transcript): | ||
logs = [] | ||
for event_log in transcript.event_logs: | ||
if isinstance(event_log, Message): | ||
log = { | ||
'text': event_log.text, | ||
'sender': event_log.sender.value, | ||
'timestamp': event_log.timestamp, | ||
'confidence': event_log.confidence, | ||
} | ||
logs.append(log) | ||
return logs |
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,12 @@ | ||
import logging | ||
from typing import Optional | ||
|
||
from vocode.streaming.report.api_call_reporter import ApiCallReporterConfig, ApiCallReporter | ||
from vocode.streaming.report.base_call_report import CallReporterConfig | ||
|
||
|
||
class CallReporterFactory: | ||
@staticmethod | ||
def create_call_reporter(config: CallReporterConfig, logger: Optional[logging.Logger] = None): | ||
if isinstance(config, ApiCallReporterConfig): | ||
return ApiCallReporter(config, logger) |
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
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
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
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
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
Oops, something went wrong.