-
Notifications
You must be signed in to change notification settings - Fork 7
Structured output #75
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary of ChangesHello @whereisfarukk, 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 expands the capabilities of the VlmRun node by introducing a robust 'Chat Completion' feature. This enhancement allows users to leverage advanced conversational AI, supporting diverse input types like text, images, videos, and files, and providing precise control over output formatting through JSON schemas. The changes aim to broaden the node's utility for complex, multi-modal AI workflows. Highlights
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. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a 'Chat Completion' operation, enabling structured output capabilities. The implementation is comprehensive, adding new types, API service methods, and node properties. My review focuses on improving code quality by addressing code duplication, strengthening validation, and removing debug statements that could leak information. Overall, this is a great feature addition.
| // Process image URLs | ||
| const imageUrls: string[] = []; | ||
| if (inputType === 'image') { | ||
| const imageUrlsParam = this.getNodeParameter('imageUrls', i) as IDataObject; | ||
| if (imageUrlsParam && imageUrlsParam.url) { | ||
| const urlEntries = Array.isArray(imageUrlsParam.url) ? imageUrlsParam.url : [imageUrlsParam.url]; | ||
| for (const entry of urlEntries) { | ||
| if (entry && typeof entry === 'object' && entry.url) { | ||
| const url = entry.url as string; | ||
| if (url && url.trim()) { | ||
| imageUrls.push(url.trim()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Process video URLs | ||
| const videoUrls: string[] = []; | ||
| if (inputType === 'video') { | ||
| const videoUrlsParam = this.getNodeParameter('videoUrls', i) as IDataObject; | ||
| if (videoUrlsParam && videoUrlsParam.url) { | ||
| const urlEntries = Array.isArray(videoUrlsParam.url) ? videoUrlsParam.url : [videoUrlsParam.url]; | ||
| for (const entry of urlEntries) { | ||
| if (entry && typeof entry === 'object' && entry.url) { | ||
| const url = entry.url as string; | ||
| if (url && url.trim()) { | ||
| videoUrls.push(url.trim()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Process file URLs | ||
| const fileUrls: string[] = []; | ||
| if (inputType === 'file') { | ||
| const fileUrlsParam = this.getNodeParameter('fileUrls', i) as IDataObject; | ||
| if (fileUrlsParam && fileUrlsParam.url) { | ||
| const urlEntries = Array.isArray(fileUrlsParam.url) ? fileUrlsParam.url : [fileUrlsParam.url]; | ||
| for (const entry of urlEntries) { | ||
| if (entry && typeof entry === 'object' && entry.url) { | ||
| const url = entry.url as string; | ||
| if (url && url.trim()) { | ||
| fileUrls.push(url.trim()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for processing URLs from imageUrls, videoUrls, and fileUrls parameters is duplicated. To improve code maintainability and reduce redundancy, this logic can be extracted into a helper function.
const getUrlsFromParam = (paramName: string): string[] => {
const urls: string[] = [];
const param = this.getNodeParameter(paramName, i) as IDataObject;
if (param && param.url) {
const urlEntries = Array.isArray(param.url) ? param.url : [param.url];
for (const entry of urlEntries) {
if (entry && typeof entry === 'object' && entry.url) {
const url = entry.url as string;
if (url && url.trim()) {
urls.push(url.trim());
}
}
}
}
return urls;
};
// Process URLs
const imageUrls: string[] = inputType === 'image' ? getUrlsFromParam('imageUrls') : [];
const videoUrls: string[] = inputType === 'video' ? getUrlsFromParam('videoUrls') : [];
const fileUrls: string[] = inputType === 'file' ? getUrlsFromParam('fileUrls') : [];| if (!message.content) { | ||
| throw new NodeOperationError( | ||
| this.getNode(), | ||
| 'Text message content cannot be empty.', | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| response = await ApiService.chatCompletion(this, messages, model, undefined, responseFormat); | ||
|
|
||
| console.log(JSON.stringify(response, null, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.