-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d56aa6b
commit 5987cb8
Showing
15 changed files
with
441 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkiverse.langchain4j</groupId> | ||
<artifactId>quarkus-langchain4j-integration-tests-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>quarkus-langchain4j-integration-test-vertex-ai-gemini</artifactId> | ||
<name>Quarkus LangChain4j - Integration Tests - Vertex AI Gemini</name> | ||
<properties> | ||
<skipITs>true</skipITs> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-jackson</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkiverse.langchain4j</groupId> | ||
<artifactId>quarkus-langchain4j-vertex-ai-gemini</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-micrometer</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-smallrye-fault-tolerance</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${assertj.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-devtools-testing</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Make sure the deployment artifact is built before executing this module --> | ||
<dependency> | ||
<groupId>io.quarkiverse.langchain4j</groupId> | ||
<artifactId>quarkus-langchain4j-vertex-ai-gemini-deployment</artifactId> | ||
<version>${project.version}</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>integration-test</goal> | ||
<goal>verify</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<profiles> | ||
<profile> | ||
<id>native-image</id> | ||
<activation> | ||
<property> | ||
<name>native</name> | ||
</property> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${native.surefire.skip}</skipTests> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<skipITs>false</skipITs> | ||
<quarkus.package.type>native</quarkus.package.type> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
...i-gemini/src/main/java/org/acme/example/gemini/aiservices/AssistantWithToolsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.acme.example.gemini.aiservices; | ||
|
||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import org.jboss.resteasy.reactive.RestQuery; | ||
|
||
import dev.langchain4j.agent.tool.Tool; | ||
import io.quarkiverse.langchain4j.RegisterAiService; | ||
|
||
@Path("assistant-with-tool") | ||
public class AssistantWithToolsResource { | ||
|
||
private final Assistant assistant; | ||
|
||
@Inject | ||
AddContentTool tool; | ||
|
||
public AssistantWithToolsResource(Assistant assistant) { | ||
this.assistant = assistant; | ||
} | ||
|
||
@GET | ||
public String get(@RestQuery String message) { | ||
return assistant.chat(message) + "; " + tool.tool1Content; | ||
} | ||
|
||
@RegisterAiService(tools = AddContentTool.class) | ||
public interface Assistant { | ||
String chat(String userMessage); | ||
} | ||
|
||
@Singleton | ||
public static class AddContentTool { | ||
|
||
volatile String tool1Content; | ||
|
||
@Tool("Add content") | ||
void addContent(String content) { | ||
this.tool1Content = "Tool1: " + content; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../vertex-ai-gemini/src/main/java/org/acme/example/gemini/aiservices/DummyAuthProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.acme.example.gemini.aiservices; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import io.quarkiverse.langchain4j.auth.ModelAuthProvider; | ||
|
||
@Singleton | ||
public class DummyAuthProvider implements ModelAuthProvider { | ||
|
||
@Override | ||
public String getAuthorization(Input input) { | ||
return "Bearer token"; | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...sts/vertex-ai-gemini/src/main/java/org/acme/example/gemini/aiservices/GeminiResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.acme.example.gemini.aiservices; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
@Path("gemini/") | ||
public class GeminiResource { | ||
|
||
@POST | ||
@Path("v1/projects/my_google_project_id/locations/west-europe/publishers/google/models/gemini-pro:generateContent") | ||
@Produces("application/json") | ||
public String get() { | ||
return """ | ||
{ | ||
"candidates": [ | ||
{ | ||
"content": { | ||
"role": "model", | ||
"parts": [ | ||
{ | ||
"text": "Nice to meet you" | ||
} | ||
] | ||
}, | ||
"finishReason": "STOP", | ||
"safetyRatings": [ | ||
{ | ||
"category": "HARM_CATEGORY_HATE_SPEECH", | ||
"probability": "NEGLIGIBLE", | ||
"probabilityScore": 0.044847902, | ||
"severity": "HARM_SEVERITY_NEGLIGIBLE", | ||
"severityScore": 0.05592617 | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_DANGEROUS_CONTENT", | ||
"probability": "NEGLIGIBLE", | ||
"probabilityScore": 0.18877223, | ||
"severity": "HARM_SEVERITY_NEGLIGIBLE", | ||
"severityScore": 0.027324531 | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_HARASSMENT", | ||
"probability": "NEGLIGIBLE", | ||
"probabilityScore": 0.15278918, | ||
"severity": "HARM_SEVERITY_NEGLIGIBLE", | ||
"severityScore": 0.045437217 | ||
}, | ||
{ | ||
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", | ||
"probability": "NEGLIGIBLE", | ||
"probabilityScore": 0.15869519, | ||
"severity": "HARM_SEVERITY_NEGLIGIBLE", | ||
"severityScore": 0.036838707 | ||
} | ||
] | ||
} | ||
], | ||
"usageMetadata": { | ||
"promptTokenCount": 11, | ||
"candidatesTokenCount": 37, | ||
"totalTokenCount": 48 | ||
} | ||
} | ||
"""; | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
integration-tests/vertex-ai-gemini/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
quarkus.langchain4j.vertexai.gemini.base-url=http://localhost:8081/gemini | ||
quarkus.langchain4j.vertexai.gemini.location=west-europe | ||
quarkus.langchain4j.vertexai.gemini.project-id=my_google_project_id | ||
quarkus.langchain4j.vertexai.gemini.log-requests=true | ||
quarkus.langchain4j.vertexai.gemini.log-responses=true |
31 changes: 31 additions & 0 deletions
31
...mini/src/test/java/org/acme/example/gemini/aiservices/AssistantResourceWithToolsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.acme.example.gemini.aiservices; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
import java.net.URL; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class AssistantResourceWithToolsTest { | ||
|
||
@TestHTTPEndpoint(AssistantWithToolsResource.class) | ||
@TestHTTPResource | ||
URL url; | ||
|
||
@Test | ||
public void get() { | ||
given() | ||
.baseUri(url.toString()) | ||
.queryParam("message", "This is a test") | ||
.get() | ||
.then() | ||
.statusCode(200) | ||
.body(equalTo("Nice to meet you; tool1: Nice to meet you")); | ||
Check failure on line 29 in integration-tests/vertex-ai-gemini/src/test/java/org/acme/example/gemini/aiservices/AssistantResourceWithToolsTest.java quarkus-bot / Build summary for 5987cb81f406163784d3e508c3fc8bdd622853d2JVM tests - integration-tests - Java 17
Raw output
Check failure on line 29 in integration-tests/vertex-ai-gemini/src/test/java/org/acme/example/gemini/aiservices/AssistantResourceWithToolsTest.java quarkus-bot / Build summary for 5987cb81f406163784d3e508c3fc8bdd622853d2JVM tests - integration-tests - Java 21
Raw output
Check failure on line 29 in integration-tests/vertex-ai-gemini/src/test/java/org/acme/example/gemini/aiservices/AssistantResourceWithToolsTest.java quarkus-bot / Build summary for 5987cb81f406163784d3e508c3fc8bdd622853d2JVM tests - integration-tests - Java 23
Raw output
|
||
} | ||
} |
Oops, something went wrong.