lizhengwei

jira:NYJ-1540 desc: add model_test.py

@@ -101,7 +101,7 @@ class TestReplayMatchEvent(unittest.TestCase): @@ -101,7 +101,7 @@ class TestReplayMatchEvent(unittest.TestCase):
101 for i, replay_name in enumerate(relays_mp4_names): 101 for i, replay_name in enumerate(relays_mp4_names):
102 print(100*"*" + f"replay_name: {replay_name}") 102 print(100*"*" + f"replay_name: {replay_name}")
103 replay_path = os.path.join(replays_mp4_dir, replay_name) 103 replay_path = os.path.join(replays_mp4_dir, replay_name)
104 - data = _base_data(i, replay_path, event_list) 104 + data = _base_data(i+1, replay_path, event_list)
105 105
106 start_time = time.time() 106 start_time = time.time()
107 result = frm.replay_match_event(data) 107 result = frm.replay_match_event(data)
@@ -100,6 +100,8 @@ req_prompt = """ @@ -100,6 +100,8 @@ req_prompt = """
100 # Output Format (输出要求) 100 # Output Format (输出要求)
101 101
102 请**仅**输出一个标准的 JSON 对象,**不要**包含任何推理过程(reasoning)、Markdown 标记(如 ```json)或额外的解释文本。 102 请**仅**输出一个标准的 JSON 对象,**不要**包含任何推理过程(reasoning)、Markdown 标记(如 ```json)或额外的解释文本。
  103 + - 请直接给出结论,不需要解释。
  104 + - 跳过分析步骤,只给结果。
103 105
104 JSON 格式如下: 106 JSON 格式如下:
105 { 107 {
@@ -121,10 +123,7 @@ class FootballReplayMatchLive: @@ -121,10 +123,7 @@ class FootballReplayMatchLive:
121 # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, 123 # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7,
122 # api_key='no_key') 124 # api_key='no_key')
123 self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key, 125 self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key,
124 -  
125 - model_kwargs={  
126 - "extra_body": {"enable_thinking": False}  
127 - } 126 + extra_body={"chat_template_kwargs": {"enable_thinking": False}}
128 ) 127 )
129 #extra_body={"chat_template_kwargs": {"enable_thinking": False}}) 128 #extra_body={"chat_template_kwargs": {"enable_thinking": False}})
130 self.cache_dir = cache_dir 129 self.cache_dir = cache_dir
@@ -196,9 +195,9 @@ class FootballReplayMatchLive: @@ -196,9 +195,9 @@ class FootballReplayMatchLive:
196 result = self.model.invoke([system_message, user_message]).content 195 result = self.model.invoke([system_message, user_message]).content
197 196
198 197
199 - print(100*"3")  
200 - print(result)  
201 - print(100*"4") 198 + # print(100*"3")
  199 + # print(result)
  200 + # print(100*"4")
202 # try: 201 # try:
203 # result_json = json.loads(result) 202 # result_json = json.loads(result)
204 # except json.JSONDecodeError: 203 # except json.JSONDecodeError:
@@ -207,7 +206,9 @@ class FootballReplayMatchLive: @@ -207,7 +206,9 @@ class FootballReplayMatchLive:
207 # except Exception as e: 206 # except Exception as e:
208 # print("JSON解析失败:", result) 207 # print("JSON解析失败:", result)
209 # raise e 208 # raise e
210 - 209 + if result.strip() == "null":
  210 + result_json = {"video_id": None}
  211 + else:
211 try: 212 try:
212 # 1. 深度清洗:去掉 Markdown 标记 213 # 1. 深度清洗:去掉 Markdown 标记
213 cleaned_result = result.replace("```json", "").replace("```", "") 214 cleaned_result = result.replace("```json", "").replace("```", "")
@@ -76,9 +76,7 @@ class FootballReplayVideoEvent: @@ -76,9 +76,7 @@ class FootballReplayVideoEvent:
76 # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7, 76 # self.model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1", model="qwen3.6:35b-a3b-q8_0", temperature=0.7,
77 # api_key='no_key') 77 # api_key='no_key')
78 self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key, 78 self.model = ChatOpenAI(base_url=base_url, model=model, temperature=temperature, api_key=api_key,
79 - model_kwargs={  
80 - "extra_body": {"enable_thinking": False}  
81 - } 79 + extra_body={"chat_template_kwargs": {"enable_thinking": False}}
82 ) 80 )
83 # extra_body={"enable_thinking": False}) 81 # extra_body={"enable_thinking": False})
84 # extra_body={"chat_template_kwargs": {"enable_thinking": False}}) 82 # extra_body={"chat_template_kwargs": {"enable_thinking": False}})
  1 +import time
  2 +from langchain_openai import ChatOpenAI
  3 +from langchain_core.messages import SystemMessage, HumanMessage
  4 +model = ChatOpenAI(base_url="http://192.168.1.59:11434/v1",
  5 + model="Qwen3.6-35B-A3B-UD-Q8_K_XL.gguf",
  6 + temperature=0.7,
  7 + api_key='no_key',
  8 + extra_body={"chat_template_kwargs": {"enable_thinking": False}}
  9 + )
  10 +
  11 +req_prompt = """
  12 +### 角色设定
  13 +你是一个聊天机器人"。
  14 +
  15 +### 输入内容
  16 +1. **文本**:问题文本。
  17 +
  18 +### 输出要求
  19 +回答问题
  20 +"""
  21 +contents = """ 你好!"""
  22 +system_message = SystemMessage(content=req_prompt)
  23 +video_message = HumanMessage(content=contents)
  24 +# asr_message = HumanMessage(content=f"解说内容:{asr_text}")
  25 +
  26 +start_time = time.time()
  27 +result = model.invoke([system_message, video_message])
  28 +end_time = time.time()
  29 +print(f"cost time: {end_time - start_time:.2f} seconds")
  30 +
  31 +print(result)