-
Notifications
You must be signed in to change notification settings - Fork 5
Gemini #100
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
Draft
jtpio
wants to merge
8
commits into
jupyterlite:main
Choose a base branch
from
jtpio:gemini
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Gemini #100
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4f5dfcc
Gemini
jtpio 710c834
fix typo
jtpio ffefa0e
lint
jtpio 3a6d3d3
remove skipLibCheck
jtpio 88e19e1
fix typo
jtpio 60298fe
Fix mistralAI completer
jtpio e2831c3
fix TS build
jtpio 04b3ecc
lint
jtpio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
CompletionHandler, | ||
IInlineCompletionContext | ||
} from '@jupyterlab/completer'; | ||
import { ChatGoogleGenerativeAI } from '@langchain/google-genai'; | ||
import { AIMessage, SystemMessage } from '@langchain/core/messages'; | ||
|
||
import { BaseCompleter } from '../../base-completer'; | ||
|
||
export class GeminiCompleter extends BaseCompleter { | ||
constructor(options: BaseCompleter.IOptions) { | ||
super(options); | ||
this._completer = new ChatGoogleGenerativeAI({ | ||
model: 'gemini-pro', | ||
...options.settings | ||
}); | ||
} | ||
|
||
async fetch( | ||
request: CompletionHandler.IRequest, | ||
context: IInlineCompletionContext | ||
) { | ||
const { text, offset: cursorOffset } = request; | ||
const prompt = text.slice(0, cursorOffset); | ||
|
||
const trimmedPrompt = prompt.trim(); | ||
|
||
const messages = [ | ||
new SystemMessage(this.systemPrompt), | ||
new AIMessage(trimmedPrompt) | ||
]; | ||
|
||
try { | ||
const response = await this._completer.invoke(messages); | ||
const items = []; | ||
|
||
// Gemini can return string or complex content, a list of string/images/other. | ||
if (typeof response.content === 'string') { | ||
items.push({ | ||
insertText: response.content | ||
}); | ||
} else { | ||
response.content.forEach(content => { | ||
if (content.type !== 'text') { | ||
return; | ||
} | ||
items.push({ | ||
insertText: content.text, | ||
filterText: prompt.substring(trimmedPrompt.length) | ||
}); | ||
}); | ||
} | ||
return { items }; | ||
} catch (error) { | ||
console.error('Error fetching completions', error); | ||
return { items: [] }; | ||
} | ||
} | ||
|
||
protected _completer: ChatGoogleGenerativeAI; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default ` | ||
<i class="fas fa-exclamation-triangle"></i> This extension is still very much experimental. It is not an official Google extension. | ||
|
||
1. Go to <https://aistudio.google.com> and create an API key. | ||
|
||
2. Open the JupyterLab settings and go to the **Ai providers** section to select the \`Gemini\` | ||
provider and add your API key (required). | ||
3. Open the chat, or use the inline completer. | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"temperature": { | ||
"type": "number", | ||
"description": "Amount of randomness injected into the response. Ranges from 0 to 1. Use temp closer to 0 for analytical / multiple choice, and temp closer to 1 for creative and generative tasks." | ||
}, | ||
"topK": { | ||
"type": "number", | ||
"description": "Only sample from the top K options for each subsequent token. Used to remove \"long tail\" low probability responses." | ||
}, | ||
"topP": { | ||
"type": "number", | ||
"description": "Nucleus sampling parameter. Only the smallest set of most probable tokens with probabilities that add up to top_p or higher are kept for generation." | ||
}, | ||
"maxOutputTokens": { | ||
"type": "number", | ||
"description": "The maximum number of tokens to generate in the response." | ||
}, | ||
"stopSequences": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
}, | ||
"description": "A list of strings upon which to stop generating. You probably want something like [\"\\n\\nHuman:\"] for chat conversations." | ||
}, | ||
"streaming": { | ||
"type": "boolean", | ||
"description": "Whether to stream the results or not" | ||
}, | ||
"apiKey": { | ||
"type": "string", | ||
"description": "Google AI Studio API key" | ||
}, | ||
"model": { | ||
"type": "string", | ||
"description": "Model name to use (e.g., gemini-pro, gemini-2.0-flash, etc.)", | ||
"default": "gemini-pro" | ||
}, | ||
"baseURL": { | ||
"type": "string", | ||
"description": "Base URL for the Google AI API" | ||
}, | ||
"safetySettings": { | ||
"type": "array", | ||
"description": "Safety settings for content filtering", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"category": { | ||
"type": "string" | ||
}, | ||
"threshold": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"description": "Input to Google Generative AI Chat class.", | ||
"definitions": {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 latest version of
@langchain/google-genai
seems to depend on newer releases of@langchain/core
, so bumping the other langchain dependencies here.