GoogleCloudPlatform / java-docs-samples

Java and Kotlin Code samples used on cloud.google.com
https://cloud.google.com/java
Apache License 2.0
1.74k stars 2.82k forks source link

fix: Update GetTokenCount.java #9334

Closed davenportjw closed 1 month ago

davenportjw commented 2 months ago

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

snippet-bot[bot] commented 2 months ago

Here is the summary of changes.

You are about to add 2 region tags. - [vertexai/snippets/src/main/java/vertexai/gemini/GetTokenCount.java:20](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/21834dc21ef3e006f20362d35f03f0ee375c2953/vertexai/snippets/src/main/java/vertexai/gemini/GetTokenCount.java#L20), tag `generativeaionvertexai_gemini_token_count` - [vertexai/snippets/src/main/java/vertexai/gemini/GetTokenCount.java:40](https://github.com/GoogleCloudPlatform/java-docs-samples/blob/21834dc21ef3e006f20362d35f03f0ee375c2953/vertexai/snippets/src/main/java/vertexai/gemini/GetTokenCount.java#L40), tag `generativeaionvertexai_gemini_token_count`

This comment is generated by snippet-bot. If you find problems with this result, please file an issue at: https://github.com/googleapis/repo-automation-bots/issues. To update this comment, add snippet-bot:force-run label or use the checkbox below:

iennae commented 2 months ago

@davenportjw any idea why change in model name might cause the error

tmpfs/docker/overlay2/85ba26e363cfea28217e7dc8e3c0363a0d8f95a8c884410d2f380c5b415db5f2/merged/sys/fs/cgroup/cpuset. [ERROR] Tests run: 21, Failures: 0, Errors: 3, Skipped: 1, Time elapsed: 1,210.961 s <<< FAILURE! - in vertexai.gemini.SnippetsIT [ERROR] vertexai.gemini.SnippetsIT.testMultimodalQuery Time elapsed: 591.885 s <<< ERROR! java.lang.IllegalArgumentException: The response is blocked due to unauthorized citations.

minherz commented 2 months ago

@davenportjw any idea why change in model name might cause the error

It looks like you need to revise the input or to adjust the safety settings by updating the model with:

  SafetySetting safetySettings = SafetySetting.newBuilder()
         .setThreshold(SafetySetting.HarmBlockThreshold.BLOCK_NONE)
         .build();
  GenerativeModel model = new GenerativeModel(modelName, vertexAI)
         .withSafetySettings(safetySettings);
gericdong commented 1 month ago

@davenportjw @iennae @minherz: GetTokenCount.java has been updated along with other files in another PR (https://github.com/GoogleCloudPlatform/java-docs-samples/pull/9356). We can close this PR. Please let me know if you have any questions.. Thank you!

minherz commented 1 month ago

No questions