-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support R1 reasoning text in model create result; enhance API d…
…ocs (#5262) Resolves #5255 --------- Co-authored-by: afourney <[email protected]>
- Loading branch information
Showing
12 changed files
with
536 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
python/packages/autogen-ext/src/autogen_ext/models/_utils/parse_r1_content.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import warnings | ||
from typing import Tuple | ||
|
||
|
||
def parse_r1_content(content: str) -> Tuple[str | None, str]: | ||
"""Parse the content of an R1-style message that contains a `<think>...</think>` field.""" | ||
# Find the start and end of the think field | ||
think_start = content.find("<think>") | ||
think_end = content.find("</think>") | ||
|
||
if think_start == -1 or think_end == -1: | ||
warnings.warn( | ||
"Could not find <think>..</think> field in model response content. " "No thought was extracted.", | ||
UserWarning, | ||
stacklevel=2, | ||
) | ||
return None, content | ||
|
||
if think_end < think_start: | ||
warnings.warn( | ||
"Found </think> before <think> in model response content. " "No thought was extracted.", | ||
UserWarning, | ||
stacklevel=2, | ||
) | ||
return None, content | ||
|
||
# Extract the think field | ||
thought = content[think_start + len("<think>") : think_end].strip() | ||
|
||
# Extract the rest of the content, skipping the think field. | ||
content = content[think_end + len("</think>") :].strip() | ||
|
||
return thought, content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.