feat(ai): Chat history and auto function calling for server templates#9763
feat(ai): Chat history and auto function calling for server templates#9763
Conversation
🦋 Changeset detectedLatest commit: a0b3839 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the AI SDK by introducing robust chat history management and automatic function calling capabilities specifically for server-side templates. By refactoring core chat logic into a shared base class and providing a dedicated Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces TemplateChatSession and ChatSessionBase to enable template-based chat functionality and centralize common chat session logic. The TemplateGenerativeModel now supports starting a chat session via startChat(). The ChatSession class has been refactored to extend ChatSessionBase. New types like StartTemplateChatParams and TemplateGenerateContentRequest are added to support this feature, and a typo in maxSequentalFunctionCalls was corrected to maxSequentialFunctionCalls. Review feedback highlights a potential TypeError crash in ChatSessionBase when handling response.candidates[0].content if it's null or undefined. Additionally, ChatSessionBase should be exported for better extensibility, and public interfaces like StartTemplateChatParams and TemplateGenerateContentRequest require TSDoc comments for their properties. The _formatRequest method in TemplateChatSession can be made more type-safe, and the [key: string]: unknown; index signature in TemplateGenerateContentRequest should be reconsidered for a more type-safe approach.
| }, | ||
| { | ||
| maxSequentalFunctionCalls: 0 | ||
| maxSequentialFunctionCalls: 0 |
|
|
||
| | Method | Modifiers | Description | | ||
| | --- | --- | --- | | ||
| | [getHistory()](./ai.chatsession.md#chatsessiongethistory) | | Gets the chat history so far. Blocked prompts are not added to history. Neither blocked candidates nor the prompts that generated them are added to history. | |
There was a problem hiding this comment.
Are there any changes that a dev needs to do within their code for regular chat (like non-server prompt template chat) to accommodate this change?
There was a problem hiding this comment.
This is a result of doing something that makes the code work better and makes the documentation messier - making ChatSession and TemplateChatSession extend a base class, ChatSessionBase, in order to avoid duplicate code. Unfortunately that means a method shared by both extended classes (getHistory) is only going to be found by clicking through to ChatSessionBase, which is linked above.
There was a problem hiding this comment.
But no changes for the developer in their actual source code for their app, right?
There was a problem hiding this comment.
Nope, just harder to read the documentation.
| {% endcomment %} | ||
|
|
||
| # ChatSessionBase class | ||
| Base class for ChatSession that enables sending chat messages and stores history of sent and received messages so far. |
There was a problem hiding this comment.
nit - ChatSession should be tagged as code
There was a problem hiding this comment.
Done, also rewrote to reflect this is a base class for multiple ChatSession variants and not just literally ChatSession (it's only two right now but it could be more in the future).
Based on initial work in #9742
API design doc (internal): https://docs.google.com/document/d/1ecqEdvMMkx1QSInhPVmqF9yOXSJaCgGlnxOc9GshcEY/edit?resourcekey=0-t1kgF5b2FKpRexQGQVc58Q&tab=t.qqsqzzhfm8vt
TemplateChatSession.ChatSessionto aChatSessionBaseabstract class and allowedChatSessionandTemplateChatSessionto extend it and add a few methods and types specific to their use cases.