Skip to content

Commit 174e328

Browse files
committed
fix: make options optional
1 parent da786fd commit 174e328

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can now use this module in any renderer. By default, `@electron/llm` auto-in
4747
```
4848
// First, load the model
4949
await window.electronAi.create({
50-
modelPath: "/full/path/to/model.gguf"
50+
modelAlias: "Meta-Llama-3-8B-Instruct.Q4_K_M.gguf"
5151
})
5252
5353
// Then, talk to it

__tests__/preload.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ describe('Preload Interface', () => {
5959
);
6060
});
6161

62+
it('prompt should invoke without options', async () => {
63+
const input = 'Test prompt';
64+
await (globalThis as any).electronAi.prompt(input);
65+
expect(ipcRenderer.invoke).toHaveBeenCalledWith(
66+
IpcRendererMessage.ELECTRON_LLM_PROMPT,
67+
input,
68+
undefined,
69+
);
70+
});
71+
6272
it('promptStreaming should invoke with correct params', async () => {
6373
const input = 'Test prompt for streaming';
6474

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface InternalLanguageModelPromptOptions
5050
export type AiProcessModelCreateData = InternalLanguageModelCreateOptions;
5151

5252
export interface AiProcessSendPromptData {
53-
options: LanguageModelPromptOptions;
53+
options?: LanguageModelPromptOptions;
5454
stream?: boolean;
5555
input: string;
5656
}

src/main/register-ai-handlers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function registerAiHandlers({
9999

100100
ipcMain.handle(
101101
IpcRendererMessage.ELECTRON_LLM_PROMPT,
102-
async (_event, input: string, options: LanguageModelPromptOptions) => {
102+
async (_event, input: string, options?: LanguageModelPromptOptions) => {
103103
if (!aiProcess) {
104104
throw new Error(
105105
'AI model process not started. Please do so with `electronAi.create()`',
@@ -132,7 +132,7 @@ export function registerAiHandlers({
132132
const timeoutPromise = new Promise((_, reject) => {
133133
setTimeout(
134134
() => reject(new Error('Prompt response timed out.')),
135-
options.timeout || 20000,
135+
options?.timeout || 20000,
136136
);
137137
});
138138

@@ -142,7 +142,7 @@ export function registerAiHandlers({
142142

143143
ipcMain.on(
144144
IpcRendererMessage.ELECTRON_LLM_PROMPT_STREAMING_REQUEST,
145-
(event, input: string, options: LanguageModelPromptOptions) => {
145+
(event, input: string, options?: LanguageModelPromptOptions) => {
146146
if (!aiProcess) {
147147
event.sender.send(
148148
'ELECTRON_LLM_PROMPT_STREAMING_ERROR',

src/utility/call-ai-model-entry-point.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ async function generateResponse(message: PromptMessage) {
4848
return;
4949
}
5050

51-
const options = abortSignalManager.getWithSignalFromPromptOptions(
52-
data.options,
53-
);
51+
const options =
52+
data.options &&
53+
abortSignalManager.getWithSignalFromPromptOptions(data.options);
5454

5555
try {
5656
// Format the prompt payload correctly for the language model

0 commit comments

Comments
 (0)