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:
Franz Kafka 2026-04-15 09:14:45 +00:00
parent 1c2f59c53e
commit f65ad6b189
3 changed files with 3 additions and 22 deletions

View file

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"strings" "strings"
"time"
) )
// ConvertOpenAIRequest converts an OpenAI ChatCompletionRequest to Anthropic format // ConvertOpenAIRequest converts an OpenAI ChatCompletionRequest to Anthropic format
@ -136,7 +137,7 @@ func ConvertAnthropicResponse(resp *AnthropicResponse, model string) *ChatComple
response := &ChatCompletionResponse{ response := &ChatCompletionResponse{
ID: resp.Id, ID: resp.Id,
Object: "chat.completion", Object: "chat.completion",
Created: 1234567890, Created: time.Now().Unix(),
Model: model, Model: model,
Choices: make([]Choice, 0), Choices: make([]Choice, 0),
Usage: Usage{ Usage: Usage{
@ -210,22 +211,3 @@ func mapStopReason(reason string) string {
return "stop" 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
}

View file

@ -253,9 +253,8 @@ func writeError(w http.ResponseWriter, code int, message, errType, errCode strin
func randomString(n int) string { func randomString(n int) string {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, n) b := make([]byte, n)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := range b { for i := range b {
b[i] = letters[r.Intn(len(letters))] b[i] = letters[rand.Intn(len(letters))]
} }
return string(b) return string(b)
} }

BIN
proxx

Binary file not shown.