Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/default-providers/ChromeAI/chat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
BaseChatModel,
BaseChatModelCallOptions
} from '@langchain/core/language_models/chat_models';
import {
AIMessageChunk,
BaseMessage,
AIMessage
} from '@langchain/core/messages';
import { ChromeAI as ChromeLLM } from '@langchain/community/experimental/llms/chrome_ai';
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
import { ChatResult, ChatGeneration } from '@langchain/core/outputs';

export interface IChromeChatCallOptions extends BaseChatModelCallOptions {}

export class ChromeChatModel extends BaseChatModel<
IChromeChatCallOptions,
AIMessageChunk
> {
private llm: ChromeLLM;

constructor(fields?: ConstructorParameters<typeof ChromeLLM>[0]) {
super(fields ?? {});
this.llm = new ChromeLLM(fields ?? {});
}

_llmType() {
return 'chrome-chat';
}

async _generate(
messages: BaseMessage[],
options: IChromeChatCallOptions,
runManager?: CallbackManagerForLLMRun
): Promise<ChatResult> {
const text = messages.map(m => m.content).join('\n');
const completion = await this.llm.invoke(text, options);

const generations: ChatGeneration[] = [
{
text: completion,
message: new AIMessage(completion)
}
];

return { generations };
}
}
6 changes: 2 additions & 4 deletions src/default-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Notification } from '@jupyterlab/apputils';

import { ChatAnthropic } from '@langchain/anthropic';
import { ChatWebLLM } from '@langchain/community/chat_models/webllm';
import { ChromeAI } from '@langchain/community/experimental/llms/chrome_ai';
import { ChromeChatModel } from '../default-providers/ChromeAI/chat';
import { ChatGoogleGenerativeAI } from '@langchain/google-genai';
import { ChatMistralAI } from '@langchain/mistralai';
import { ChatOllama } from '@langchain/ollama';
Expand Down Expand Up @@ -56,9 +56,7 @@ const AIProviders: IAIProvider[] = [
},
{
name: 'ChromeAI',
// TODO: fix
// @ts-expect-error: missing properties
chat: ChromeAI,
chat: ChromeChatModel,
completer: ChromeCompleter,
instructions: ChromeAIInstructions,
settingsSchema: ChromeAISettings,
Expand Down
Loading