Improve code quality: remove unused code, simplify random, dynamic timestamps
- Remove unused buildToolCalls() function (logic is inlined)\n- Simplify randomString() using global rand (Go 1.20+)\n- Use dynamic timestamps instead of hardcoded 1234567890\n- Add time import to converter.go
This commit is contained in:
parent
1c2f59c53e
commit
f65ad6b189
3 changed files with 3 additions and 22 deletions
22
converter.go
22
converter.go
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ConvertOpenAIRequest converts an OpenAI ChatCompletionRequest to Anthropic format
|
||||
|
|
@ -136,7 +137,7 @@ func ConvertAnthropicResponse(resp *AnthropicResponse, model string) *ChatComple
|
|||
response := &ChatCompletionResponse{
|
||||
ID: resp.Id,
|
||||
Object: "chat.completion",
|
||||
Created: 1234567890,
|
||||
Created: time.Now().Unix(),
|
||||
Model: model,
|
||||
Choices: make([]Choice, 0),
|
||||
Usage: Usage{
|
||||
|
|
@ -210,22 +211,3 @@ func mapStopReason(reason string) string {
|
|||
return "stop"
|
||||
}
|
||||
}
|
||||
|
||||
// buildToolCalls builds OpenAI ToolCall slice from Anthropic ContentBlocks
|
||||
func buildToolCalls(content []ContentBlock) []ToolCall {
|
||||
var toolCalls []ToolCall
|
||||
for _, block := range content {
|
||||
if block.Type == "tool_use" {
|
||||
inputJSON, _ := json.Marshal(block.Input)
|
||||
toolCalls = append(toolCalls, ToolCall{
|
||||
ID: block.Id,
|
||||
Type: "function",
|
||||
Function: FunctionCall{
|
||||
Name: block.Name,
|
||||
Arguments: string(inputJSON),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
return toolCalls
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,9 +253,8 @@ func writeError(w http.ResponseWriter, code int, message, errType, errCode strin
|
|||
func randomString(n int) string {
|
||||
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
b := make([]byte, n)
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
for i := range b {
|
||||
b[i] = letters[r.Intn(len(letters))]
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
|
|
|||
BIN
proxx
BIN
proxx
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue