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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ You can now use this module in any renderer. By default, `@electron/llm` auto-in
```
// First, load the model
await window.electronAi.create({
modelPath: "/full/path/to/model.gguf"
modelAlias: "Meta-Llama-3-8B-Instruct.Q4_K_M.gguf"
})

// Then, talk to it
Expand Down
10 changes: 10 additions & 0 deletions __tests__/preload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('Preload Interface', () => {
);
});

it('prompt should invoke without options', async () => {
const input = 'Test prompt';
await (globalThis as any).electronAi.prompt(input);
expect(ipcRenderer.invoke).toHaveBeenCalledWith(
IpcRendererMessage.ELECTRON_LLM_PROMPT,
input,
undefined,
);
});

it('promptStreaming should invoke with correct params', async () => {
const input = 'Test prompt for streaming';

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface InternalLanguageModelPromptOptions
export type AiProcessModelCreateData = InternalLanguageModelCreateOptions;

export interface AiProcessSendPromptData {
options: LanguageModelPromptOptions;
options?: LanguageModelPromptOptions;
stream?: boolean;
input: string;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/register-ai-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function registerAiHandlers({

ipcMain.handle(
IpcRendererMessage.ELECTRON_LLM_PROMPT,
async (_event, input: string, options: LanguageModelPromptOptions) => {
async (_event, input: string, options?: LanguageModelPromptOptions) => {
if (!aiProcess) {
throw new Error(
'AI model process not started. Please do so with `electronAi.create()`',
Expand Down Expand Up @@ -132,7 +132,7 @@ export function registerAiHandlers({
const timeoutPromise = new Promise((_, reject) => {
setTimeout(
() => reject(new Error('Prompt response timed out.')),
options.timeout || 20000,
options?.timeout || 20000,
);
});

Expand All @@ -142,7 +142,7 @@ export function registerAiHandlers({

ipcMain.on(
IpcRendererMessage.ELECTRON_LLM_PROMPT_STREAMING_REQUEST,
(event, input: string, options: LanguageModelPromptOptions) => {
(event, input: string, options?: LanguageModelPromptOptions) => {
if (!aiProcess) {
event.sender.send(
'ELECTRON_LLM_PROMPT_STREAMING_ERROR',
Expand Down
6 changes: 3 additions & 3 deletions src/utility/call-ai-model-entry-point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ async function generateResponse(message: PromptMessage) {
return;
}

const options = abortSignalManager.getWithSignalFromPromptOptions(
data.options,
);
const options =
data.options &&
abortSignalManager.getWithSignalFromPromptOptions(data.options);

try {
// Format the prompt payload correctly for the language model
Expand Down