OpenIPOS commited on
Commit
94359fc
·
verified ·
1 Parent(s): 9f9afd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -4,8 +4,7 @@ import fitz
4
  import docx
5
  from huggingface_hub import InferenceClient
6
 
7
- # 1. 引擎配置:GPT-OSS-120B (基于 MoE 架构的高阶逻辑重器)
8
- # 采用 fastest 自动分流模式,确保响应最灵敏
9
  model_id = "openai/gpt-oss-120b"
10
  hf_token = os.getenv("HF_TOKEN")
11
 
@@ -36,8 +35,8 @@ def extract_text(file_path):
36
 
37
  def chat_fn(message, history):
38
  clean_messages = []
39
- # 设定为全能通用 AI 助手身份
40
- clean_messages.append({"role": "system", "content": "You are a highly capable AI assistant powered by GPT-OSS-120B. Provide professional, detailed, and accurate responses."})
41
 
42
  for turn in history:
43
  clean_messages.append({"role": turn["role"], "content": str(turn["content"])})
@@ -50,7 +49,7 @@ def chat_fn(message, history):
50
  file_path = f.get("path") if isinstance(f, dict) else f
51
  context = extract_text(file_path)
52
  if context:
53
- prompt_text = f"【参考背景】:\n{context}\n\n【用户指令】: {prompt_text}"
54
 
55
  clean_messages.append({"role": "user", "content": prompt_text})
56
 
@@ -61,21 +60,33 @@ def chat_fn(message, history):
61
  clean_messages,
62
  max_tokens=4096,
63
  stream=True,
64
- temperature=0.5
65
  )
66
 
67
  for msg in stream:
68
  if hasattr(msg, 'choices') and len(msg.choices) > 0:
69
  delta_content = msg.choices[0].delta.content
70
  if delta_content:
71
- response += str(delta_content)
 
 
 
 
 
 
 
 
 
 
 
 
72
  yield response
73
 
74
  if response:
75
  yield response + "\n\n---\n> **OpenIPOS MegaNode | GPT-OSS-120B 通用算力出口**"
76
 
77
  except Exception as e:
78
- yield f"⚠️ 算力调度提示: {str(e)}。由于 120B 模型负载较大,请刷新重试。"
79
 
80
  # 3. 统一品牌装修
81
  with gr.Blocks(fill_height=True) as demo:
 
4
  import docx
5
  from huggingface_hub import InferenceClient
6
 
7
+ # 1. 引擎配置:GPT-OSS-120B (通用重型算力)
 
8
  model_id = "openai/gpt-oss-120b"
9
  hf_token = os.getenv("HF_TOKEN")
10
 
 
35
 
36
  def chat_fn(message, history):
37
  clean_messages = []
38
+ # 设定通用大师身份
39
+ clean_messages.append({"role": "system", "content": "You are a professional AI assistant. Please output responses in standard Markdown format (including tables, bold text, etc.)."})
40
 
41
  for turn in history:
42
  clean_messages.append({"role": turn["role"], "content": str(turn["content"])})
 
49
  file_path = f.get("path") if isinstance(f, dict) else f
50
  context = extract_text(file_path)
51
  if context:
52
+ prompt_text = f"【参考背景文档】:\n{context}\n\n【用户指令】: {prompt_text}"
53
 
54
  clean_messages.append({"role": "user", "content": prompt_text})
55
 
 
60
  clean_messages,
61
  max_tokens=4096,
62
  stream=True,
63
+ temperature=0.4
64
  )
65
 
66
  for msg in stream:
67
  if hasattr(msg, 'choices') and len(msg.choices) > 0:
68
  delta_content = msg.choices[0].delta.content
69
  if delta_content:
70
+ # --- 核心修复:针对性清洗 JSON 列表格式数据 ---
71
+ # 120B 经常返回 [{'text': '...'}],我们需要把里面的文字抠出来
72
+ content = ""
73
+ if isinstance(delta_content, list):
74
+ for item in delta_content:
75
+ if isinstance(item, dict) and 'text' in item:
76
+ content += item['text']
77
+ elif isinstance(delta_content, dict):
78
+ content = delta_content.get("text", "")
79
+ else:
80
+ content = str(delta_content)
81
+
82
+ response += content
83
  yield response
84
 
85
  if response:
86
  yield response + "\n\n---\n> **OpenIPOS MegaNode | GPT-OSS-120B 通用算力出口**"
87
 
88
  except Exception as e:
89
+ yield f"⚠️ 算力调度提示: {str(e)}。由于 120B 模型算力强劲但协议特殊,请尝试重新发送指令。"
90
 
91
  # 3. 统一品牌装修
92
  with gr.Blocks(fill_height=True) as demo: