Skip to content

Commit

Permalink
Merge pull request voideditor#273 from voideditor/model-selection
Browse files Browse the repository at this point in the history
UI improvements
  • Loading branch information
andrewpareles authored Feb 6, 2025
2 parents e3941d5 + 9025886 commit 5fa21be
Show file tree
Hide file tree
Showing 30 changed files with 1,265 additions and 687 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ product.overrides.json
*.snap.actual
.vscode-test
.tmp/
.tmp2/
.tool-versions
7 changes: 7 additions & 0 deletions remote/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/vs/platform/void/common/llmMessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { createDecorator } from '../../instantiation/common/instantiation.js';
import { Event } from '../../../base/common/event.js';
import { Disposable } from '../../../base/common/lifecycle.js';
import { IVoidSettingsService } from './voidSettingsService.js';
import { displayInfoOfProviderName, isFeatureNameDisabled } from './voidSettingsTypes.js';
// import { INotificationService } from '../../notification/common/notification.js';

// calls channel to implement features
Expand Down Expand Up @@ -90,10 +91,24 @@ export class LLMMessageService extends Disposable implements ILLMMessageService
const { onText, onFinalMessage, onError, ...proxyParams } = params;
const { useProviderFor: featureName } = proxyParams

// end early if no provider
// throw an error if no model/provider selected (this should usually never be reached, the UI should check this first, but might happen in cases like Apply where we haven't built much UI/checks yet, good practice to have check logic on backend)
const isDisabled = isFeatureNameDisabled(featureName, this.voidSettingsService.state)
const modelSelection = this.voidSettingsService.state.modelSelectionOfFeature[featureName]
if (modelSelection === null) {
onError({ message: 'Please add a Provider in Settings!', fullError: null })
if (isDisabled || modelSelection === null) {
let message: string

if (isDisabled === 'addProvider' || isDisabled === 'providerNotAutoDetected')
message = `Please add a provider in Void Settings.`
else if (isDisabled === 'addModel')
message = `Please add a model.`
else if (isDisabled === 'needToEnableModel')
message = `Please enable a model.`
else if (isDisabled === 'notFilledIn')
message = `Please fill in Void Settings${modelSelection !== null ? ` for ${displayInfoOfProviderName(modelSelection.providerName).title}` : ''}.`
else
message = 'Please add a provider in Void Settings.'

onError({ message, fullError: null })
return null
}

Expand Down
27 changes: 14 additions & 13 deletions src/vs/platform/void/common/llmMessageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* Licensed under the Apache License, Version 2.0. See LICENSE.txt for more information.
*--------------------------------------------------------------------------------------*/

import { ProviderName, SettingsOfProvider } from './voidSettingsTypes.js'
import { FeatureName, ProviderName, SettingsOfProvider } from './voidSettingsTypes.js'


export const errorDetails = (fullError: Error | null): string | null => {
if (fullError === null) {
return null
}
else if (typeof fullError === 'object') {
if (Object.keys(fullError).length === 0) return null
return JSON.stringify(fullError, null, 2)
}
else if (typeof fullError === 'string') {
Expand All @@ -24,28 +25,28 @@ export type OnFinalMessage = (p: { fullText: string }) => void
export type OnError = (p: { message: string, fullError: Error | null }) => void
export type AbortRef = { current: (() => void) | null }

export type LLMMessage = {
export type LLMChatMessage = {
role: 'system' | 'user' | 'assistant';
content: string;
}

export type _InternalLLMMessage = {
export type _InternalLLMChatMessage = {
role: 'user' | 'assistant';
content: string;
}

type _InternalOllamaFIMMessages = {
type _InternalSendFIMMessage = {
prefix: string;
suffix: string;
stopTokens: string[];
}

type SendLLMType = {
type: 'sendLLMMessage';
messages: LLMMessage[];
messagesType: 'chatMessages';
messages: LLMChatMessage[];
} | {
type: 'ollamaFIM';
messages: _InternalOllamaFIMMessages;
messagesType: 'FIMMessage';
messages: _InternalSendFIMMessage;
}

// service types
Expand All @@ -54,7 +55,7 @@ export type ServiceSendLLMMessageParams = {
onFinalMessage: OnFinalMessage;
onError: OnError;
logging: { loggingName: string, };
useProviderFor: 'Ctrl+K' | 'Ctrl+L' | 'Autocomplete';
useProviderFor: FeatureName;
} & SendLLMType

// params to the true sendLLMMessage function
Expand Down Expand Up @@ -85,7 +86,7 @@ export type EventLLMMessageOnFinalMessageParams = Parameters<OnFinalMessage>[0]
export type EventLLMMessageOnErrorParams = Parameters<OnError>[0] & { requestId: string }


export type _InternalSendLLMMessageFnType = (
export type _InternalSendLLMChatMessageFnType = (
params: {
onText: OnText;
onFinalMessage: OnFinalMessage;
Expand All @@ -95,11 +96,11 @@ export type _InternalSendLLMMessageFnType = (
modelName: string;
_setAborter: (aborter: () => void) => void;

messages: _InternalLLMMessage[];
messages: _InternalLLMChatMessage[];
}
) => void

export type _InternalOllamaFIMMessageFnType = (
export type _InternalSendLLMFIMMessageFnType = (
params: {
onText: OnText;
onFinalMessage: OnFinalMessage;
Expand All @@ -109,7 +110,7 @@ export type _InternalOllamaFIMMessageFnType = (
modelName: string;
_setAborter: (aborter: () => void) => void;

messages: _InternalOllamaFIMMessages;
messages: _InternalSendFIMMessage;
}
) => void

Expand Down
8 changes: 4 additions & 4 deletions src/vs/platform/void/common/refreshModelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export type RefreshModelStateOfProvider = Record<RefreshableProviderName, Refres


const refreshBasedOn: { [k in RefreshableProviderName]: (keyof SettingsOfProvider[k])[] } = {
ollama: ['_enabled', 'endpoint'],
// openAICompatible: ['_enabled', 'endpoint', 'apiKey'],
ollama: ['_didFillInProviderSettings', 'endpoint'],
// openAICompatible: ['_didFillInProviderSettings', 'endpoint', 'apiKey'],
}
const REFRESH_INTERVAL = 5_000
// const COOLDOWN_TIMEOUT = 300
Expand Down Expand Up @@ -95,7 +95,7 @@ export class RefreshModelService extends Disposable implements IRefreshModelServ

for (const providerName of refreshableProviderNames) {

// const { _enabled: enabled } = this.voidSettingsService.state.settingsOfProvider[providerName]
// const { '_didFillInProviderSettings': enabled } = this.voidSettingsService.state.settingsOfProvider[providerName]
this.startRefreshingModels(providerName, autoOptions)

// every time providerName.enabled changes, refresh models too, like a useEffect
Expand Down Expand Up @@ -175,7 +175,7 @@ export class RefreshModelService extends Disposable implements IRefreshModelServ
{ enableProviderOnSuccess: options.enableProviderOnSuccess, hideRefresh: options.doNotFire }
)

if (options.enableProviderOnSuccess) this.voidSettingsService.setSettingOfProvider(providerName, '_enabled', true)
if (options.enableProviderOnSuccess) this.voidSettingsService.setSettingOfProvider(providerName, '_didFillInProviderSettings', true)

this._setRefreshState(providerName, 'finished', options)
autoPoll()
Expand Down
Loading

0 comments on commit 5fa21be

Please sign in to comment.