Detailed changes
@@ -7,6 +7,7 @@ import (
"encoding/base64"
"encoding/json"
"errors"
+ "flag"
"fmt"
"io"
"log/slog"
@@ -125,13 +126,19 @@ func (a *provider) LanguageModel(ctx context.Context, modelID string) (fantasy.L
for key, value := range a.options.headers {
clientOptions = append(clientOptions, option.WithHeader(key, value))
}
- if a.options.client != nil {
- clientOptions = append(clientOptions, option.WithHTTPClient(a.options.client))
- }
if a.options.vertexProject != "" && a.options.vertexLocation != "" {
- credentials, err := google.FindDefaultCredentials(ctx)
- if err != nil {
- return nil, err
+ var credentials *google.Credentials
+ var err error
+ // Check if we are in tests
+ if flag.Lookup("test.v") != nil {
+ credentials = &google.Credentials{
+ TokenSource: &dummyTokenProvider{},
+ }
+ } else {
+ credentials, err = google.FindDefaultCredentials(ctx)
+ if err != nil {
+ return nil, err
+ }
}
clientOptions = append(
@@ -168,6 +175,10 @@ func (a *provider) LanguageModel(ctx context.Context, modelID string) (fantasy.L
)
}
}
+
+ if a.options.client != nil {
+ clientOptions = append(clientOptions, option.WithHTTPClient(a.options.client))
+ }
return languageModel{
modelID: modelID,
provider: a.options.name,
@@ -0,0 +1,10 @@
+package anthropic
+
+import "golang.org/x/oauth2"
+
+type dummyTokenProvider struct{}
+
+// Token implements the auth.TokenProvider interface.
+func (dummyTokenProvider) Token() (*oauth2.Token, error) {
+ return &oauth2.Token{AccessToken: "dummy-token"}, nil
+}
@@ -8,6 +8,6 @@ FANTASY_HUGGINGFACE_API_KEY=
FANTASY_OPENAI_API_KEY=
FANTASY_OPENROUTER_API_KEY=
FANTASY_VERTEX_LOCATION=us-east5
-FANTASY_VERTEX_PROJECT=fantasy-playground-472418
+FANTASY_VERTEX_PROJECT=fantasy
FANTASY_XAI_API_KEY=
FANTASY_ZAI_API_KEY=
@@ -94,8 +94,10 @@ func geminiBuilder(model string) builderFunc {
func vertexBuilder(model string) builderFunc {
return func(t *testing.T, r *recorder.Recorder) (fantasy.LanguageModel, error) {
+ project := cmp.Or(os.Getenv("FANTASY_VERTEX_PROJECT"), "fantasy")
+ location := cmp.Or(os.Getenv("FANTASY_VERTEX_LOCATION"), "us-east5")
provider, err := google.New(
- google.WithVertex(os.Getenv("FANTASY_VERTEX_PROJECT"), os.Getenv("FANTASY_VERTEX_LOCATION")),
+ google.WithVertex(project, location),
google.WithHTTPClient(&http.Client{Transport: r}),
google.WithToolCallIDFunc(generateIDMock()),
)
@@ -16,7 +16,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
method: POST
response:
proto: HTTP/2.0
@@ -16,7 +16,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
method: POST
response:
proto: HTTP/2.0
@@ -16,7 +16,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
method: POST
response:
proto: HTTP/2.0
@@ -46,7 +46,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:rawPredict
method: POST
response:
proto: HTTP/2.0
@@ -16,7 +16,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
method: POST
response:
proto: HTTP/2.0
@@ -97,7 +97,7 @@ interactions:
- application/json
User-Agent:
- Anthropic/Go 1.14.0
- url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy-playground-472418/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
+ url: https://us-east5-aiplatform.googleapis.com/v1/projects/fantasy/locations/us-east5/publishers/anthropic/models/claude-3-7-sonnet@20250219:streamRawPredict
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -98,7 +98,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -49,7 +49,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -88,7 +88,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -49,7 +49,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-flash:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -98,7 +98,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -49,7 +49,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -15,7 +15,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -88,7 +88,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:generateContent
method: POST
response:
proto: HTTP/2.0
@@ -18,7 +18,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -49,7 +49,7 @@ interactions:
- application/json
User-Agent:
- google-genai-sdk/1.29.0 gl-go/go1.25.1
- url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
+ url: https://us-east5-aiplatform.googleapis.com/v1beta1/projects/fantasy/locations/us-east5/publishers/google/models/gemini-2.5-pro:streamGenerateContent?alt=sse
method: POST
response:
proto: HTTP/2.0
@@ -1,3 +0,0 @@
----
-version: 2
-interactions: []
@@ -1,70 +0,0 @@
----
-version: 2
-interactions:
-- id: 0
- request:
- proto: HTTP/1.1
- proto_major: 1
- proto_minor: 1
- content_length: 180
- host: us-central1-aiplatform.googleapis.com
- body: |
- {"contents":[{"parts":[{"text":"Say hi in Portuguese"}],"role":"user"}],"generationConfig":{},"systemInstruction":{"parts":[{"text":"You are a helpful assistant"}],"role":"user"}}
- headers:
- Content-Type:
- - application/json
- User-Agent:
- - google-genai-sdk/1.25.0 gl-go/go1.25.0
- url: https://us-central1-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-central1/publishers/google/models/gemini-2.5-flash:generateContent
- method: POST
- response:
- proto: HTTP/2.0
- proto_major: 2
- proto_minor: 0
- content_length: -1
- uncompressed: true
- body: |
- {
- "candidates": [
- {
- "content": {
- "role": "model",
- "parts": [
- {
- "text": "Olรก!"
- }
- ]
- },
- "finishReason": "STOP",
- "avgLogprobs": -0.57995378971099854
- }
- ],
- "usageMetadata": {
- "promptTokenCount": 9,
- "candidatesTokenCount": 2,
- "totalTokenCount": 37,
- "trafficType": "ON_DEMAND",
- "promptTokensDetails": [
- {
- "modality": "TEXT",
- "tokenCount": 9
- }
- ],
- "candidatesTokensDetails": [
- {
- "modality": "TEXT",
- "tokenCount": 2
- }
- ],
- "thoughtsTokenCount": 26
- },
- "modelVersion": "gemini-2.5-flash",
- "createTime": "2025-09-24T19:46:03.607780Z",
- "responseId": "e0rUaKSMJb-gm9IP0PuYmQo"
- }
- headers:
- Content-Type:
- - application/json; charset=UTF-8
- status: 200 OK
- code: 200
- duration: 1.489268833s
@@ -1,70 +0,0 @@
----
-version: 2
-interactions:
-- id: 0
- request:
- proto: HTTP/1.1
- proto_major: 1
- proto_minor: 1
- content_length: 180
- host: us-central1-aiplatform.googleapis.com
- body: |
- {"contents":[{"parts":[{"text":"Say hi in Portuguese"}],"role":"user"}],"generationConfig":{},"systemInstruction":{"parts":[{"text":"You are a helpful assistant"}],"role":"user"}}
- headers:
- Content-Type:
- - application/json
- User-Agent:
- - google-genai-sdk/1.25.0 gl-go/go1.25.0
- url: https://us-central1-aiplatform.googleapis.com/v1beta1/projects/fantasy-playground-472418/locations/us-central1/publishers/google/models/gemini-2.5-pro:generateContent
- method: POST
- response:
- proto: HTTP/2.0
- proto_major: 2
- proto_minor: 0
- content_length: -1
- uncompressed: true
- body: |
- {
- "candidates": [
- {
- "content": {
- "role": "model",
- "parts": [
- {
- "text": "Of course! The most common ways to say \"hi\" in Portuguese are:\n\n* **Olรก** (oh-LAH) - This is the equivalent of \"hello\" and can be used in any situation.\n* **Oi** (oy) - This is more informal, like \"hi,\" and is extremely common, especially in Brazil.\n\nYou can also use a greeting depending on the time of day:\n\n* **Bom dia** (bohm JEE-ah) - Good morning\n* **Boa tarde** (BOH-ah TAR-jee) - Good afternoon\n* **Boa noite** (BOH-ah NOY-tchee) - Good evening / Good night"
- }
- ]
- },
- "finishReason": "STOP",
- "avgLogprobs": -0.93591674386638479
- }
- ],
- "usageMetadata": {
- "promptTokenCount": 9,
- "candidatesTokenCount": 146,
- "totalTokenCount": 905,
- "trafficType": "ON_DEMAND",
- "promptTokensDetails": [
- {
- "modality": "TEXT",
- "tokenCount": 9
- }
- ],
- "candidatesTokensDetails": [
- {
- "modality": "TEXT",
- "tokenCount": 146
- }
- ],
- "thoughtsTokenCount": 750
- },
- "modelVersion": "gemini-2.5-pro",
- "createTime": "2025-09-24T19:46:04.550048Z",
- "responseId": "fErUaKDJIaChmecP8LzZwQs"
- }
- headers:
- Content-Type:
- - application/json; charset=UTF-8
- status: 200 OK
- code: 200
- duration: 8.665756459s