Skip to content

Commit 9ada4e1

Browse files
committed
code_style: reduce token usage by remove repo parameter from tool call
Signed-off-by: leo <longshuang@msn.cn>
1 parent f547ea8 commit 9ada4e1

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

‎src/AI/Agent.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task GenerateCommitMessageAsync(string repo, string currentBranch,
9595

9696
foreach (var call in completion.ToolCalls)
9797
{
98-
var result = await ChatTools.ProcessAsync(call, onUpdate, amendParent);
98+
var result = await ChatTools.ProcessAsync(call, repo, amendParent, onUpdate);
9999
messages.Add(result);
100100
}
101101

‎src/AI/ChatTools.cs‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ public static class ChatTools
1515
{
1616
"type": "object",
1717
"properties": {
18-
"repo": {
19-
"type": "string",
20-
"description": "The path to the repository."
21-
},
2218
"file": {
2319
"type": "string",
2420
"description": "The path to the file."
@@ -28,28 +24,25 @@ public static class ChatTools
2824
"description": "The path to the original file when it has been renamed or copied."
2925
}
3026
},
31-
"required": ["repo", "file"]
27+
"required": ["file"]
3228
}
3329
""")), false);
3430

35-
public static async Task<ToolChatMessage> ProcessAsync(ChatToolCall call, Action<string> output, string amendParent)
31+
public static async Task<ToolChatMessage> ProcessAsync(ChatToolCall call, string repo, string amendParent, Action<string> output)
3632
{
3733
using var doc = JsonDocument.Parse(call.FunctionArguments);
3834

3935
if (call.FunctionName.Equals(GetDetailChangesInFile.FunctionName))
4036
{
41-
var hasRepo = doc.RootElement.TryGetProperty("repo", out var repoPath);
4237
var hasFile = doc.RootElement.TryGetProperty("file", out var filePath);
4338
var hasOriginalFile = doc.RootElement.TryGetProperty("originalFile", out var originalFilePath);
44-
if (!hasRepo)
45-
throw new ArgumentException("repo", "The repo argument is required");
4639
if (!hasFile)
4740
throw new ArgumentException("file", "The file argument is required");
4841

4942
output?.Invoke($"Read changes in file: {filePath.GetString()}");
5043

5144
var orgFilePath = hasOriginalFile ? originalFilePath.GetString() : string.Empty;
52-
var rs = await new Commands.GetFileChangeForAI(repoPath.GetString(), filePath.GetString(), orgFilePath, amendParent).ReadAsync();
45+
var rs = await new Commands.GetFileChangeForAI(repo, filePath.GetString(), orgFilePath, amendParent).ReadAsync();
5346
var message = rs.IsSuccess ? rs.StdOut : string.Empty;
5447
return new ToolChatMessage(call.Id, message);
5548
}

‎src/ViewModels/AIAssistant.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public AIAssistant(Repository repo, AI.Service service, List<Models.Change> chan
5050
SerializeChange(c, builder);
5151
_changeList = builder.ToString();
5252

53-
_amendParent = changes.Count > 0 ? changes[0].DataForAmend?.ParentSHA : null;
53+
if (changes.Count > 0 && changes[0].DataForAmend is { } amend)
54+
_amendParent = amend.ParentSHA;
5455
}
5556

5657
public async Task GenAsync()

0 commit comments

Comments
 (0)