Modernize Python typing across the codebase
Automated via ruff UP006, UP007, UP035, UP045 rules (target: py311): - Replace `typing.List`, `Dict`, `Tuple`, `Set`, `FrozenSet`, `Type` with their built-in equivalents (`list`, `dict`, `tuple`, etc.) - Replace `typing.Optional[X]` with `X | None` - Replace `typing.Union[X, Y]` with `X | Y` - Move `Mapping`, `Sequence`, `Callable`, `Awaitable`, `MutableMapping`, `MutableSequence`, `Iterator`, `AsyncIterator`, `AsyncGenerator` imports from `typing` to `collections.abc` - Remove now-unused `typing` imports - Add `from __future__ import annotations` to 5 files that use forward-reference strings in `X | "Y"` annotations
This commit is contained in:
@@ -84,7 +84,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
logger.debug(
|
||||
f"loaded conversation from {filename}\n{json.dumps(params.context.get_messages(), indent=4)}"
|
||||
|
||||
@@ -105,7 +105,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
messages = json.load(file)
|
||||
# HACK: if using the older Nova Sonic (pre-2) model, you need a special way of
|
||||
# triggering the first assistant response. The call to trigger_assistant_response(),
|
||||
|
||||
@@ -110,7 +110,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
await params.result_callback(
|
||||
{
|
||||
|
||||
@@ -94,7 +94,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
await params.llm.reset_conversation()
|
||||
# Manually create a response since we've reset the conversation
|
||||
|
||||
@@ -91,7 +91,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
await params.llm.reset_conversation()
|
||||
# NOTE: we manually create a response here rather than relying
|
||||
|
||||
@@ -85,7 +85,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
logger.debug(
|
||||
f"loaded conversation from {filename}\n{json.dumps(params.context.get_messages(), indent=4)}"
|
||||
|
||||
@@ -85,7 +85,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
logger.debug(
|
||||
f"loaded conversation from {filename}\n{json.dumps(params.context.get_messages(), indent=4)}"
|
||||
|
||||
@@ -85,7 +85,7 @@ async def load_conversation(params: FunctionCallParams):
|
||||
filename = params.arguments["filename"]
|
||||
logger.debug(f"loading conversation from {filename}")
|
||||
try:
|
||||
with open(filename, "r") as file:
|
||||
with open(filename) as file:
|
||||
params.context.set_messages(json.load(file))
|
||||
logger.debug(
|
||||
f"loaded conversation from {filename}\n{json.dumps(params.context.get_messages(), indent=4)}"
|
||||
|
||||
@@ -87,7 +87,7 @@ def get_rag_content():
|
||||
"""Get the RAG content from the file."""
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
rag_content_path = os.path.join(script_dir, "assets", "rag-content.txt")
|
||||
with open(rag_content_path, "r") as f:
|
||||
with open(rag_content_path) as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import argparse
|
||||
import asyncio
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Dict
|
||||
|
||||
import uvicorn
|
||||
from dotenv import load_dotenv
|
||||
@@ -39,7 +38,7 @@ load_dotenv(override=True)
|
||||
app = FastAPI()
|
||||
|
||||
# Store connections by pc_id
|
||||
pcs_map: Dict[str, SmallWebRTCConnection] = {}
|
||||
pcs_map: dict[str, SmallWebRTCConnection] = {}
|
||||
|
||||
ice_servers = [
|
||||
IceServer(
|
||||
|
||||
@@ -45,13 +45,13 @@ class TranscriptHandler:
|
||||
output_file: Optional path to file where transcript is saved. If None, outputs to log only.
|
||||
"""
|
||||
|
||||
def __init__(self, output_file: Optional[str] = None):
|
||||
def __init__(self, output_file: str | None = None):
|
||||
"""Initialize handler with optional file output.
|
||||
|
||||
Args:
|
||||
output_file: Path to output file. If None, outputs to log only.
|
||||
"""
|
||||
self.output_file: Optional[str] = output_file
|
||||
self.output_file: str | None = output_file
|
||||
logger.debug(
|
||||
f"TranscriptHandler initialized {'with output_file=' + output_file if output_file else 'with log output only'}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user