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 canonical samples for chat, caching, embeds, and code execution #205

Merged
merged 7 commits into from
Jul 11, 2024

Conversation

hsubox76
Copy link
Collaborator

@hsubox76 hsubox76 commented Jul 10, 2024

Finish required samples (internal link: https://docs.google.com/spreadsheets/d/10X--DI0YPL3QfEMObe387rYg0t4-kuv33yKn2TIal7E/edit?resourcekey=0-kfy1Ry4YAZh6O4DltLjV9w&gid=0#gid=0)

file region tag
chat chat
chat chat_streaming
chat chat_streaming_with_images
cache cache_create
cache cache_create_from_name
cache cache_create_from_chat
cache cache_delete
cache cache_get
cache cache_list
cache cache_update
embed embed_content
embed batch_embed_contents
code_execution code_execution_basic
code_execution code_execution_request_override
code_execution code_execution_chat

Mostly trying to conform to Python: https://github.com/google-gemini/generative-ai-python/tree/main/samples

Also updated text_generation.js to use more convenient ways to display streaming and non streaming responses (reduce lines, write streaming to process.stdout to prevent line breaks).

Next PR is to add a script to add comments to each sample explaining what import lines (e.g., import { GoogleGenerativeAI } from '@google/generative-ai') will need to be added, since we cannot otherwise include import lines in the samples.

@hsubox76 hsubox76 marked this pull request as ready for review July 10, 2024 22:35
@hsubox76 hsubox76 requested a review from dlarocque July 10, 2024 22:40
@hsubox76 hsubox76 changed the title Ch samples chat cache Add canonical samples for chat, caching, embeds, and code execution Jul 10, 2024
Comment on lines +173 to +174
await cacheManager.delete(cacheResult.name);
// [END cache_delete]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The other samples in this file END the sample before deleting the cached content. Do we want to do this here, too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, because this is the delete sample, so we want to show it in the sample.

samples/node/text_generation.js Show resolved Hide resolved
@hsubox76 hsubox76 merged commit 23f5fdb into main Jul 11, 2024
8 checks passed
@hsubox76 hsubox76 deleted the ch-samples-chat-cache branch July 11, 2024 17:05
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.

2 participants