Files
weichenandCursor b49b95dc7a feat(agentx): add OpenAI-compatible streaming LLM client
Parse MiniMax-style SSE deltas, including incremental tool calls, and encode transport failures on the event stream instead of panicking.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 14:43:32 +00:00

51 lines
1.4 KiB
Go

package llm
import (
"context"
"os"
"testing"
"time"
)
// TestSmokeMiniMax hits the real MiniMax endpoint when RUN_AGENTX_SMOKE=1.
// It calibrates the incremental SSE tool-call format and is not part of -short CI.
func TestSmokeMiniMax(t *testing.T) {
if os.Getenv("RUN_AGENTX_SMOKE") != "1" {
t.Skip("set RUN_AGENTX_SMOKE=1 to call MiniMax")
}
key := os.Getenv("AGENTX_API_KEY")
if key == "" {
key = os.Getenv("MINIMAX_API_KEY")
}
if key == "" {
t.Fatal("AGENTX_API_KEY or MINIMAX_API_KEY is required")
}
base := os.Getenv("AGENTX_API_BASE")
if base == "" {
base = os.Getenv("MINIMAX_ENDPOINT_URL")
}
if base == "" {
base = "https://api.minimaxi.com/v1"
}
model := os.Getenv("AGENTX_MODEL")
if model == "" {
model = "MiniMax-M2.7-highspeed"
}
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
defer cancel()
c := &Client{BaseURL: base, APIKey: key, HTTPClient: nil}
var end Event
for ev := range c.Stream(ctx, model, []Message{{Role: RoleUser, Content: "Reply with the single word pong."}}, nil, StreamOptions{MaxTokens: 64}) {
if ev.Kind == KindError {
t.Fatalf("provider error retryable=%v %s", ev.Retryable, ev.ErrorMessage)
}
if ev.Kind == KindMessageEnd {
end = ev
}
}
if end.Message.StopReason != StopEnd || end.Message.Content == "" {
t.Fatalf("unexpected completion %#v", end.Message)
}
t.Logf("smoke ok stop=%s tokens=%d", end.Message.StopReason, end.Usage.TotalTokens)
}