Upload main.go
Browse files
main.go
CHANGED
|
@@ -545,15 +545,18 @@ func countTokens(c *gin.Context) {
|
|
| 545 |
|
| 546 |
if estimateErr == nil {
|
| 547 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 548 |
-
// 返回估算值,但添加警告信息
|
| 549 |
-
c.JSON(http.
|
| 550 |
"input_tokens": estimatedResult.InputTokens,
|
| 551 |
"warning": fmt.Sprintf("The tokenizer for model '%s' is not supported yet. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 552 |
"estimated_with": "gpt-4o",
|
|
|
|
| 553 |
})
|
| 554 |
return
|
| 555 |
} else {
|
| 556 |
log.Printf("使用GPT-4o估算失败: %v", estimateErr)
|
|
|
|
|
|
|
| 557 |
}
|
| 558 |
} else {
|
| 559 |
log.Printf("完全不支持的模型: %s, 将尝试使用GPT-4o估算", originalModel)
|
|
@@ -565,10 +568,11 @@ func countTokens(c *gin.Context) {
|
|
| 565 |
estimatedResult, estimateErr := countTokensWithOpenAI(gptReq)
|
| 566 |
if estimateErr == nil {
|
| 567 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 568 |
-
c.JSON(http.
|
| 569 |
"input_tokens": estimatedResult.InputTokens,
|
| 570 |
"warning": fmt.Sprintf("The tokenizer for model '%s' is not supported yet. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 571 |
"estimated_with": "gpt-4o",
|
|
|
|
| 572 |
})
|
| 573 |
} else {
|
| 574 |
log.Printf("使用GPT-4o估算失败: %v", estimateErr)
|
|
@@ -593,12 +597,12 @@ func countTokens(c *gin.Context) {
|
|
| 593 |
if estimateErr == nil {
|
| 594 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 595 |
|
| 596 |
-
// 返回估算值,但添加警告信息和原始错误
|
| 597 |
-
c.JSON(http.
|
| 598 |
"input_tokens": estimatedResult.InputTokens,
|
| 599 |
"warning": fmt.Sprintf("Token calculation for model '%s' failed. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 600 |
"estimated_with": "gpt-4o",
|
| 601 |
-
"
|
| 602 |
})
|
| 603 |
return
|
| 604 |
} else {
|
|
|
|
| 545 |
|
| 546 |
if estimateErr == nil {
|
| 547 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 548 |
+
// 返回估算值,但添加警告信息,使用400状态码
|
| 549 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 550 |
"input_tokens": estimatedResult.InputTokens,
|
| 551 |
"warning": fmt.Sprintf("The tokenizer for model '%s' is not supported yet. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 552 |
"estimated_with": "gpt-4o",
|
| 553 |
+
"error": fmt.Sprintf("Unsupported model: %s", originalModel),
|
| 554 |
})
|
| 555 |
return
|
| 556 |
} else {
|
| 557 |
log.Printf("使用GPT-4o估算失败: %v", estimateErr)
|
| 558 |
+
c.JSON(http.StatusBadRequest, ErrorResponse{Error: fmt.Sprintf("Failed to estimate tokens for unsupported model: %s", originalModel)})
|
| 559 |
+
return
|
| 560 |
}
|
| 561 |
} else {
|
| 562 |
log.Printf("完全不支持的模型: %s, 将尝试使用GPT-4o估算", originalModel)
|
|
|
|
| 568 |
estimatedResult, estimateErr := countTokensWithOpenAI(gptReq)
|
| 569 |
if estimateErr == nil {
|
| 570 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 571 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 572 |
"input_tokens": estimatedResult.InputTokens,
|
| 573 |
"warning": fmt.Sprintf("The tokenizer for model '%s' is not supported yet. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 574 |
"estimated_with": "gpt-4o",
|
| 575 |
+
"error": fmt.Sprintf("Unsupported model: %s", originalModel),
|
| 576 |
})
|
| 577 |
} else {
|
| 578 |
log.Printf("使用GPT-4o估算失败: %v", estimateErr)
|
|
|
|
| 597 |
if estimateErr == nil {
|
| 598 |
log.Printf("使用GPT-4o估算成功: 模型=%s, 估算tokens=%d", originalModel, estimatedResult.InputTokens)
|
| 599 |
|
| 600 |
+
// 返回估算值,但添加警告信息和原始错误,使用400状态码
|
| 601 |
+
c.JSON(http.StatusBadRequest, gin.H{
|
| 602 |
"input_tokens": estimatedResult.InputTokens,
|
| 603 |
"warning": fmt.Sprintf("Token calculation for model '%s' failed. This is an estimation based on gpt-4o and may not be accurate.", originalModel),
|
| 604 |
"estimated_with": "gpt-4o",
|
| 605 |
+
"error": err.Error(),
|
| 606 |
})
|
| 607 |
return
|
| 608 |
} else {
|