Showing
9 changed files
with
27 additions
and
22 deletions
| @@ -10,6 +10,6 @@ output_kafka: | @@ -10,6 +10,6 @@ output_kafka: | ||
| 10 | topic: football_replay_match_resp | 10 | topic: football_replay_match_resp |
| 11 | 11 | ||
| 12 | cache_dir: /data/cache | 12 | cache_dir: /data/cache |
| 13 | -llm_base_url: http://prod-llm:11434 | ||
| 14 | -llm_model: qwen3.6:35b-a3b-q8_0 | 13 | +llm_base_url: http://prod-llm:11434/v1 |
| 14 | +llm_model: Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf | ||
| 15 | llm_temperature: 0.7 | 15 | llm_temperature: 0.7 |
| @@ -11,8 +11,8 @@ output_kafka: | @@ -11,8 +11,8 @@ output_kafka: | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | llm: | 13 | llm: |
| 14 | - base_url: http://192.168.1.59:11434 | ||
| 15 | - model_name: qwen3.6:35b-a3b-q8_0 | 14 | + base_url: http://192.168.1.59:11434/v1 |
| 15 | + model_name: Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf | ||
| 16 | temperature: 0.7 | 16 | temperature: 0.7 |
| 17 | 17 | ||
| 18 | common: | 18 | common: |
| @@ -44,7 +44,7 @@ def replay_match_event(data: dict) -> dict: | @@ -44,7 +44,7 @@ def replay_match_event(data: dict) -> dict: | ||
| 44 | events : list 赛事事件片段(直播候选) | 44 | events : list 赛事事件片段(直播候选) |
| 45 | |- id : str 事件id | 45 | |- id : str 事件id |
| 46 | |- type : str 事件类型(1:进球) | 46 | |- type : str 事件类型(1:进球) |
| 47 | - |- url : str 事件片段url(m3u8) | 47 | + |- url : str 完整视频url(m3u8) |
| 48 | |- event_utc : int 事件发生的utc时间点 | 48 | |- event_utc : int 事件发生的utc时间点 |
| 49 | 49 | ||
| 50 | 响应参数: | 50 | 响应参数: |
| @@ -82,20 +82,23 @@ def replay_match_event(data: dict) -> dict: | @@ -82,20 +82,23 @@ def replay_match_event(data: dict) -> dict: | ||
| 82 | raise RuntimeError(f"回看视频处理失败: {e}") | 82 | raise RuntimeError(f"回看视频处理失败: {e}") |
| 83 | 83 | ||
| 84 | # 2. 为每个 event(直播候选)提取帧并构建 LLM content | 84 | # 2. 为每个 event(直播候选)提取帧并构建 LLM content |
| 85 | - # event 的 url 本身已是视频片段,直接处理完整片段 | 85 | + # event 的 url 为完整视频,通过 event_utc 向前延长10秒、向后延长5秒截取片段 |
| 86 | live_videos = [] | 86 | live_videos = [] |
| 87 | for event in events: | 87 | for event in events: |
| 88 | event_id = event.get("id") | 88 | event_id = event.get("id") |
| 89 | event_url = event.get("url") | 89 | event_url = event.get("url") |
| 90 | + event_utc = event.get("event_utc") | ||
| 90 | 91 | ||
| 91 | - if not event_url: | 92 | + if not event_url or event_utc is None: |
| 92 | continue | 93 | continue |
| 93 | 94 | ||
| 94 | try: | 95 | try: |
| 96 | + event_start = event_utc - 10 | ||
| 97 | + event_end = event_utc + 5 | ||
| 95 | event_frames = v2f.to_frames( | 98 | event_frames = v2f.to_frames( |
| 96 | url=event_url, | 99 | url=event_url, |
| 97 | - start_utc=0, | ||
| 98 | - end_utc=999999, # 传极大值,实际以视频真实长度为准 | 100 | + start_utc=event_start, |
| 101 | + end_utc=event_end, | ||
| 99 | fps=2, | 102 | fps=2, |
| 100 | ) | 103 | ) |
| 101 | event_contents = frames2content(event_frames) | 104 | event_contents = frames2content(event_frames) |
| @@ -357,8 +357,8 @@ if __name__ == "__main__": | @@ -357,8 +357,8 @@ if __name__ == "__main__": | ||
| 357 | from util.football_replay_video_event_by_llm import FootballReplayVideoEvent | 357 | from util.football_replay_video_event_by_llm import FootballReplayVideoEvent |
| 358 | 358 | ||
| 359 | fbrv = FootballReplayVideoEvent( | 359 | fbrv = FootballReplayVideoEvent( |
| 360 | - base_url="http://192.168.1.59:11434", | ||
| 361 | - model="qwen3.6:35b-a3b-q8_0", | 360 | + base_url="http://192.168.1.59:11434/v1", |
| 361 | + model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", | ||
| 362 | temperature=0.7, | 362 | temperature=0.7, |
| 363 | ) | 363 | ) |
| 364 | event_json = fbrv.video_event_for_contents(content, None) | 364 | event_json = fbrv.video_event_for_contents(content, None) |
| @@ -3,7 +3,7 @@ import os.path | @@ -3,7 +3,7 @@ import os.path | ||
| 3 | from pathlib import Path | 3 | from pathlib import Path |
| 4 | 4 | ||
| 5 | from langchain_core.messages import SystemMessage, HumanMessage | 5 | from langchain_core.messages import SystemMessage, HumanMessage |
| 6 | -from langchain_ollama import ChatOllama | 6 | +from langchain_openai import ChatOpenAI |
| 7 | 7 | ||
| 8 | try: | 8 | try: |
| 9 | from .llm_video_content import contents as video_contents | 9 | from .llm_video_content import contents as video_contents |
| @@ -79,7 +79,8 @@ class FootballReplayMatchLive: | @@ -79,7 +79,8 @@ class FootballReplayMatchLive: | ||
| 79 | # keep_alive=-1, reasoning=False) | 79 | # keep_alive=-1, reasoning=False) |
| 80 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, | 80 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, |
| 81 | # api_key='no_key') | 81 | # api_key='no_key') |
| 82 | - self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False) | 82 | + self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key, |
| 83 | + extra_body={"chat_template_kwargs": {"enable_thinking": False}}) | ||
| 83 | 84 | ||
| 84 | def _match_once(self, replay_video_contents: list, live_videos: list[dict], cache_path=None, record: list = None): | 85 | def _match_once(self, replay_video_contents: list, live_videos: list[dict], cache_path=None, record: list = None): |
| 85 | 86 |
| @@ -3,7 +3,7 @@ import os.path | @@ -3,7 +3,7 @@ import os.path | ||
| 3 | from pathlib import Path | 3 | from pathlib import Path |
| 4 | 4 | ||
| 5 | from langchain_core.messages import SystemMessage, HumanMessage | 5 | from langchain_core.messages import SystemMessage, HumanMessage |
| 6 | -from langchain_ollama import ChatOllama | 6 | +from langchain_openai import ChatOpenAI |
| 7 | 7 | ||
| 8 | try: | 8 | try: |
| 9 | from .llm_video_content import contents as video_contents | 9 | from .llm_video_content import contents as video_contents |
| @@ -74,7 +74,8 @@ class FootballReplayVideoEvent: | @@ -74,7 +74,8 @@ class FootballReplayVideoEvent: | ||
| 74 | # keep_alive=-1, reasoning=False) | 74 | # keep_alive=-1, reasoning=False) |
| 75 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, | 75 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, |
| 76 | # api_key='no_key') | 76 | # api_key='no_key') |
| 77 | - self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False) | 77 | + self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key, |
| 78 | + extra_body={"chat_template_kwargs": {"enable_thinking": False}}) | ||
| 78 | 79 | ||
| 79 | def video_event(self, video_path: str, asr_text: str = '无', cache_path=None): | 80 | def video_event(self, video_path: str, asr_text: str = '无', cache_path=None): |
| 80 | if cache_path is not None and os.path.exists(cache_path): | 81 | if cache_path is not None and os.path.exists(cache_path): |
| @@ -6,9 +6,9 @@ import json | @@ -6,9 +6,9 @@ import json | ||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | def batch_match(): | 8 | def batch_match(): |
| 9 | - replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0") | 9 | + replay_match_live = FootballReplayMatchLive(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf") |
| 10 | qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B") | 10 | qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B") |
| 11 | - fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7) | 11 | + fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7) |
| 12 | 12 | ||
| 13 | videos_dir = rf"R:\wdx\202604\20260420_download_football_video\finished" | 13 | videos_dir = rf"R:\wdx\202604\20260420_download_football_video\finished" |
| 14 | for video_name in sorted(os.listdir(videos_dir)): | 14 | for video_name in sorted(os.listdir(videos_dir)): |
| @@ -4,7 +4,7 @@ import os | @@ -4,7 +4,7 @@ import os | ||
| 4 | from football_replay_video_event_by_llm import FootballReplayVideoEvent | 4 | from football_replay_video_event_by_llm import FootballReplayVideoEvent |
| 5 | from qwen_asr_util import QwenAsr | 5 | from qwen_asr_util import QwenAsr |
| 6 | def batch_with_asr(): | 6 | def batch_with_asr(): |
| 7 | - fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7) | 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) |
| 8 | qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B",temperature=0.7, | 8 | qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B",temperature=0.7, |
| 9 | api_key='no_key') | 9 | api_key='no_key') |
| 10 | 10 | ||
| @@ -27,7 +27,7 @@ def batch_with_asr(): | @@ -27,7 +27,7 @@ def batch_with_asr(): | ||
| 27 | print(event_json) | 27 | print(event_json) |
| 28 | 28 | ||
| 29 | def batch_without_asr(): | 29 | def batch_without_asr(): |
| 30 | - fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7) | 30 | + fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7) |
| 31 | # qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B", temperature=0.7, | 31 | # qwen_asr = QwenAsr(base_url="http://192.168.1.59:8101/v1", model="Qwen/Qwen3-ASR-1.7B", temperature=0.7, |
| 32 | # api_key='no_key') | 32 | # api_key='no_key') |
| 33 | 33 | ||
| @@ -51,7 +51,7 @@ def batch_without_asr(): | @@ -51,7 +51,7 @@ def batch_without_asr(): | ||
| 51 | print(event_json) | 51 | print(event_json) |
| 52 | 52 | ||
| 53 | def one_video_test(video_path): | 53 | def one_video_test(video_path): |
| 54 | - fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434", model="qwen3.6:35b-a3b-q8_0", temperature=0.7) | 54 | + fbrv = FootballReplayVideoEvent(base_url="http://192.168.1.59:11434/v1", model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf", temperature=0.7) |
| 55 | event_json = fbrv.video_event(video_path, None) | 55 | event_json = fbrv.video_event(video_path, None) |
| 56 | print(event_json) | 56 | print(event_json) |
| 57 | 57 |
| @@ -3,7 +3,7 @@ import json | @@ -3,7 +3,7 @@ import json | ||
| 3 | from pathlib import Path | 3 | from pathlib import Path |
| 4 | 4 | ||
| 5 | from aabd.base.time_util import vms2str_auto | 5 | from aabd.base.time_util import vms2str_auto |
| 6 | -from langchain_ollama import ChatOllama | 6 | +from langchain_openai import ChatOpenAI |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | class ClipByEvent: | 9 | class ClipByEvent: |
| @@ -19,7 +19,7 @@ class ClipByEvent: | @@ -19,7 +19,7 @@ class ClipByEvent: | ||
| 19 | # keep_alive=-1, reasoning=False) | 19 | # keep_alive=-1, reasoning=False) |
| 20 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, | 20 | # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, |
| 21 | # api_key='no_key') | 21 | # api_key='no_key') |
| 22 | - self.model = ChatOllama(base_url=base_url, model=model, temperature=temperature, keep_alive=-1, reasoning=False) | 22 | + self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key) |
| 23 | 23 | ||
| 24 | def get_video_match_time(self, video_path, video_time): | 24 | def get_video_match_time(self, video_path, video_time): |
| 25 | import cv2 | 25 | import cv2 |
-
Please register or login to post a comment