add ollamaList to llmMessageService

This commit is contained in:
Andrew Pareles 2024-12-12 19:01:01 -08:00
parent 696abc39fd
commit 94f4d2caaf
15 changed files with 202 additions and 215 deletions

View file

@ -124,8 +124,6 @@ import { ExtensionSignatureVerificationService, IExtensionSignatureVerificationS
import { LLMMessageChannel } from '../../platform/void/electron-main/llmMessageChannel.js';
import { IMetricsService } from '../../platform/void/common/metricsService.js';
import { MetricsMainService } from '../../platform/void/electron-main/metricsMainService.js';
import { OllamaListMainService } from '../../platform/void/electron-main/ollamaListMainService.js';
import { IOllamaListService } from '../../platform/void/common/ollamaListService.js';
/**
* The main VS Code application. There will only ever be one instance,
@ -1109,7 +1107,6 @@ export class CodeApplication extends Disposable {
// Void main process services (required for services with a channel for comm between browser and electron-main (node))
services.set(IMetricsService, new SyncDescriptor(MetricsMainService, undefined, false));
services.set(IOllamaListService, new SyncDescriptor(OllamaListMainService, undefined, false));
// Default Extensions Profile Init
services.set(IExtensionsProfileScannerService, new SyncDescriptor(ExtensionsProfileScannerService, undefined, true));
@ -1245,13 +1242,11 @@ export class CodeApplication extends Disposable {
mainProcessElectronServer.registerChannel('logger', loggerChannel);
sharedProcessClient.then(client => client.registerChannel('logger', loggerChannel));
// Void
// Void - use loggerChannel as reference
const metricsChannel = ProxyChannel.fromService(accessor.get(IMetricsService), disposables);
mainProcessElectronServer.registerChannel('void-channel-metrics', metricsChannel);
const ollamaListChannel = ProxyChannel.fromService(accessor.get(IOllamaListService), disposables);
mainProcessElectronServer.registerChannel('void-channel-ollama-list', ollamaListChannel);
const sendLLMMessageChannel = new LLMMessageChannel(accessor.get(IMetricsService));
mainProcessElectronServer.registerChannel('void-channel-sendLLMMessage', sendLLMMessageChannel);
const llmMessageChannel = new LLMMessageChannel(accessor.get(IMetricsService));
mainProcessElectronServer.registerChannel('void-channel-llmMessageService', llmMessageChannel);
// Extension Host Debug Broadcasting
const electronExtensionHostDebugBroadcastChannel = new ElectronExtensionHostDebugBroadcastChannel(accessor.get(IWindowsMainService));

View file

@ -3,7 +3,7 @@
* Void Editor additions licensed under the AGPL 3.0 License.
*--------------------------------------------------------------------------------------------*/
import { ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, LLMMessageServiceParams, ProxyLLMMessageParams, ProxyLLMMessageAbortParams } from '../common/llmMessageTypes.js';
import { EventLLMMessageOnTextParams, EventLLMMessageOnErrorParams, EventLLMMessageOnFinalMessageParams, ServiceSendLLMMessageParams, MainLLMMessageParams, MainLLMMessageAbortParams, ServiceOllamaListParams, EventOllamaListOnSuccessParams, EventOllamaListOnErrorParams, MainOllamaListParams } from '../common/llmMessageTypes.js';
import { IChannel } from '../../../base/parts/ipc/common/ipc.js';
import { IMainProcessService } from '../../ipc/common/mainProcessService.js';
import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js';
@ -21,7 +21,7 @@ export const ISendLLMMessageService = createDecorator<ISendLLMMessageService>('s
// defines an interface that node/ creates and browser/ uses
export interface ISendLLMMessageService {
readonly _serviceBrand: undefined;
sendLLMMessage: (params: LLMMessageServiceParams) => string | null;
sendLLMMessage: (params: ServiceSendLLMMessageParams) => string | null;
abort: (requestId: string) => void;
}
@ -31,9 +31,16 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage
readonly _serviceBrand: undefined;
private readonly channel: IChannel // LLMMessageChannel
private readonly onTextHooks: { [eventId: string]: ((params: ProxyOnTextPayload) => void) } = {}
private readonly onFinalMessageHooks: { [eventId: string]: ((params: ProxyOnFinalMessagePayload) => void) } = {}
private readonly onErrorHooks: { [eventId: string]: ((params: ProxyOnErrorPayload) => void) } = {}
// llmMessage
private readonly onTextHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnTextParams) => void) } = {}
private readonly onFinalMessageHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnFinalMessageParams) => void) } = {}
private readonly onErrorHooks_llm: { [eventId: string]: ((params: EventLLMMessageOnErrorParams) => void) } = {}
// ollamaList
private readonly onSuccess_ollama: { [eventId: string]: ((params: EventOllamaListOnSuccessParams) => void) } = {}
private readonly onError_ollama: { [eventId: string]: ((params: EventOllamaListOnErrorParams) => void) } = {}
constructor(
@IMainProcessService private readonly mainProcessService: IMainProcessService, // used as a renderer (only usable on client side)
@ -43,22 +50,22 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage
super()
// const service = ProxyChannel.toService<LLMMessageChannel>(mainProcessService.getChannel('void-channel-sendLLMMessage')); // lets you call it like a service
this.channel = this.mainProcessService.getChannel('void-channel-sendLLMMessage')
this.channel = this.mainProcessService.getChannel('void-channel-llmMessageService')
// this sets up an IPC channel and takes a few ms, so we set up listeners immediately and add hooks to them instead
const onTextEvent: Event<ProxyOnTextPayload> = this.channel.listen('onText')
const onFinalMessageEvent: Event<ProxyOnFinalMessagePayload> = this.channel.listen('onFinalMessage')
const onErrorEvent: Event<ProxyOnErrorPayload> = this.channel.listen('onError')
const onTextEvent: Event<EventLLMMessageOnTextParams> = this.channel.listen('onText')
const onFinalMessageEvent: Event<EventLLMMessageOnFinalMessageParams> = this.channel.listen('onFinalMessage')
const onErrorEvent: Event<EventLLMMessageOnErrorParams> = this.channel.listen('onError')
this._register(
onTextEvent(e => {
this.onTextHooks[e.requestId]?.(e)
this.onTextHooks_llm[e.requestId]?.(e)
})
)
this._register(
onFinalMessageEvent(e => {
this.onFinalMessageHooks[e.requestId]?.(e)
this.onFinalMessageHooks_llm[e.requestId]?.(e)
this._onRequestIdDone(e.requestId)
})
)
@ -66,14 +73,13 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage
this._register(
onErrorEvent(e => {
console.log('Error in SendLLMMessageService:', JSON.stringify(e))
this.onErrorHooks[e.requestId]?.(e)
this.onErrorHooks_llm[e.requestId]?.(e)
this._onRequestIdDone(e.requestId)
})
)
}
sendLLMMessage(params: LLMMessageServiceParams) {
sendLLMMessage(params: ServiceSendLLMMessageParams) {
const { onText, onFinalMessage, onError, ...proxyParams } = params;
const { featureName } = proxyParams
@ -87,9 +93,9 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage
// add state for request id
const requestId_ = generateUuid();
this.onTextHooks[requestId_] = onText
this.onFinalMessageHooks[requestId_] = onFinalMessage
this.onErrorHooks[requestId_] = onError
this.onTextHooks_llm[requestId_] = onText
this.onFinalMessageHooks_llm[requestId_] = onFinalMessage
this.onErrorHooks_llm[requestId_] = onError
const { settingsOfProvider } = this.voidConfigStateService.state
@ -100,21 +106,42 @@ export class SendLLMMessageService extends Disposable implements ISendLLMMessage
providerName,
modelName,
settingsOfProvider,
} satisfies ProxyLLMMessageParams);
} satisfies MainLLMMessageParams);
return requestId_
}
abort(requestId: string) {
this.channel.call('abort', { requestId } satisfies ProxyLLMMessageAbortParams);
this.channel.call('abort', { requestId } satisfies MainLLMMessageAbortParams);
this._onRequestIdDone(requestId)
}
ollamaList = (params: ServiceOllamaListParams) => {
const { onSuccess, onError, ...proxyParams } = params
const { settingsOfProvider } = this.voidConfigStateService.state
// add state for request id
const requestId_ = generateUuid();
this.onSuccess_ollama[requestId_] = onSuccess
this.onError_ollama[requestId_] = onError
this.channel.call('ollamaList', {
...proxyParams,
settingsOfProvider,
requestId: requestId_,
} satisfies MainOllamaListParams)
}
_onRequestIdDone(requestId: string) {
delete this.onTextHooks[requestId]
delete this.onFinalMessageHooks[requestId]
delete this.onErrorHooks[requestId]
delete this.onTextHooks_llm[requestId]
delete this.onFinalMessageHooks_llm[requestId]
delete this.onErrorHooks_llm[requestId]
delete this.onSuccess_ollama[requestId]
delete this.onError_ollama[requestId]
}
}

