Skip to content

Commit

Permalink
refactor(webui): 优化剧本生成功能
Browse files Browse the repository at this point in the history
- 调整 API 请求方式,使用 JSON 数据发送请求
- 添加请求头,指定内容类型为 application/json
-优化异常处理,捕获具体异常信息
  • Loading branch information
linyqh committed Nov 21, 2024
1 parent bfc601e commit 6fa80d1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions webui/components/script_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,19 @@ def update_progress(progress: float, message: str = ""):
raise Exception("没有有效的帧内容可以处理")

# ===================开始生成文案===================
update_progress(90, "正在生成文案...")
update_progress(80, "正在生成文案...")
# 校验配置
api_params = {
'vision_model_name': vision_model,
'vision_api_key': vision_api_key,
'vision_base_url': vision_base_url,
'text_model_name': text_model,
'text_api_key': text_api_key,
'text_base_url': text_base_url
"vision_api_key": vision_api_key,
"vision_model_name": vision_model,
"vision_base_url": vision_base_url or "",
"text_api_key": text_api_key,
"text_model_name": text_model,
"text_base_url": text_base_url or ""
}
headers = {
'accept': 'application/json',
'Content-Type': 'application/json'
}
session = requests.Session()
retry_strategy = Retry(
Expand All @@ -518,13 +522,13 @@ def update_progress(progress: float, message: str = ""):
try:
response = session.post(
f"{config.app.get('narrato_api_url')}/video/config",
params=api_params,
headers=headers,
json=api_params,
timeout=30,
verify=True # 启用证书验证
verify=True
)
except:
except Exception as e:
pass

custom_prompt = st.session_state.get('custom_prompt', '')
processor = ScriptProcessor(
model_name=text_model,
Expand All @@ -536,7 +540,7 @@ def update_progress(progress: float, message: str = ""):
# 处理帧内容生成脚本
script_result = processor.process_frames(frame_content_list)

# 将结果转换为JSON字符串
# ��结果转换为JSON字符串
script = json.dumps(script_result, ensure_ascii=False, indent=2)

except Exception as e:
Expand All @@ -561,7 +565,7 @@ def update_progress(progress: float, message: str = ""):
if not api_key:
raise ValueError("未配置 Narrato API Key,请在基础设置中配置")

# 准备API请求
# 准���API请求
headers = {
'X-API-Key': api_key,
'accept': 'application/json'
Expand Down

0 comments on commit 6fa80d1

Please sign in to comment.