Skip to content

Commit a36e126

Browse files
mrh997meguminnnnnnnnn
authored andcommitted
feat(agentic_gemini): support agentic gemini
1 parent 30377f9 commit a36e126

File tree

16 files changed

+3896
-0
lines changed

16 files changed

+3896
-0
lines changed

components/agentic/gemini/conv.go

Lines changed: 641 additions & 0 deletions
Large diffs are not rendered by default.

components/agentic/gemini/conv_test.go

Lines changed: 742 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2025 CloudWeGo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"log"
23+
"os"
24+
25+
"google.golang.org/genai"
26+
27+
"github.com/cloudwego/eino/schema"
28+
29+
"github.com/cloudwego/eino-ext/components/agentic/gemini"
30+
)
31+
32+
func main() {
33+
apiKey := os.Getenv("GEMINI_API_KEY")
34+
modelName := os.Getenv("GEMINI_MODEL")
35+
36+
ctx := context.Background()
37+
client, err := genai.NewClient(ctx, &genai.ClientConfig{
38+
APIKey: apiKey,
39+
})
40+
if err != nil {
41+
log.Fatalf("NewClient of gemini failed, err=%v", err)
42+
}
43+
44+
cm, err := gemini.NewAgenticModel(ctx, &gemini.Config{
45+
Client: client,
46+
Model: modelName,
47+
ThinkingConfig: &genai.ThinkingConfig{
48+
IncludeThoughts: true,
49+
ThinkingBudget: nil,
50+
},
51+
})
52+
if err != nil {
53+
log.Fatalf("NewChatModel of gemini failed, err=%v", err)
54+
}
55+
56+
resp, err := cm.Generate(ctx, []*schema.AgenticMessage{schema.UserAgenticMessage("What's the capital of France")})
57+
if err != nil {
58+
log.Fatalf("Generate error: %v", err)
59+
}
60+
61+
fmt.Printf("\n%s\n", resp.String())
62+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright 2025 CloudWeGo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
"encoding/base64"
22+
"fmt"
23+
"log"
24+
"os"
25+
26+
"google.golang.org/genai"
27+
28+
"github.com/cloudwego/eino/schema"
29+
30+
"github.com/cloudwego/eino-ext/components/agentic/gemini"
31+
)
32+
33+
func main() {
34+
apiKey := os.Getenv("GEMINI_API_KEY")
35+
modelName := os.Getenv("GEMINI_MODEL")
36+
37+
ctx := context.Background()
38+
client, err := genai.NewClient(ctx, &genai.ClientConfig{
39+
APIKey: apiKey,
40+
})
41+
if err != nil {
42+
log.Fatalf("NewClient of gemini failed, err=%v", err)
43+
}
44+
45+
cm, err := gemini.NewAgenticModel(ctx, &gemini.Config{
46+
Client: client,
47+
Model: modelName,
48+
})
49+
if err != nil {
50+
log.Fatalf("NewChatModel of gemini failed, err=%v", err)
51+
}
52+
53+
image, err := os.ReadFile("./examples/generate_with_image/test.jpg")
54+
if err != nil {
55+
log.Fatalf("os.ReadFile failed, err=%v\n", err)
56+
}
57+
58+
imageStr := base64.StdEncoding.EncodeToString(image)
59+
60+
resp, err := cm.Generate(ctx, []*schema.AgenticMessage{
61+
{
62+
Role: schema.AgenticRoleTypeUser,
63+
ContentBlocks: []*schema.ContentBlock{
64+
{Type: schema.ContentBlockTypeUserInputText, UserInputText: &schema.UserInputText{Text: "What do you see in this image?"}},
65+
{Type: schema.ContentBlockTypeUserInputImage, UserInputImage: &schema.UserInputImage{Base64Data: imageStr, MIMEType: "image/jpeg"}},
66+
},
67+
},
68+
})
69+
if err != nil {
70+
log.Fatalf("Generate error: %v", err)
71+
}
72+
fmt.Printf("Assistant: %s\n", resp.String())
73+
}
7.92 KB
Loading

0 commit comments

Comments
 (0)