google / generative-ai-docs

Documentation for Google's Gen AI site - including the Gemini API and Gemma
https://ai.google.dev
Apache License 2.0
1.46k stars 494 forks source link

fix: documentation error #447

Open MohammedAbidNafi opened 4 weeks ago

MohammedAbidNafi commented 4 weeks ago

Description of the bug:

The documentation has the following error:

// The Gemini 1.5 models are versatile and work with multi-turn conversations (like chat)
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

// (optional) Create previous chat history for context
Content.Builder userContentBuilder = new Content.Builder();
userContentBuilder.setRole("user");
userContentBuilder.addText("Hello, I have 2 dogs in my house.");
Content userContent = userContentBuilder.build();

Content.Builder modelContentBuilder = new Content.Builder();
modelContentBuilder.setRole("model");
modelContentBuilder.addText("Great to meet you. What would you like to know?");
Content modelContent = userContentBuilder.build(); // Here it should be modelContentBuilder where its again accessing userContentBuilder 

List<Content> history = Arrays.asList(userContent, modelContent);

// Initialize the chat
ChatFutures chat = model.startChat(history);

// Create a new user message
Content userMessage = new Content.Builder()
    .setRole("user")
    .addText("How many paws are in my house?")
    .build();

Executor executor = // ...

// Send the message
ListenableFuture<GenerateContentResponse> response = chat.sendMessage(userMessage);

Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
    @Override
    public void onSuccess(GenerateContentResponse result) {
        String resultText = result.getText();
        System.out.println(resultText);
    }

    @Override
    public void onFailure(Throwable t) {
        t.printStackTrace();
    }
}, executor);

Actual vs expected behavior:

The issue is that in modelContentBuilder at the end its again building to userContentBuilder where as it should be modelContentBuilder

Any other information you'd like to share?

No response

singhniraj08 commented 3 weeks ago

@MohammedAbidNafi, Thank you for reporting this issue. Can you please provide the source documentation link for us to fix the bug. Also, if you are interested in contributing, feel free to create a PR for the same.

MohammedAbidNafi commented 3 weeks ago

https://ai.google.dev/gemini-api/docs/get-started/tutorial?lang=android#java_5 here is the link to documentation.

Sure I would love to contribute in this

github-actions[bot] commented 1 week ago

Marking this issue as stale since it has been open for 14 days with no activity. This issue will be closed if no further activity occurs.