forked from langchain4j/langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gemini updates: * update to latest Java SDK version * langchain4j#1269 * langchain4j#1270 * langchain4j#1208 * langchain4j#1399 * langchain4j#1397 * langchain4j#1182 * langchain4j#828 * fixes parallel function calling which wasn't working properly in the previous release * refactored a bit the `generate()` method to have a single entry point and less duplication Vertex AI embedding model: * add new task types (question answering and fact verification) Imagen image model: * support more configuration parameters * langchain4j#1367
- Loading branch information
Showing
21 changed files
with
1,741 additions
and
106 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
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
13 changes: 13 additions & 0 deletions
13
langchain4j-vertex-ai-gemini/src/main/java/dev/langchain4j/model/vertexai/HarmCategory.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,13 @@ | ||
package dev.langchain4j.model.vertexai; | ||
|
||
/** | ||
* Possible harm categories for the generation of responses that have been blocked by the model. | ||
*/ | ||
public enum HarmCategory { | ||
HARM_CATEGORY_UNSPECIFIED, | ||
HARM_CATEGORY_HATE_SPEECH, | ||
HARM_CATEGORY_DANGEROUS_CONTENT, | ||
HARM_CATEGORY_HARASSMENT, | ||
HARM_CATEGORY_SEXUALLY_EXPLICIT, | ||
UNRECOGNIZED | ||
} |
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
35 changes: 35 additions & 0 deletions
35
...in4j-vertex-ai-gemini/src/main/java/dev/langchain4j/model/vertexai/ResponseGrounding.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,35 @@ | ||
package dev.langchain4j.model.vertexai; | ||
|
||
import com.google.cloud.vertexai.api.GoogleSearchRetrieval; | ||
import com.google.cloud.vertexai.api.Retrieval; | ||
import com.google.cloud.vertexai.api.Tool; | ||
import com.google.cloud.vertexai.api.VertexAISearch; | ||
|
||
/** | ||
* Ground Gemini responses with Google Search web results | ||
* or with Vertex AI Search datastores | ||
*/ | ||
class ResponseGrounding { | ||
|
||
static Tool googleSearchTool() { | ||
return Tool.newBuilder() | ||
.setGoogleSearchRetrieval( | ||
GoogleSearchRetrieval.newBuilder() | ||
// .setDisableAttribution(false) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* @param datastore fully qualified name of the Vertex Search datastore, with the following format | ||
* "projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATASTORE_NAME" | ||
*/ | ||
static Tool vertexAiSearch(String datastore) { | ||
return Tool.newBuilder() | ||
.setRetrieval( | ||
Retrieval.newBuilder() | ||
.setVertexAiSearch(VertexAISearch.newBuilder().setDatastore(datastore)) | ||
.setDisableAttribution(false)) | ||
.build(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...j-vertex-ai-gemini/src/main/java/dev/langchain4j/model/vertexai/SafetySettingsMapper.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,34 @@ | ||
package dev.langchain4j.model.vertexai; | ||
|
||
import com.google.cloud.vertexai.api.HarmCategory; | ||
import com.google.cloud.vertexai.api.SafetySetting.HarmBlockThreshold; | ||
import com.google.cloud.vertexai.api.SafetySetting; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Maps between Vertex AI <code>SafetSetting</code> and LangChain4j | ||
* <code>HarmCategoty</code> and <code>SafetyThreshold</code> | ||
*/ | ||
class SafetySettingsMapper { | ||
static List<SafetySetting> mapSafetySettings(Map<dev.langchain4j.model.vertexai.HarmCategory, SafetyThreshold> safetySettingsMap) { | ||
return safetySettingsMap.entrySet().stream() | ||
.map(entry -> { | ||
SafetySetting.Builder safetySettingBuilder = SafetySetting.newBuilder(); | ||
safetySettingBuilder.setCategory(map(entry.getKey())); | ||
safetySettingBuilder.setThreshold(map(entry.getValue())); | ||
return safetySettingBuilder.build(); | ||
}) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private static HarmCategory map(dev.langchain4j.model.vertexai.HarmCategory harmCategory) { | ||
return HarmCategory.valueOf(harmCategory.name()); | ||
} | ||
|
||
private static HarmBlockThreshold map(SafetyThreshold safetyThreshold) { | ||
return HarmBlockThreshold.valueOf(safetyThreshold.name()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...hain4j-vertex-ai-gemini/src/main/java/dev/langchain4j/model/vertexai/SafetyThreshold.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,13 @@ | ||
package dev.langchain4j.model.vertexai; | ||
|
||
/** | ||
* Safety thresholds, for the harm categories for the generation of responses that have been blocked by the model. | ||
*/ | ||
public enum SafetyThreshold { | ||
HARM_BLOCK_THRESHOLD_UNSPECIFIED, | ||
BLOCK_LOW_AND_ABOVE, | ||
BLOCK_MEDIUM_AND_ABOVE, | ||
BLOCK_ONLY_HIGH, | ||
BLOCK_NONE, | ||
UNRECOGNIZED | ||
} |
Oops, something went wrong.