Skip to content

Commit cfd2eb4

Browse files
authored
Update Black and lint the codebase to improve code quality and consis… (vocodedev#541)
* Update Black and lint the codebase to improve code quality and consistency, closes vocodedev#450 * Remove logger from telephony_server initialization
1 parent 3f97e39 commit cfd2eb4

25 files changed

+151
-117
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 23.1.0
4-
hooks:
5-
- id: black
6-
- repo: https://github.com/pre-commit/mirrors-mypy
7-
rev: v1.8.0
8-
hooks:
9-
- id: mypy
10-
args: [--ignore-missing-imports, ./]
11-
language: system
12-
pass_filenames: false
13-
stages: [pre-push]
2+
- repo: https://github.com/psf/black
3+
rev: 24.4.2
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/pre-commit/mirrors-mypy
7+
rev: v1.8.0
8+
hooks:
9+
- id: mypy
10+
args: [--ignore-missing-imports, ./]
11+
language: system
12+
pass_filenames: false
13+
stages: [pre-push]

apps/telephony_app/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
account_sid=os.environ["TWILIO_ACCOUNT_SID"],
7474
auth_token=os.environ["TWILIO_AUTH_TOKEN"],
7575
),
76-
logger=logger,
7776
)
7877
],
7978
agent_factory=SpellerAgentFactory(),

contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ If you submit a PR, we'd love to feature your contribution on Twitter so please
4040

4141
## Linting and Typechecking
4242

43-
We use [`black`](https://black.readthedocs.io/en/stable/) for linting. If you're using VSCode, code should auto-format automatically. Otherwise, run the following script before pushing:
43+
We use [`black`](https://black.readthedocs.io/en/stable/) for linting. If you're using [VSCode](https://code.visualstudio.com/docs/editor/codebasics#_formatting), code should auto-format automatically. Otherwise, run the following script before pushing:
4444

4545
```
4646
make lint_diff

playground/streaming/tracing_utils.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ def get_final_metrics(scope_metrics, final_spans=None):
5151
agent_str = metric_name.split(".", 1)[1].rsplit(".", 1)[0]
5252
generate_total_key = f"agent.{agent_str}.generate_total"
5353
respond_total_key = f"agent.{agent_str}.respond_total"
54-
final_metrics[
55-
f"agent.{agent_str}.characters_per_second"
56-
] = raw_metric.value / (
57-
sum(final_spans[generate_total_key])
58-
if generate_total_key in final_spans
59-
else sum(final_spans[respond_total_key])
54+
final_metrics[f"agent.{agent_str}.characters_per_second"] = (
55+
raw_metric.value
56+
/ (
57+
sum(final_spans[generate_total_key])
58+
if generate_total_key in final_spans
59+
else sum(final_spans[respond_total_key])
60+
)
6061
)
6162
else:
6263
try:

poetry.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ langchain-community = "^0.0.16"
4848

4949

5050
[tool.poetry.group.lint.dependencies]
51-
black = "^23.1.0"
51+
black = "^24.4.2"
5252

5353

5454
[tool.poetry.group.dev.dependencies]

vocode/helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ def create_streaming_microphone_input_and_speaker_output(
4040
):
4141
return _create_microphone_input_and_speaker_output(
4242
microphone_class=StreamingMicrophoneInput,
43-
speaker_class=BlockingStreamingSpeakerOutput
44-
if use_blocking_speaker_output
45-
else StreamingSpeakerOutput,
43+
speaker_class=(
44+
BlockingStreamingSpeakerOutput
45+
if use_blocking_speaker_output
46+
else StreamingSpeakerOutput
47+
),
4648
use_default_devices=use_default_devices,
4749
input_device_name=input_device_name,
4850
output_device_name=output_device_name,

vocode/streaming/action/transfer_call.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class TransferCall(
3131
TransferCallActionConfig, TransferCallParameters, TransferCallResponse
3232
]
3333
):
34-
description: str = "transfers the call. use when you need to connect the active call to another phone line."
34+
description: str = (
35+
"transfers the call. use when you need to connect the active call to another phone line."
36+
)
3537
parameters_type: Type[TransferCallParameters] = TransferCallParameters
3638
response_type: Type[TransferCallResponse] = TransferCallResponse
3739

vocode/streaming/action/worker.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ async def process(self, item: InterruptibleEvent[ActionInput]):
4646
conversation_id=action_input.conversation_id,
4747
action_input=action_input,
4848
action_output=action_output,
49-
vonage_uuid=action_input.vonage_uuid
50-
if isinstance(action_input, VonagePhoneCallActionInput)
51-
else None,
52-
twilio_sid=action_input.twilio_sid
53-
if isinstance(action_input, TwilioPhoneCallActionInput)
54-
else None,
49+
vonage_uuid=(
50+
action_input.vonage_uuid
51+
if isinstance(action_input, VonagePhoneCallActionInput)
52+
else None
53+
),
54+
twilio_sid=(
55+
action_input.twilio_sid
56+
if isinstance(action_input, TwilioPhoneCallActionInput)
57+
else None
58+
),
5559
is_quiet=action.quiet,
5660
)
5761
)

vocode/streaming/agent/base_agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def __init__(
140140
interruptible_event_factory: InterruptibleEventFactory = InterruptibleEventFactory(),
141141
logger: Optional[logging.Logger] = None,
142142
):
143-
self.input_queue: asyncio.Queue[
144-
InterruptibleEvent[AgentInput]
145-
] = asyncio.Queue()
143+
self.input_queue: asyncio.Queue[InterruptibleEvent[AgentInput]] = (
144+
asyncio.Queue()
145+
)
146146
self.output_queue: asyncio.Queue[
147147
InterruptibleAgentResponseEvent[AgentResponse]
148148
] = asyncio.Queue()
@@ -154,9 +154,9 @@ def __init__(
154154
interruptible_event_factory=interruptible_event_factory,
155155
)
156156
self.action_factory = action_factory
157-
self.actions_queue: asyncio.Queue[
158-
InterruptibleEvent[ActionInput]
159-
] = asyncio.Queue()
157+
self.actions_queue: asyncio.Queue[InterruptibleEvent[ActionInput]] = (
158+
asyncio.Queue()
159+
)
160160
self.logger = logger or logging.getLogger(__name__)
161161
self.goodbye_model = None
162162
if self.agent_config.end_conversation_on_goodbye:

0 commit comments

Comments
 (0)