code cleanup
This commit is contained in:
@@ -88,8 +88,6 @@ Start the gateway with default settings:
|
||||
| `-socks` | `""` | SOCKS5 proxy URL (e.g. `socks5://127.0.0.1:1080`) |
|
||||
| `-user-agent` | *(Chrome UA)* | Custom User-Agent string |
|
||||
|
||||
*(Note: legacy flags `-browser`, `-xvfb`, and `-headless` are retained for backward compatibility but are ignored, as groqqer operates completely headless via direct WebSocket).*
|
||||
|
||||
## API usage examples
|
||||
|
||||
### 1. List available models
|
||||
|
||||
BIN
Binary file not shown.
+10
-71
@@ -107,14 +107,11 @@ func (m *ChatMessage) GetContentString() string {
|
||||
}
|
||||
|
||||
type ChatCompletionRequest struct {
|
||||
Model string `json:"model"`
|
||||
Messages []ChatMessage `json:"messages"`
|
||||
Tools []Tool `json:"tools,omitempty"`
|
||||
ToolChoice interface{} `json:"tool_choice,omitempty"`
|
||||
Stream bool `json:"stream"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
MaxCompletionTokens int `json:"max_completion_tokens"`
|
||||
ReasoningEffort string `json:"reasoning_effort,omitempty"`
|
||||
Model string `json:"model"`
|
||||
Messages []ChatMessage `json:"messages"`
|
||||
Tools []Tool `json:"tools,omitempty"`
|
||||
ToolChoice interface{} `json:"tool_choice,omitempty"`
|
||||
Stream bool `json:"stream"`
|
||||
}
|
||||
|
||||
type ChatCompletionResponseChoice struct {
|
||||
@@ -1609,12 +1606,8 @@ func parseToolCallsFromText(input string) ([]ToolCall, bool) {
|
||||
|
||||
func parseXMLToolCall(block string) ([]ToolCall, bool) {
|
||||
inner := strings.TrimSpace(block)
|
||||
if strings.HasPrefix(inner, "<tool_call>") {
|
||||
inner = strings.TrimPrefix(inner, "<tool_call>")
|
||||
}
|
||||
if strings.HasSuffix(inner, "</tool_call>") {
|
||||
inner = strings.TrimSuffix(inner, "</tool_call>")
|
||||
}
|
||||
inner = strings.TrimPrefix(inner, "<tool_call>")
|
||||
inner = strings.TrimSuffix(inner, "</tool_call>")
|
||||
inner = cleanJSONBlock(inner)
|
||||
|
||||
if calls, ok := parseToolCallsFromText(inner); ok {
|
||||
@@ -1658,51 +1651,6 @@ func parseXMLToolCall(block string) ([]ToolCall, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func ExtractToolCallBlocks(content string) (blocks []string, remaining string) {
|
||||
var b []string
|
||||
s := content
|
||||
searchOffset := 0
|
||||
var remainingBuilder strings.Builder
|
||||
lastPos := 0
|
||||
|
||||
for {
|
||||
relStart := strings.Index(s[searchOffset:], "<tool_call>")
|
||||
if relStart == -1 {
|
||||
break
|
||||
}
|
||||
startIdx := searchOffset + relStart
|
||||
afterStart := startIdx + len("<tool_call>")
|
||||
|
||||
relEnd := strings.Index(s[afterStart:], "</tool_call>")
|
||||
if relEnd == -1 {
|
||||
// Unclosed <tool_call>, do not treat as block
|
||||
searchOffset = afterStart
|
||||
continue
|
||||
}
|
||||
|
||||
if innerNext := strings.Index(s[afterStart:afterStart+relEnd], "<tool_call>"); innerNext != -1 {
|
||||
searchOffset = afterStart + innerNext
|
||||
continue
|
||||
}
|
||||
|
||||
endIdx := afterStart + relEnd + len("</tool_call>")
|
||||
blockText := s[startIdx:endIdx]
|
||||
b = append(b, blockText)
|
||||
|
||||
if startIdx > lastPos {
|
||||
remainingBuilder.WriteString(s[lastPos:startIdx])
|
||||
}
|
||||
lastPos = endIdx
|
||||
searchOffset = endIdx
|
||||
}
|
||||
|
||||
if lastPos < len(s) {
|
||||
remainingBuilder.WriteString(s[lastPos:])
|
||||
}
|
||||
|
||||
return b, strings.TrimSpace(remainingBuilder.String())
|
||||
}
|
||||
|
||||
func DetectToolCalls(content string, allowedTools map[string]bool) ([]ToolCall, string, bool) {
|
||||
if len(allowedTools) == 0 {
|
||||
return nil, content, false
|
||||
@@ -2200,10 +2148,9 @@ func WriteCompletionResponse(w http.ResponseWriter, completionID string, created
|
||||
}
|
||||
|
||||
type APIErrorDetail struct {
|
||||
Message string `json:"message"`
|
||||
Type string `json:"type"`
|
||||
Param *string `json:"param"`
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Type string `json:"type"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
type APIErrorResponse struct {
|
||||
@@ -2232,7 +2179,6 @@ type GroqqerGateway struct {
|
||||
proxyURL string
|
||||
userAgent string
|
||||
defaultModel string
|
||||
port int
|
||||
models []ModelItem
|
||||
modelsMu sync.RWMutex
|
||||
}
|
||||
@@ -2664,12 +2610,6 @@ func main() {
|
||||
flag.StringVar(socksProxy, "proxy", "", "Proxy address alias")
|
||||
flag.StringVar(socksProxy, "socks5", "", "SOCKS5 proxy alias")
|
||||
|
||||
// Retain flags for backward compatibility (browser/Xvfb are no longer required)
|
||||
_ = flag.String("browser", "", "Ignored: browser is no longer required (headless WebSocket mode)")
|
||||
_ = flag.Bool("xvfb", false, "Ignored: Xvfb is no longer required")
|
||||
_ = flag.Bool("no-xvfb", false, "Ignored: Xvfb is no longer required")
|
||||
_ = flag.Bool("headless", true, "Ignored: always runs headless via direct WebSocket")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
effectiveProxy := *socksProxy
|
||||
@@ -2689,7 +2629,6 @@ func main() {
|
||||
proxyURL: effectiveProxy,
|
||||
userAgent: *userAgent,
|
||||
defaultModel: *defaultModel,
|
||||
port: *port,
|
||||
}
|
||||
|
||||
// Initial discovery of live models in background
|
||||
|
||||
Reference in New Issue
Block a user