fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解 - 修复缺失的urllib.parse导入
This commit is contained in:
@@ -8,6 +8,7 @@ import time
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
class TingwuClient:
|
||||
def __init__(self):
|
||||
self.access_key = os.getenv("ALI_ACCESS_KEY", "")
|
||||
@@ -17,7 +18,9 @@ class TingwuClient:
|
||||
if not self.access_key or not self.secret_key:
|
||||
raise ValueError("ALI_ACCESS_KEY and ALI_SECRET_KEY required")
|
||||
|
||||
def _sign_request(self, method: str, uri: str, query: str = "", body: str = "") -> dict[str, str]:
|
||||
def _sign_request(
|
||||
self, method: str, uri: str, query: str = "", body: str = ""
|
||||
) -> dict[str, str]:
|
||||
"""阿里云签名 V3"""
|
||||
timestamp = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
@@ -39,7 +42,9 @@ class TingwuClient:
|
||||
from alibabacloud_tingwu20230930 import models as tingwu_models
|
||||
from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
||||
|
||||
config = open_api_models.Config(access_key_id=self.access_key, access_key_secret=self.secret_key)
|
||||
config = open_api_models.Config(
|
||||
access_key_id=self.access_key, access_key_secret=self.secret_key
|
||||
)
|
||||
config.endpoint = "tingwu.cn-beijing.aliyuncs.com"
|
||||
client = TingwuSDKClient(config)
|
||||
|
||||
@@ -47,7 +52,9 @@ class TingwuClient:
|
||||
type="offline",
|
||||
input=tingwu_models.Input(source="OSS", file_url=audio_url),
|
||||
parameters=tingwu_models.Parameters(
|
||||
transcription=tingwu_models.Transcription(diarization_enabled=True, sentence_max_length=20)
|
||||
transcription=tingwu_models.Transcription(
|
||||
diarization_enabled=True, sentence_max_length=20
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
@@ -65,7 +72,9 @@ class TingwuClient:
|
||||
print(f"Tingwu API error: {e}")
|
||||
return f"mock_task_{int(time.time())}"
|
||||
|
||||
def get_task_result(self, task_id: str, max_retries: int = 60, interval: int = 5) -> dict[str, Any]:
|
||||
def get_task_result(
|
||||
self, task_id: str, max_retries: int = 60, interval: int = 5
|
||||
) -> dict[str, Any]:
|
||||
"""获取任务结果"""
|
||||
try:
|
||||
# 导入移到文件顶部会导致循环导入,保持在这里
|
||||
@@ -73,7 +82,9 @@ class TingwuClient:
|
||||
from alibabacloud_tingwu20230930 import models as tingwu_models
|
||||
from alibabacloud_tingwu20230930.client import Client as TingwuSDKClient
|
||||
|
||||
config = open_api_models.Config(access_key_id=self.access_key, access_key_secret=self.secret_key)
|
||||
config = open_api_models.Config(
|
||||
access_key_id=self.access_key, access_key_secret=self.secret_key
|
||||
)
|
||||
config.endpoint = "tingwu.cn-beijing.aliyuncs.com"
|
||||
client = TingwuSDKClient(config)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user