Go: fix context (#18118)

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-08-11 19:19:29 +08:00
committed by GitHub
parent 8bd5768ebc
commit c75edbfbe8
36 changed files with 492 additions and 352 deletions

View File

@@ -35,7 +35,9 @@ func TestLLM_ForwardsTopP(t *testing.T) {
ModelID: "echo",
TopP: &topP,
})
if _, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "hi"}); err != nil {
ctx := t.Context()
if _, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "hi"}); err != nil {
t.Fatalf("Invoke: %v", err)
}
if stub.calls != 1 {
@@ -57,9 +59,11 @@ func TestLLM_ForwardsTopP(t *testing.T) {
func TestLLM_TopPFromInputs(t *testing.T) {
stub := &stubInvoker{resp: &ChatInvokeResponse{Content: "ok", Model: "echo"}}
withStubInvoker(t, stub)
ctx := t.Context()
c := NewLLMComponent(LLMParam{ModelID: "echo"})
if _, err := c.Invoke(context.Background(), nil, map[string]any{
if _, err := c.Invoke(ctx, nil, map[string]any{
"user_prompt": "hi",
"top_p": 0.7,
}); err != nil {
@@ -78,9 +82,10 @@ func TestLLM_TopPFromInputs(t *testing.T) {
func TestLLM_NoTopPByDefault(t *testing.T) {
stub := &stubInvoker{resp: &ChatInvokeResponse{Content: "ok", Model: "echo"}}
withStubInvoker(t, stub)
ctx := t.Context()
c := NewLLMComponent(LLMParam{ModelID: "echo"})
if _, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "hi"}); err != nil {
if _, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "hi"}); err != nil {
t.Fatalf("Invoke: %v", err)
}
if stub.captured == nil {
@@ -128,6 +133,7 @@ func TestAgentParam_ForwardsTopP(t *testing.T) {
}
return &schema.Message{Content: "ok"}, nil
})
ctx := t.Context()
topP := 0.5
c := NewAgentComponent(AgentParam{
@@ -135,7 +141,7 @@ func TestAgentParam_ForwardsTopP(t *testing.T) {
TopP: &topP,
MaxRounds: 1,
})
if _, err := c.Invoke(context.Background(), nil, map[string]any{"user_prompt": "hi"}); err != nil {
if _, err := c.Invoke(ctx, nil, map[string]any{"user_prompt": "hi"}); err != nil {
t.Fatalf("Invoke: %v", err)
}
}
@@ -148,9 +154,10 @@ func TestAgent_TopPFromInputs(t *testing.T) {
}
return &schema.Message{Content: "ok"}, nil
})
ctx := t.Context()
c := NewAgentComponent(AgentParam{ModelID: "echo", MaxRounds: 1})
if _, err := c.Invoke(context.Background(), nil, map[string]any{
if _, err := c.Invoke(ctx, nil, map[string]any{
"user_prompt": "hi",
"top_p": 0.42,
}); err != nil {