mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-13 18:07:36 +08:00
fix
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user