Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add samples for log prob and search grounding #273

Merged
merged 5 commits into from
Oct 7, 2024
Merged

Add samples for log prob and search grounding #273

merged 5 commits into from
Oct 7, 2024

Conversation

junyanxu
Copy link
Collaborator

@junyanxu junyanxu commented Oct 4, 2024

Please help review new samples.

@junyanxu junyanxu requested a review from pcoet October 4, 2024 00:39
* limitations under the License.
*/

import {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd leave these imports on a single line, unless they get longer than 80 characters. That's what I usually see in JS.

},
},
);
const prompt =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need to split this across two lines.

);

const prompt =
"What is the Google stock today?";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"What is the Google stock today?" -> "What is the price of Google stock today?"

"What is the Google stock today?";

const result = await model.generateContent(prompt);
console.log(JSON.stringify(result.response));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to use JSON.stringify here. Just console.log(result.response);

@junyanxu
Copy link
Collaborator Author

junyanxu commented Oct 4, 2024

Fixed

Copy link
Collaborator

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) does this match the samples being done for Python and other languages? When we first added samples to the repo, I was given the impression it was really important that all the samples match across languages as much as possible - especially the includecode region tags. Also the content of the prompts, etc.

(2) Have you run these samples against the live backend, do they give the expected output?

samples/search_grouding.js Outdated Show resolved Hide resolved
samples/log_prob.js Outdated Show resolved Hide resolved

async function enableLogProb() {
// [START log probability]
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For devsite snippets we add a comment like this about what imports the user will need, since the import at the top of the file will not be included in the includecode snippet: https://github.com/google-gemini/generative-ai-js/blob/add-samples/samples/text_generation.js#L43-L44

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this is resolved, but I don't see the comment added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

samples/log_prob.js Outdated Show resolved Hide resolved
samples/search_grouding.js Outdated Show resolved Hide resolved
samples/search_grouding.js Outdated Show resolved Hide resolved
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
const model = genAI.getGenerativeModel(
{
model: "gemini-1.5-pro",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for choosing different models for each sample?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the two models are now flash and flash-002, is there a reason they are different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the logprob is only supported for 002 model. A bit background: Labs are calling vertex for all 002 models. And logprob is a feature only supported by vertex for now.

samples/search_grouding.js Outdated Show resolved Hide resolved
@junyanxu
Copy link
Collaborator Author

junyanxu commented Oct 4, 2024

(1) does this match the samples being done for Python and other languages? When we first added samples to the repo, I was given the impression it was really important that all the samples match across languages as much as possible - especially the includecode region tags. Also the content of the prompts, etc.

(2) Have you run these samples against the live backend, do they give the expected output?

(1) I don't see python has example of search grounding or log probs.
(2) Yeah I have tested and run locally.

@junyanxu junyanxu requested a review from hsubox76 October 4, 2024 19:40
@junyanxu junyanxu requested a review from pcoet October 7, 2024 16:08
@junyanxu
Copy link
Collaborator Author

junyanxu commented Oct 7, 2024

Add import comment to new samples.

@junyanxu junyanxu merged commit bb553d0 into main Oct 7, 2024
7 of 9 checks passed
@junyanxu junyanxu deleted the add-samples branch October 7, 2024 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants