-
Notifications
You must be signed in to change notification settings - Fork 0
badrock integration #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||
| import * as vscode from 'vscode'; | ||||||||||||||
| import { CopilotModel } from './models/copilot'; | ||||||||||||||
| import { BedrockModel } from './models/bedrock'; | ||||||||||||||
|
|
||||||||||||||
| export type MessageType = { | ||||||||||||||
| role: 'user' | 'assistant' | 'system'; | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| export interface Model { | ||||||||||||||
| sendMessage: (message: string, messageType: MessageType) => Promise<string>; | ||||||||||||||
| init: () => Promise<void>; | ||||||||||||||
| type: string; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| export async function getModel(token: vscode.CancellationToken): Promise<Model> { | ||||||||||||||
| const bedrockModel = vscode.workspace.getConfiguration('netapp-fsx-ontap').get('bedrockmodel',""); | ||||||||||||||
| if (bedrockModel) { | ||||||||||||||
| const model = new BedrockModel(bedrockModel as string); | ||||||||||||||
|
Comment on lines
+19
to
+21
|
||||||||||||||
| const bedrockModel = vscode.workspace.getConfiguration('netapp-fsx-ontap').get('bedrockmodel',""); | |
| if (bedrockModel) { | |
| const model = new BedrockModel(bedrockModel as string); | |
| const bedrockModel = vscode.workspace.getConfiguration('netapp-fsx-ontap').get<string>('bedrockmodel', undefined); | |
| if (typeof bedrockModel === 'string' && bedrockModel.trim() !== "") { | |
| const model = new BedrockModel(bedrockModel); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||
| import { BedrockRuntimeClient, ConversationRole, ConverseCommand } from "@aws-sdk/client-bedrock-runtime"; | ||||||||||||||
| import { MessageType, Model } from "../modelFactory"; | ||||||||||||||
| import * as vscode from 'vscode'; | ||||||||||||||
| import { state } from "../../state"; | ||||||||||||||
|
|
||||||||||||||
| export class BedrockModel implements Model { | ||||||||||||||
| type: string = "bedrock"; | ||||||||||||||
| client: BedrockRuntimeClient | null = null; | ||||||||||||||
| temperature = 0.7; | ||||||||||||||
| maxTokens = 4096; | ||||||||||||||
|
|
||||||||||||||
| constructor(private modelName: string) {} | ||||||||||||||
|
|
||||||||||||||
| async init(): Promise<void> { | ||||||||||||||
| const bedrockRegion = vscode.workspace.getConfiguration('netapp-fsx-ontap').get('bedrockregion',"us-east-1"); | ||||||||||||||
| try { | ||||||||||||||
| this.client = new BedrockRuntimeClient({ | ||||||||||||||
| region: bedrockRegion as string, | ||||||||||||||
| profile: state.currentProfile | ||||||||||||||
| }); | ||||||||||||||
| console.log(`Initialized Bedrock client for model: ${this.modelName} in region: ${bedrockRegion}`); | ||||||||||||||
| } catch (error) { | ||||||||||||||
| console.error("Failed to initialize Bedrock client:", error); | ||||||||||||||
| throw error; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| async sendMessage(message: string, messageType: MessageType): Promise<string> { | ||||||||||||||
| const content = [{ | ||||||||||||||
| role: ConversationRole.USER, | ||||||||||||||
|
Comment on lines
+30
to
+31
|
||||||||||||||
| const content = [{ | |
| role: ConversationRole.USER, | |
| // Map MessageType to ConversationRole | |
| const role = messageType === "user" ? ConversationRole.USER : ConversationRole.ASSISTANT; | |
| const content = [{ | |
| role: role, |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||
| import * as vscode from 'vscode'; | ||||||||||||||||||||
| import { MessageType, Model } from "../modelFactory"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| export class CopilotModel implements Model { | ||||||||||||||||||||
| type: string = "copilot"; | ||||||||||||||||||||
| chatModel: vscode.LanguageModelChat | null = null; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| constructor(private token: vscode.CancellationToken) {} | ||||||||||||||||||||
|
|
||||||||||||||||||||
| async getWorkingLanguageModel(): Promise<vscode.LanguageModelChat | null> { | ||||||||||||||||||||
| const chatModels = await vscode.lm.selectChatModels(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| for (const model of chatModels) { | ||||||||||||||||||||
| try { | ||||||||||||||||||||
| // Test the model with a simple request | ||||||||||||||||||||
| const testMessage = vscode.LanguageModelChatMessage.Assistant('Hello'); | ||||||||||||||||||||
| await model.sendRequest([testMessage], {}, new vscode.CancellationTokenSource().token); | ||||||||||||||||||||
| return model; | ||||||||||||||||||||
|
Comment on lines
+18
to
+19
|
||||||||||||||||||||
| await model.sendRequest([testMessage], {}, new vscode.CancellationTokenSource().token); | |
| return model; | |
| const cts = new vscode.CancellationTokenSource(); | |
| try { | |
| await model.sendRequest([testMessage], {}, cts.token); | |
| return model; | |
| } finally { | |
| cts.dispose(); | |
| } |
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 secrets.get call is made inside a map operation for each filesystem, resulting in N sequential async calls. Consider batching these secret retrievals or caching them to improve performance when rendering many filesystems.