lizhengwei

jira:NYJ-1540 desc: update api.py

... ... @@ -10,6 +10,6 @@ output_kafka:
topic: football_replay_match_resp
cache_dir: /data/cache
llm_base_url: http://prod-llm:11434
llm_model: qwen3.6:35b-a3b-q8_0
llm_base_url: http://prod-llm:11434/v1
llm_model: Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf
llm_temperature: 0.7
... ...
... ... @@ -11,8 +11,8 @@ output_kafka:
llm:
base_url: http://192.168.1.59:11434
model_name: qwen3.6:35b-a3b-q8_0
base_url: http://192.168.1.59:11434/v1
model_name: Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf
temperature: 0.7
common:
... ...
... ... @@ -44,7 +44,7 @@ def replay_match_event(data: dict) -> dict:
events : list 赛事事件片段(直播候选)
|- id : str 事件id
|- type : str 事件类型(1:进球)
|- url : str 事件片段url(m3u8)
|- url : str 完整视频url(m3u8)
|- event_utc : int 事件发生的utc时间点
响应参数:
... ... @@ -82,20 +82,23 @@ def replay_match_event(data: dict) -> dict:
raise RuntimeError(f"回看视频处理失败: {e}")
# 2. 为每个 event(直播候选)提取帧并构建 LLM content
# event 的 url 本身已是视频片段,直接处理完整片段
# event 的 url 为完整视频,通过 event_utc 向前延长10秒、向后延长5秒截取片段
live_videos = []
for event in events:
event_id = event.get("id")
event_url = event.get("url")
event_utc = event.get("event_utc")
if not event_url:
if not event_url or event_utc is None:
continue
try:
event_start = event_utc - 10
event_end = event_utc + 5
event_frames = v2f.to_frames(
url=event_url,
start_utc=0,
end_utc=999999, # 传极大值,实际以视频真实长度为准
start_utc=event_start,
end_utc=event_end,
fps=2,
)
event_contents = frames2content(event_frames)
... ...
... ... @@ -357,8 +357,8 @@ if __name__ == "__main__":
from util.football_replay_video_event_by_llm import FootballReplayVideoEvent
fbrv = FootballReplayVideoEvent(
base_url="http://192.168.1.59:11434",
model="qwen3.6:35b-a3b-q8_0",
base_url="http://192.168.1.59:11434/v1",
model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf",
temperature=0.7,
)
event_json = fbrv.video_event_for_contents(content, None)
... ...
... ... @@ -3,7 +3,7 @@ import os.path
from pathlib import Path
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_ollama import ChatOllama
from langchain_openai import ChatOpenAI
try:
from .llm_video_content import contents as video_contents
... ... @@ -79,7 +79,8 @@ class FootballReplayMatchLive:
# keep_alive=-1, reasoning=False)
# self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7,
# api_key='no_key')
self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False)
self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key,
extra_body={"chat_template_kwargs": {"enable_thinking": False}})
def _match_once(self, replay_video_contents: list, live_videos: list[dict], cache_path=None, record: list = None):
... ...
... ... @@ -3,7 +3,7 @@ import os.path
from pathlib import Path
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_ollama import ChatOllama
from langchain_openai import ChatOpenAI
try:
from .llm_video_content import contents as video_contents
... ... @@ -74,7 +74,8 @@ class FootballReplayVideoEvent:
# keep_alive=-1, reasoning=False)
# self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7,
# api_key='no_key')
self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False)
self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key,
extra_body={"chat_template_kwargs": {"enable_thinking": False}})
def video_event(self, video_path: str, asr_text: str = '无', cache_path=None):
if cache_path is not None and os.path.exists(cache_path):
... ...
... ... @@ -6,9 +6,9 @@ import json
def batch_match():
replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0")
replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf")
qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B")
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7)
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7)
videos_dir = rf"R:\wdx\202604\20260420_download_football_video\finished"
for video_name in sorted(os.listdir(videos_dir)):
... ...
... ... @@ -4,7 +4,7 @@ import os
from football_replay_video_event_by_llm import FootballReplayVideoEvent
from qwen_asr_util import QwenAsr
def batch_with_asr():
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7)
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7)
qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B",temperature=0.7,
api_key='no_key')
... ... @@ -27,7 +27,7 @@ def batch_with_asr():
print(event_json)
def batch_without_asr():
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7)
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7)
# qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B", temperature=0.7,
# api_key='no_key')
... ... @@ -51,7 +51,7 @@ def batch_without_asr():
print(event_json)
def one_video_test(video_path):
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7)
fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7)
event_json = fbrv.video_event(video_path, None)
print(event_json)
... ...
... ... @@ -3,7 +3,7 @@ import json
from pathlib import Path
from aabd.base.time_util import vms2str_auto
from langchain_ollama import ChatOllama
from langchain_openai import ChatOpenAI
class ClipByEvent:
... ... @@ -19,7 +19,7 @@ class ClipByEvent:
# keep_alive=-1, reasoning=False)
# self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7,
# api_key='no_key')
self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False)
self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key)
def get_video_match_time(self, video_path, video_time):
import cv2
... ...