View file

@ -1,30 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Glass Devtools, Inc. All rights reserved.
* Void Editor additions licensed under the AGPL 3.0 License.
*--------------------------------------------------------------------------------------------*/
import { ProxyChannel } from '../../../base/parts/ipc/common/ipc.js';
import { IMainProcessService } from '../../ipc/common/mainProcessService.js';
import { InstantiationType, registerSingleton } from '../../instantiation/common/extensions.js';
import { IOllamaListService } from '../common/ollamaListService.js';
// BROWSER IMPLEMENTATION, calls channel
export class OllamaListService implements IOllamaListService {
readonly _serviceBrand: undefined;
private readonly ollamaListService: IOllamaListService;
constructor(
@IMainProcessService mainProcessService: IMainProcessService // (only usable on client side)
) {
this.ollamaListService = ProxyChannel.toService<IOllamaListService>(mainProcessService.getChannel('void-channel-ollama-list'));
}
list: IOllamaListService['list'] = (...params) => {
this.ollamaListService.list(...params);
}
}
registerSingleton(IOllamaListService, OllamaListService, InstantiationType.Eager);

View file

@ -8,11 +8,8 @@ import { ProviderName, SettingsOfProvider } from './voidConfigTypes'
export type OnText = (p: { newText: string, fullText: string }) => void
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 = {
@ -30,20 +27,8 @@ export type LLMFeatureSelection = {
range: IRange
}
export type LLMMessageServiceParams = {
onText: OnText;
onFinalMessage: OnFinalMessage;
onError: OnError;
messages: LLMMessage[];
logging: {
loggingName: string,
};
} & LLMFeatureSelection
// params to the true sendLLMMessage function
export type SendLLMMMessageParams = {
export type LLMMMessageParams = {
onText: OnText;
onFinalMessage: OnFinalMessage;
onError: OnError;
@ -59,21 +44,29 @@ export type SendLLMMMessageParams = {
settingsOfProvider: SettingsOfProvider;
}
export type ServiceSendLLMMessageParams = {
onText: OnText;
onFinalMessage: OnFinalMessage;
onError: OnError;
messages: LLMMessage[];
logging: {
loggingName: string,
};
} & LLMFeatureSelection
// can't send functions across a proxy, use listeners instead
export type BlockedProxyParams = 'onText' | 'onFinalMessage' | 'onError' | 'abortRef'
export type ProxyLLMMessageParams = Omit<SendLLMMMessageParams, BlockedProxyParams> & { requestId: string }
export type BlockedMainLLMMessageParams = 'onText' | 'onFinalMessage' | 'onError' | 'abortRef'
export type ProxyOnTextPayload = Parameters<OnText>[0] & { requestId: string }
export type ProxyOnFinalMessagePayload = Parameters<OnFinalMessage>[0] & { requestId: string }
export type ProxyOnErrorPayload = Parameters<OnError>[0] & { requestId: string }
export type MainLLMMessageParams = Omit<LLMMMessageParams, BlockedMainLLMMessageParams> & { requestId: string }
export type MainLLMMessageAbortParams = { requestId: string }
export type ProxyLLMMessageAbortParams = { requestId: string }
export type EventLLMMessageOnTextParams = Parameters<OnText>[0] & { requestId: string }
export type EventLLMMessageOnFinalMessageParams = Parameters<OnFinalMessage>[0] & { requestId: string }
export type EventLLMMessageOnErrorParams = Parameters<OnError>[0] & { requestId: string }
export type SendLLMMessageFnTypeInternal = (params: {
export type _InternalSendLLMMessageFnType = (params: {
messages: LLMMessage[];
onText: OnText;
onFinalMessage: OnFinalMessage;
@ -84,3 +77,64 @@ export type SendLLMMessageFnTypeInternal = (params: {
_setAborter: (aborter: () => void) => void;
}) => void
// service -> main -> internal -> event (back to main)
// (browser)
// These are from 'ollama' SDK
interface ModelDetails {
parent_model: string;
format: string;
family: string;
families: string[];
parameter_size: string;
quantization_level: string;
}
type ModelResponse = {
name: string;
modified_at: Date;
size: number;
digest: string;
details: ModelDetails;
expires_at: Date;
size_vram: number;
}
// params to the true list fn
export type OllamaListParams = {
settingsOfProvider: SettingsOfProvider;
onSuccess: (param: { models: ModelResponse[] }) => void;
onError: (param: { error: any }) => void;
}
export type ServiceOllamaListParams = {
onSuccess: (param: { models: ModelResponse[] }) => void;
onError: (param: { error: any }) => void;
}
type BlockedMainOllamaListParams = 'onSuccess' | 'onError'
export type MainOllamaListParams = Omit<OllamaListParams, BlockedMainOllamaListParams> & { requestId: string }
export type EventOllamaListOnSuccessParams = Parameters<OllamaListParams['onSuccess']>[0] & { requestId: string }
export type EventOllamaListOnErrorParams = Parameters<OllamaListParams['onError']>[0] & { requestId: string }
export type _InternalOllamaListFnType = (params: OllamaListParams) => void

View file

@ -1,48 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Glass Devtools, Inc. All rights reserved.
* Void Editor additions licensed under the AGPL 3.0 License.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from '../../instantiation/common/instantiation.js';
import { SettingsOfProvider } from './voidConfigTypes.js';
export type OllamaListFnParams = {
settingsOfProvider: SettingsOfProvider;
onSuccess: (param: { models: ModelResponse[] }) => void;
onError: (param: { error: any }) => void;
}
export interface IOllamaListService {
readonly _serviceBrand: undefined;
list(params: OllamaListFnParams): void;
}
export const IOllamaListService = createDecorator<IOllamaListService>('ollamaListService');
// These are from 'ollama' SDK
interface ModelDetails {
parent_model: string;
format: string;
family: string;
families: string[];
parameter_size: string;
quantization_level: string;
}
type ModelResponse = {
name: string;
modified_at: Date;
size: number;
digest: string;
details: ModelDetails;
expires_at: Date;
size_vram: number;
}

View file

@ -5,7 +5,7 @@
import Anthropic from '@anthropic-ai/sdk';
import { parseMaxTokensStr } from './util.js';
import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js';
import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js';
import { displayInfoOfSettingName } from '../../common/voidConfigTypes.js';
// Anthropic
@ -13,7 +13,7 @@ type LLMMessageAnthropic = {
role: 'user' | 'assistant';
content: string;
}
export const sendAnthropicMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
export const sendAnthropicMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
const thisConfig = settingsOfProvider.anthropic

View file

@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import { Content, GoogleGenerativeAI, GoogleGenerativeAIFetchError } from '@google/generative-ai';
import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js';
import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js';
// Gemini
export const sendGeminiMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
export const sendGeminiMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
let fullText = ''

View file

@ -4,11 +4,11 @@
*--------------------------------------------------------------------------------------------*/
import Groq from 'groq-sdk';
import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js';
import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js';
import { parseMaxTokensStr } from './util.js';
// Groq
export const sendGroqMsg: SendLLMMessageFnTypeInternal = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
export const sendGroqMsg: _InternalSendLLMMessageFnType = async ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
let fullText = '';
const thisConfig = settingsOfProvider.groq

View file

@ -4,11 +4,10 @@
*--------------------------------------------------------------------------------------------*/
import { Ollama } from 'ollama';
import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js';
import { _InternalOllamaListFnType, _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js';
import { parseMaxTokensStr } from './util.js';
import { OllamaListFnParams } from '../../common/ollamaListService.js';
export const getDefaultOllamaModels = async ({ onSuccess, onError, settingsOfProvider }: OllamaListFnParams) => {
export const ollamaList: _InternalOllamaListFnType = async ({ onSuccess, onError, settingsOfProvider }) => {
const thisConfig = settingsOfProvider.ollama
const ollama = new Ollama({ host: thisConfig.endpoint })
ollama.list()
@ -24,7 +23,7 @@ export const getDefaultOllamaModels = async ({ onSuccess, onError, settingsOfPro
// Ollama
export const sendOllamaMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
export const sendOllamaMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter }) => {
const thisConfig = settingsOfProvider.ollama

View file

@ -4,12 +4,12 @@
*--------------------------------------------------------------------------------------------*/
import OpenAI from 'openai';
import { SendLLMMessageFnTypeInternal } from '../../common/llmMessageTypes.js';
import { _InternalSendLLMMessageFnType } from '../../common/llmMessageTypes.js';
import { parseMaxTokensStr } from './util.js';
// OpenAI, OpenRouter, OpenAICompatible
export const sendOpenAIMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter, providerName }) => {
export const sendOpenAIMsg: _InternalSendLLMMessageFnType = ({ messages, onText, onFinalMessage, onError, settingsOfProvider, modelName, _setAborter, providerName }) => {
let fullText = ''

View file

@ -3,7 +3,7 @@
* Void Editor additions licensed under the AGPL 3.0 License.
*--------------------------------------------------------------------------------------------*/
import { SendLLMMMessageParams, OnText, OnFinalMessage, OnError } from '../../common/llmMessageTypes.js';
import { LLMMMessageParams, OnText, OnFinalMessage, OnError } from '../../common/llmMessageTypes.js';
import { IMetricsService } from '../../common/metricsService.js';
import { sendAnthropicMsg } from './anthropic.js';
@ -22,7 +22,7 @@ export const sendLLMMessage = ({
settingsOfProvider,
providerName,
modelName,
}: SendLLMMMessageParams,
}: LLMMMessageParams,
metricsService: IMetricsService
) => {

View file

@ -8,43 +8,55 @@
import { IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
import { Emitter, Event } from '../../../base/common/event.js';
import { BlockedProxyParams, ProxyOnTextPayload, ProxyOnErrorPayload, ProxyOnFinalMessagePayload, ProxyLLMMessageParams, AbortRef, SendLLMMMessageParams, ProxyLLMMessageAbortParams } from '../common/llmMessageTypes.js';
import { EventLLMMessageOnTextParams, EventLLMMessageOnErrorParams, EventLLMMessageOnFinalMessageParams, MainLLMMessageParams, AbortRef, LLMMMessageParams, MainLLMMessageAbortParams, MainOllamaListParams, OllamaListParams, EventOllamaListOnSuccessParams, EventOllamaListOnErrorParams } from '../common/llmMessageTypes.js';
import { sendLLMMessage } from './llmMessage/sendLLMMessage.js'
import { IMetricsService } from '../common/metricsService.js';
import { ollamaList } from './llmMessage/ollama.js';
// NODE IMPLEMENTATION - calls actual sendLLMMessage() and returns listeners to it
export class LLMMessageChannel implements IServerChannel {
private readonly _onText = new Emitter<ProxyOnTextPayload>();
readonly onText = this._onText.event;
// sendLLMMessage
private readonly _onText_llm = new Emitter<EventLLMMessageOnTextParams>();
private readonly onText_llm = this._onText_llm.event;
private readonly _onFinalMessage = new Emitter<ProxyOnFinalMessagePayload>();
readonly onFinalMessage = this._onFinalMessage.event;
private readonly _onFinalMessage_llm = new Emitter<EventLLMMessageOnFinalMessageParams>();
private readonly onFinalMessage_llm = this._onFinalMessage_llm.event;
private readonly _onError = new Emitter<ProxyOnErrorPayload>();
readonly onError = this._onError.event;
private readonly _onError_llm = new Emitter<EventLLMMessageOnErrorParams>();
private readonly onError_llm = this._onError_llm.event;
private readonly _abortRefOfRequestId_llm: Record<string, AbortRef> = {}
private readonly _abortRefOfRequestId: Record<string, AbortRef> = {}
// ollamaList
private readonly _onSuccess_ollama = new Emitter<EventOllamaListOnSuccessParams>();
private readonly onSuccess_ollama = this._onSuccess_ollama.event;
private readonly _onError_ollama = new Emitter<EventOllamaListOnErrorParams>();
private readonly onError_ollama = this._onError_ollama.event;
// stupidly, channels can't take in @IService
constructor(
private readonly metricsService: IMetricsService,
) {
}
// browser uses this to listen for changes
listen(_: unknown, event: BlockedProxyParams): Event<any> {
if (event === 'onText') {
return this.onText;
listen(_: unknown, event: string): Event<any> {
if (event === 'onText_llm') {
return this.onText_llm;
}
else if (event === 'onFinalMessage') {
return this.onFinalMessage;
else if (event === 'onFinalMessage_llm') {
return this.onFinalMessage_llm;
}
else if (event === 'onError') {
return this.onError;
else if (event === 'onError_llm') {
return this.onError_llm;
}
else if (event === 'onSuccess_ollama') {
return this.onSuccess_ollama;
}
else if (event === 'onError_ollama') {
return this.onError_ollama;
}
else {
throw new Error(`Event not found: ${event}`);
@ -61,6 +73,9 @@ export class LLMMessageChannel implements IServerChannel {
else if (command === 'abort') {
this._callAbort(params)
}
else if (command === 'ollamaList') {
this._callOllamaList(params)
}
else {
throw new Error(`Void sendLLM: command "${command}" not recognized.`)
}
@ -71,27 +86,38 @@ export class LLMMessageChannel implements IServerChannel {
}
// the only place sendLLMMessage is actually called
private async _callSendLLMMessage(params: ProxyLLMMessageParams) {
private async _callSendLLMMessage(params: MainLLMMessageParams) {
const { requestId } = params;
if (!(requestId in this._abortRefOfRequestId))
this._abortRefOfRequestId[requestId] = { current: null }
if (!(requestId in this._abortRefOfRequestId_llm))
this._abortRefOfRequestId_llm[requestId] = { current: null }
const mainThreadParams: SendLLMMMessageParams = {
const mainThreadParams: LLMMMessageParams = {
...params,
onText: ({ newText, fullText }) => { this._onText.fire({ requestId, newText, fullText }); },
onFinalMessage: ({ fullText }) => { this._onFinalMessage.fire({ requestId, fullText }); },
onError: ({ message: error, fullError }) => { console.log('sendLLM: firing err'); this._onError.fire({ requestId, message: error, fullError }); },
abortRef: this._abortRefOfRequestId[requestId],
onText: ({ newText, fullText }) => { this._onText_llm.fire({ requestId, newText, fullText }); },
onFinalMessage: ({ fullText }) => { this._onFinalMessage_llm.fire({ requestId, fullText }); },
onError: ({ message: error, fullError }) => { console.log('sendLLM: firing err'); this._onError_llm.fire({ requestId, message: error, fullError }); },
abortRef: this._abortRefOfRequestId_llm[requestId],
}
sendLLMMessage(mainThreadParams, this.metricsService);
}
private _callAbort(params: ProxyLLMMessageAbortParams) {
private _callAbort(params: MainLLMMessageAbortParams) {
const { requestId } = params;
if (!(requestId in this._abortRefOfRequestId)) return
this._abortRefOfRequestId[requestId].current?.()
delete this._abortRefOfRequestId[requestId]
if (!(requestId in this._abortRefOfRequestId_llm)) return
this._abortRefOfRequestId_llm[requestId].current?.()
delete this._abortRefOfRequestId_llm[requestId]
}
private _callOllamaList(params: MainOllamaListParams) {
const { requestId } = params;
const mainThreadParams: OllamaListParams = {
...params,
onSuccess: ({ models }) => { this._onSuccess_ollama.fire({ requestId, models }); },
onError: ({ error }) => { this._onError_ollama.fire({ requestId, error }); },
}
ollamaList(mainThreadParams)
}

View file

@ -1,24 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Glass Devtools, Inc. All rights reserved.
* Void Editor additions licensed under the AGPL 3.0 License.
*--------------------------------------------------------------------------------------------*/
import { Disposable } from '../../../base/common/lifecycle.js';
import { IOllamaListService } from '../common/ollamaListService.js';
import { getDefaultOllamaModels } from './llmMessage/ollama.js';
export class OllamaListMainService extends Disposable implements IOllamaListService {
_serviceBrand: undefined;
constructor() {
super()
}
list: IOllamaListService['list'] = (...params) => {
return getDefaultOllamaModels(...params)
}
}

View file

@ -28,7 +28,7 @@ import { ILanguageService } from '../../../../editor/common/languages/language.j
import * as dom from '../../../../base/browser/dom.js';
import { Widget } from '../../../../base/browser/ui/widget.js';
import { URI } from '../../../../base/common/uri.js';
import { LLMFeatureSelection, LLMMessageServiceParams } from '../../../../platform/void/common/llmMessageTypes.js';
import { LLMFeatureSelection, ServiceSendLLMMessageParams } from '../../../../platform/void/common/llmMessageTypes.js';
import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMessageService.js';
@ -709,7 +709,7 @@ Please finish writing the new file by applying the diff to the original file. Re
let streamRequestId: string | null = null
const object: LLMMessageServiceParams = {
const object: ServiceSendLLMMessageParams = {
logging: { loggingName: 'streamChunk' },
messages: [
{ role: 'system', content: writeFileWithDiffInstructions, },

View file

@ -46,7 +46,6 @@ import { ISendLLMMessageService } from '../../../../platform/void/browser/llmMes
import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
import { IViewsService } from '../../../services/views/common/viewsService.js';
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
import { IOllamaListService } from '../../../../platform/void/common/ollamaListService.js';
// compare against search.contribution.ts and debug.contribution.ts, scm.contribution.ts (source control)
@ -89,20 +88,9 @@ class VoidSidebarViewPane extends ViewPane {
@IOpenerService openerService: IOpenerService,
@ITelemetryService telemetryService: ITelemetryService,
@IHoverService hoverService: IHoverService,
@IVoidConfigStateService configStateService: IVoidConfigStateService,
@IOllamaListService ollamaListService: IOllamaListService,
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService)
console.log('calling Ollama list!!!')
ollamaListService.list({
onSuccess: ({ models }) => {
console.log('ollama models:', models)
}, onError: ({ error }) => {
console.error('ollama error:', error)
},
settingsOfProvider: configStateService.state.settingsOfProvider,
})
}