Skip to content

Commit daf1274

Browse files
ddobrinmarkpollack
authored andcommitted
Add spring-ai-google-genai module using Google's new GenAI SDK
Introduces a new module that provides an alternative to spring-ai-vertex-ai-gemini using Google's latest GenAI SDK. This implementation offers the same functionality and API surface as the existing Vertex AI module while leveraging Google's new unified AI platform. Key Features: - GoogleGenAiChatModel with identical functionality to VertexAiGeminiChatModel - Complete support for Gemini Pro, 1.5 Pro, and 2.0 Flash model variants - Full tool/function calling capabilities via GoogleGenAiToolCallingManager - Streaming support with reactive programming model - Comprehensive safety settings and content filtering - Multi-modal content support (text, images, PDFs) - Google Search Retrieval integration - Built-in retry mechanisms and Micrometer observability Technical Implementation: - Mirrors the architecture and patterns of spring-ai-vertex-ai-gemini - Uses Google's com.google.genai.Client instead of Vertex AI SDK - Maintains full API compatibility with existing Spring AI patterns - Includes comprehensive test suite covering all functionality areas - Proper Maven integration and AOT support Test Coverage: - 12 comprehensive test classes mirroring vertex-ai-gemini tests - Integration tests for chat, streaming, tool calling, and observations - Multi-modal content testing with images and PDFs - Safety settings and retry mechanism validation - Schema conversion and JSON handling tests Signed-off-by: ddobrin <[email protected]>
1 parent 49e5c63 commit daf1274

36 files changed

+4990
-26
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[VertexAI Gemini Chat](https://docs.spring.io/spring-ai/reference/api/chat/vertexai-gemini-chat.html)
2+
3+
### Starter - WIP
4+
```xml
5+
<dependency>
6+
<groupId>org.springframework.ai</groupId>
7+
<artifactId>spring-ai-starter-model-spring-ai-google-genai</artifactId>
8+
</dependency>
9+
```
10+
11+
### Manual config
12+
```xml
13+
<dependency>
14+
<groupId>org.springframework.ai</groupId>
15+
<artifactId>spring-ai-google-genai</artifactId>
16+
</dependency>
17+
```
18+
19+
### Environment variables
20+
```shell
21+
export GOOGLE_GENAI_USE_VERTEXAI=true
22+
export GOOGLE_CLOUD_PROJECT='your-project-id'
23+
export GOOGLE_CLOUD_LOCATION='your-region'
24+
```

models/spring-ai-google-genai/pom.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.springframework.ai</groupId>
24+
<artifactId>spring-ai-parent</artifactId>
25+
<version>1.1.0-SNAPSHOT</version>
26+
<relativePath>../../pom.xml</relativePath>
27+
</parent>
28+
<artifactId>spring-ai-google-genai</artifactId>
29+
<packaging>jar</packaging>
30+
<name>Spring AI Model - Google GenAI</name>
31+
<description>Google GenAI Gemini models support</description>
32+
<url>https://github.com/spring-projects/spring-ai</url>
33+
34+
<scm>
35+
<url>https://github.com/spring-projects/spring-ai</url>
36+
<connection>git://github.com/spring-projects/spring-ai.git</connection>
37+
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
38+
</scm>
39+
40+
<properties>
41+
</properties>
42+
43+
<dependencies>
44+
45+
<dependency>
46+
<groupId>com.google.genai</groupId>
47+
<artifactId>google-genai</artifactId>
48+
<version>1.8.0</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.github.victools</groupId>
53+
<artifactId>jsonschema-generator</artifactId>
54+
<version>${victools.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.github.victools</groupId>
58+
<artifactId>jsonschema-module-jackson</artifactId>
59+
<version>${victools.version}</version>
60+
</dependency>
61+
62+
<!-- production dependencies -->
63+
<dependency>
64+
<groupId>org.springframework.ai</groupId>
65+
<artifactId>spring-ai-model</artifactId>
66+
<version>${project.parent.version}</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.ai</groupId>
71+
<artifactId>spring-ai-retry</artifactId>
72+
<version>${project.parent.version}</version>
73+
</dependency>
74+
75+
76+
<!-- Spring Framework -->
77+
<dependency>
78+
<groupId>org.springframework</groupId>
79+
<artifactId>spring-context-support</artifactId>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.slf4j</groupId>
84+
<artifactId>slf4j-api</artifactId>
85+
</dependency>
86+
87+
<!-- test dependencies -->
88+
<dependency>
89+
<groupId>org.springframework.ai</groupId>
90+
<artifactId>spring-ai-test</artifactId>
91+
<version>${project.version}</version>
92+
<scope>test</scope>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>io.micrometer</groupId>
97+
<artifactId>micrometer-observation-test</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
101+
</dependencies>
102+
103+
</project>

0 commit comments

Comments
 (0)