feat: 添加 Token 费用估算与自定义忽略规则
- 在 LLM 客户端中捕获流式响应的 Token 使用量 - 内置多模型官方定价表,支持自定义输入/输出单价覆盖 - 新增 `--price-input` 和 `--price-output` 配置项 - 支持通过 `.airignore` 文件自定义排除评审文件 - 更新中英日文文档,补充费用估算与忽略规则说明
This commit is contained in:
1 parent
02e2e4edd3
commit
28c29e69df
13 files changed
+691
-82
No files matched your search
@@ -3,8 +3,9 @@ package reviewer
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/unclesam-ly/git-air/internal/llm"
|
||||
"strings"
|
||||
|
||||
"github.com/unclesam-ly/git-air/internal/llm"
|
||||
)
|
||||
|
||||
type Reviewer struct {
|
||||
@@ -23,18 +24,19 @@ func NewReviewer(client *llm.Client, repoRoot string, customPrompt string) *Revi
|
||||
}
|
||||
}
|
||||
|
||||
// Execute 执行代码评审
|
||||
func (r *Reviewer) Execute(ctx context.Context, diff string, stream bool, onChunk func(chunk string)) (string, error) {
|
||||
// Execute 执行代码评审,返回 (result, usage, error)
|
||||
func (r *Reviewer) Execute(ctx context.Context, diff string, stream bool, onChunk func(chunk string)) (string, *llm.Usage, error) {
|
||||
if strings.TrimSpace(diff) == "" {
|
||||
return "", fmt.Errorf("diff 内容为空,无需评审")
|
||||
return "", nil, fmt.Errorf("diff 内容为空,无需评审")
|
||||
}
|
||||
|
||||
// 动态组装最终 System Prompt
|
||||
systemPrompt := BuildSystemPrompt(r.customPrompt, r.repoRoot)
|
||||
if stream && onChunk != nil {
|
||||
err := r.client.ReviewStream(ctx, systemPrompt, diff, onChunk)
|
||||
return "", err
|
||||
usage, err := r.client.ReviewStream(ctx, systemPrompt, diff, onChunk)
|
||||
return "", usage, err
|
||||
}
|
||||
|
||||
return r.client.Review(ctx, systemPrompt, diff)
|
||||
result, err := r.client.Review(ctx, systemPrompt, diff)
|
||||
return result, nil, err
|
||||
}
|
||||
Reference in new issue
Block a user