Skip to content

Commit 5949b4e

Browse files
committed
fix: Ignore the Chain-of-Thought in AI response
1 parent dd254eb commit 5949b4e

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/Models/OpenAI.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,33 @@ namespace SourceGit.Models
1313
public class OpenAIChatMessage
1414
{
1515
[JsonPropertyName("role")]
16-
public string Role
17-
{
18-
get;
19-
set;
20-
}
16+
public string Role { get; set; }
2117

2218
[JsonPropertyName("content")]
2319
public string Content
2420
{
25-
get;
26-
set;
21+
get => _content;
22+
set
23+
{
24+
// Trim leading newline characters
25+
value = value.TrimStart('\n');
26+
27+
// Ignore the Chain-of-Thought
28+
var thinkTag = "<think>";
29+
var thinkEndTag = "</think>";
30+
var thinkStartIndex = value.IndexOf(thinkTag, StringComparison.OrdinalIgnoreCase);
31+
var thinkEndIndex = value.IndexOf(thinkEndTag, StringComparison.OrdinalIgnoreCase);
32+
33+
if (thinkStartIndex >= 0 && thinkEndIndex > thinkStartIndex)
34+
{
35+
value = value.Substring(thinkEndIndex + thinkEndTag.Length).Trim();
36+
}
37+
38+
_content = value;
39+
}
2740
}
41+
42+
private string _content;
2843
}
2944

3045
public class OpenAIChatChoice

0 commit comments

Comments
 (0)