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

@@ -17,7 +17,6 @@
package component
import (
"context"
"reflect"
"testing"
@@ -285,10 +284,11 @@ func TestBuildMessagesWithImages_WithImages_UsesUserInputMultiContent(t *testing
func TestLLM_Invoke_ForwardsImagesToInvoker(t *testing.T) {
stub := &stubInvoker{resp: &ChatInvokeResponse{Content: "ok", Model: "echo"}}
withStubInvoker(t, stub)
ctx := t.Context()
uri := "data:image/png;base64,iVBORw0KGgo="
c := NewLLMComponent(LLMParam{ModelID: "echo"})
_, err := c.Invoke(context.Background(), nil, map[string]any{
_, err := c.Invoke(ctx, nil, map[string]any{
"user_prompt": "what is this?",
"visual_files": []string{uri},
})
@@ -318,9 +318,10 @@ func TestLLM_Invoke_ForwardsImagesToInvoker(t *testing.T) {
func TestLLM_Invoke_NoVisualFiles_BackwardCompat(t *testing.T) {
stub := &stubInvoker{resp: &ChatInvokeResponse{Content: "ok", Model: "echo"}}
withStubInvoker(t, stub)
ctx := t.Context()
c := NewLLMComponent(LLMParam{ModelID: "echo"})
_, err := c.Invoke(context.Background(), nil, map[string]any{
_, err := c.Invoke(ctx, nil, map[string]any{
"user_prompt": "hi",
})
if err != nil {
@@ -347,10 +348,11 @@ func TestLLM_Invoke_NoVisualFiles_BackwardCompat(t *testing.T) {
func TestLLM_Invoke_VisualFilesAsString(t *testing.T) {
stub := &stubInvoker{resp: &ChatInvokeResponse{Content: "ok", Model: "echo"}}
withStubInvoker(t, stub)
ctx := t.Context()
uri := "data:image/jpeg;base64,/9j/4AAQ"
c := NewLLMComponent(LLMParam{ModelID: "echo"})
_, err := c.Invoke(context.Background(), nil, map[string]any{
_, err := c.Invoke(ctx, nil, map[string]any{
"user_prompt": "describe",
"visual_files": "see " + uri,
})