You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`generate()`|`(messages: Message[], tools?: LLMTool[]) => Promise<void>`| Runs model to complete chat passed in `messages` argument. It doesn't manage conversation context. |
66
-
|`interrupt()`|`() => void`| Function to interrupt the current inference. |
67
-
|`response`|`string`| State of the generated response. This field is updated with each token generated by the model. |
68
-
|`token`|`string`| The most recently generated token. |
69
-
|`isReady`|`boolean`| Indicates whether the model is ready. |
70
-
|`isGenerating`|`boolean`| Indicates whether the model is currently generating a response. |
71
-
|`downloadProgress`|`number`| Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval. |
72
-
|`error`| <code>string | null</code> | Contains the error message if the model failed to load. |
73
-
|`configure`|`({chatConfig?: Partial<ChatConfig>, toolsConfig?: ToolsConfig, generationConfig?: GenerationConfig}) => void`| Configures chat and tool calling. See more details in [configuring the model](#configuring-the-model). |
74
-
|`sendMessage`|`(message: string) => Promise<void>`| Function to add user message to conversation. After model responds, `messageHistory` will be updated with both user message and model response. |
75
-
|`deleteMessage`|`(index: number) => void`| Deletes all messages starting with message on `index` position. After deletion `messageHistory` will be updated. |
76
-
|`messageHistory`|`Message[]`| History containing all messages in conversation. This field is updated after model responds to `sendMessage`. |
77
-
|`getGeneratedTokenCount`|`() => number`| Returns the number of tokens generated in the last response. |
|`generate()`|`(messages: Message[], tools?: LLMTool[]) => Promise<string>`| Runs model to complete chat passed in `messages` argument. Returns the generated response. It doesn't manage conversation context. |
66
+
|`interrupt()`|`() => void`| Function to interrupt the current inference. |
67
+
|`response`|`string`| State of the generated response. This field is updated with each token generated by the model. |
68
+
|`token`|`string`| The most recently generated token. |
69
+
|`isReady`|`boolean`| Indicates whether the model is ready. |
70
+
|`isGenerating`|`boolean`| Indicates whether the model is currently generating a response. |
71
+
|`downloadProgress`|`number`| Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval. |
72
+
|`error`| <code>string | null</code> | Contains the error message if the model failed to load. |
73
+
|`configure`|`({chatConfig?: Partial<ChatConfig>, toolsConfig?: ToolsConfig, generationConfig?: GenerationConfig}) => void`| Configures chat and tool calling. See more details in [configuring the model](#configuring-the-model). |
74
+
|`sendMessage`|`(message: string) => Promise<string>`| Function to add user message to conversation. Returns the generated response. After model responds, `messageHistory` will be updated with both user message and model response. |
75
+
|`deleteMessage`|`(index: number) => void`| Deletes all messages starting with message on `index` position. After deletion `messageHistory` will be updated. |
76
+
|`messageHistory`|`Message[]`| History containing all messages in conversation. This field is updated after model responds to `sendMessage`. |
77
+
|`getGeneratedTokenCount`|`() => number`| Returns the number of tokens generated in the last response. |
@@ -166,21 +166,22 @@ You can use functions returned from this hooks in two manners:
166
166
167
167
### Simple generation
168
168
169
-
To perform chat completion you can use the `generate` function. There is no return value. Instead, the `response` value is updated with each token.
169
+
To perform chat completion you can use the `generate` function. The `response` value is updated with each token as it's generated, and the function returns a promise that resolves to the complete response when generation finishes.
170
170
171
171
```tsx
172
172
const llm =useLLM({ model: LLAMA3_2_1B });
173
173
174
-
const handleGenerate = () => {
174
+
const handleGenerate =async() => {
175
175
const chat:Message[] = [
176
176
{ role: 'system', content: 'You are a helpful assistant' },
177
177
{ role: 'user', content: 'Hi!' },
178
178
{ role: 'assistant', content: 'Hi!, how can I help you?' },
179
179
{ role: 'user', content: 'What is the meaning of life?' },
180
180
];
181
181
182
-
// Chat completion
183
-
llm.generate(chat);
182
+
// Chat completion - returns the generated response
0 commit comments