(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func TestModelFromConfig_UserAgent(t *testing.T) { |
| 35 | t.Parallel() |
| 36 | ctx := testutil.Context(t, testutil.WaitShort) |
| 37 | |
| 38 | expectedUA := chatprovider.UserAgent() |
| 39 | called := make(chan struct{}) |
| 40 | serverURL := chattest.NewOpenAI(t, func(req *chattest.OpenAIRequest) chattest.OpenAIResponse { |
| 41 | assert.Equal(t, expectedUA, req.Header.Get("User-Agent")) |
| 42 | close(called) |
| 43 | return chattest.OpenAINonStreamingResponse("hello") |
| 44 | }) |
| 45 | |
| 46 | keys := chatprovider.ProviderAPIKeys{ |
| 47 | ByProvider: map[string]string{"openai": "test-key"}, |
| 48 | BaseURLByProvider: map[string]string{"openai": serverURL}, |
| 49 | } |
| 50 | |
| 51 | model, err := chatprovider.ModelFromConfig("openai", "gpt-4", keys, expectedUA, nil, nil) |
| 52 | require.NoError(t, err) |
| 53 | |
| 54 | // Make a real call so Fantasy sends an HTTP request to the |
| 55 | // fake server, which asserts the User-Agent header. |
| 56 | _, err = model.Generate(ctx, fantasy.Call{ |
| 57 | Prompt: []fantasy.Message{ |
| 58 | { |
| 59 | Role: fantasy.MessageRoleUser, |
| 60 | Content: []fantasy.MessagePart{ |
| 61 | fantasy.TextPart{Text: "hello"}, |
| 62 | }, |
| 63 | }, |
| 64 | }, |
| 65 | }) |
| 66 | require.NoError(t, err) |
| 67 | _ = testutil.TryReceive(ctx, t, called) |
| 68 | } |
nothing calls this directly
no test coverage detected