update action parser
This commit is contained in:
@@ -18,9 +18,7 @@ class ModelConfig:
|
|||||||
temperature: float = 0.0
|
temperature: float = 0.0
|
||||||
top_p: float = 0.85
|
top_p: float = 0.85
|
||||||
frequency_penalty: float = 0.2
|
frequency_penalty: float = 0.2
|
||||||
extra_body: dict[str, Any] = field(
|
extra_body: dict[str, Any] = field(default_factory=dict)
|
||||||
default_factory=lambda: {"skip_special_tokens": False}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -65,6 +63,7 @@ class ModelClient:
|
|||||||
top_p=self.config.top_p,
|
top_p=self.config.top_p,
|
||||||
frequency_penalty=self.config.frequency_penalty,
|
frequency_penalty=self.config.frequency_penalty,
|
||||||
extra_body=self.config.extra_body,
|
extra_body=self.config.extra_body,
|
||||||
|
stream=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
raw_content = response.choices[0].message.content
|
raw_content = response.choices[0].message.content
|
||||||
@@ -78,20 +77,43 @@ class ModelClient:
|
|||||||
"""
|
"""
|
||||||
Parse the model response into thinking and action parts.
|
Parse the model response into thinking and action parts.
|
||||||
|
|
||||||
|
Parsing rules:
|
||||||
|
1. If content contains 'finish(message=', everything before is thinking,
|
||||||
|
everything from 'finish(message=' onwards is action.
|
||||||
|
2. If rule 1 doesn't apply but content contains 'do(action=',
|
||||||
|
everything before is thinking, everything from 'do(action=' onwards is action.
|
||||||
|
3. Fallback: If content contains '<answer>', use legacy parsing with XML tags.
|
||||||
|
4. Otherwise, return empty thinking and full content as action.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
content: Raw response content.
|
content: Raw response content.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of (thinking, action).
|
Tuple of (thinking, action).
|
||||||
"""
|
"""
|
||||||
if "<answer>" not in content:
|
# Rule 1: Check for finish(message=
|
||||||
return "", content
|
if "finish(message=" in content:
|
||||||
|
parts = content.split("finish(message=", 1)
|
||||||
|
thinking = parts[0].strip()
|
||||||
|
action = "finish(message=" + parts[1]
|
||||||
|
return thinking, action
|
||||||
|
|
||||||
parts = content.split("<answer>", 1)
|
# Rule 2: Check for do(action=
|
||||||
thinking = parts[0].replace("<think>", "").replace("</think>", "").strip()
|
if "do(action=" in content:
|
||||||
action = parts[1].replace("</answer>", "").strip()
|
parts = content.split("do(action=", 1)
|
||||||
|
thinking = parts[0].strip()
|
||||||
|
action = "do(action=" + parts[1]
|
||||||
|
return thinking, action
|
||||||
|
|
||||||
return thinking, action
|
# Rule 3: Fallback to legacy XML tag parsing
|
||||||
|
if "<answer>" in content:
|
||||||
|
parts = content.split("<answer>", 1)
|
||||||
|
thinking = parts[0].replace("<think>", "").replace("</think>", "").strip()
|
||||||
|
action = parts[1].replace("</answer>", "").strip()
|
||||||
|
return thinking, action
|
||||||
|
|
||||||
|
# Rule 4: No markers found, return content as action
|
||||||
|
return "", content
|
||||||
|
|
||||||
|
|
||||||
class MessageBuilder:
|
class MessageBuilder:
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ if __name__ == "__main__":
|
|||||||
temperature=args.temperature,
|
temperature=args.temperature,
|
||||||
top_p=args.top_p,
|
top_p=args.top_p,
|
||||||
frequency_penalty=args.frequency_penalty,
|
frequency_penalty=args.frequency_penalty,
|
||||||
extra_body={"skip_special_tokens": False},
|
stream=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("\n模型推理结果:")
|
print("\n模型推理结果:")
|
||||||
|
|||||||
Reference in New Issue
Block a user