This commit is contained in:
lpf
2026-02-13 14:20:24 +08:00
parent 28cea4c3bd
commit 1deb9e6888
2 changed files with 21 additions and 3 deletions

View File

@@ -30,6 +30,8 @@ import (
var errGatewayNotRunningSlash = errors.New("gateway not running")
const llmCallTimeout = 90 * time.Second
type AgentLoop struct {
bus *bus.MessageBus
provider providers.LLMProvider
@@ -253,10 +255,12 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
})
llmStart := time.Now()
response, err := al.callLLMWithModelFallback(ctx, messages, providerToolDefs, map[string]interface{}{
llmCtx, cancelLLM := context.WithTimeout(ctx, llmCallTimeout)
response, err := al.callLLMWithModelFallback(llmCtx, messages, providerToolDefs, map[string]interface{}{
"max_tokens": 8192,
"temperature": 0.7,
})
cancelLLM()
llmElapsed := time.Since(llmStart)
if err != nil {
@@ -469,10 +473,12 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
})
llmStart := time.Now()
response, err := al.callLLMWithModelFallback(ctx, messages, providerToolDefs, map[string]interface{}{
llmCtx, cancelLLM := context.WithTimeout(ctx, llmCallTimeout)
response, err := al.callLLMWithModelFallback(llmCtx, messages, providerToolDefs, map[string]interface{}{
"max_tokens": 8192,
"temperature": 0.7,
})
cancelLLM()
llmElapsed := time.Since(llmStart)
if err != nil {

View File

@@ -8,12 +8,14 @@ package providers
import (
"bytes"
"clawgo/pkg/logger"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
"clawgo/pkg/config"
)
@@ -25,13 +27,15 @@ type HTTPProvider struct {
httpClient *http.Client
}
const defaultChatTimeout = 90 * time.Second
func NewHTTPProvider(apiKey, apiBase, authMode string) *HTTPProvider {
return &HTTPProvider{
apiKey: apiKey,
apiBase: apiBase,
authMode: authMode,
httpClient: &http.Client{
Timeout: 0,
Timeout: defaultChatTimeout,
},
}
}
@@ -41,6 +45,14 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
return nil, fmt.Errorf("API base not configured")
}
logger.DebugCF("provider", "HTTP chat request", map[string]interface{}{
"api_base": p.apiBase,
"model": model,
"messages_count": len(messages),
"tools_count": len(tools),
"timeout": defaultChatTimeout.String(),
})
requestBody := map[string]interface{}{
"model": model,
"messages": messages,