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
## Description
Solving few issues:
- Example app crashed when model was deleted during generation. This is
prevented now and we throw error if library users try it.
- state of hook and controller is properly reseted when changing models.
- `preventLoad` props in hook so you can postpone loading model until
you're ready
- fixes in state management in hook
### Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Documentation update (improves or adds clarity to existing
documentation)
### Tested on
- [x] iOS
- [ ] Android
### Screenshots
Preventing model swap during generation:
https://github.com/user-attachments/assets/0cfec0e9-02fc-414c-ac3a-5f6e767ea7ea
### Related issues
#235#237#241#264
### Checklist
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation accordingly
- [x] My changes generate no new warnings
@@ -129,9 +129,33 @@ Given computational constraints, our architecture is designed to support only on
129
129
130
130
**`modelSource`** - A string that specifies the location of the model binary. For more information, take a look at [loading models](../fundamentals/loading-models.md) section.
131
131
132
-
**`tokenizerSource`** - URL to the JSON file which contains the tokenizer
132
+
**`tokenizerSource`** - URL to the JSON file which contains the tokenizer.
133
+
134
+
**`tokenizerConfigSource`** - URL to the JSON file which contains the tokenizer config.
133
135
134
-
**`tokenizerConfigSource`** - URL to the JSON file which contains the tokenizer config
136
+
**`preventLoad?`** - Boolean that can prevent automatic model loading (and downloading the data if you load it for the first time) after running the hook.
|`messageHistory`|`Message[]`| History containing all messages in conversation. This field is updated after model responds to `sendMessage`. |
143
+
|`response`|`string`| State of the generated response. This field is updated with each token generated by the model. |
144
+
|`isReady`|`boolean`| Indicates whether the model is ready. |
145
+
|`isGenerating`|`boolean`| Indicates whether the model is currently generating a response. |
146
+
|`downloadProgress`|`number`| Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval. |
147
+
|`error`| <code>string | null</code> | Contains the error message if the model failed to load. |
148
+
|`configure`|`({ chatConfig?: Partial<ChatConfig>, toolsConfig?: ToolsConfig }) => void`| Configures chat and tool calling. See more details in [configuring the model](#configuring-the-model). |
149
+
|`sendMessage`|`(message: string, tools?: LLMTool[]) => Promise<void>`| Method to add user message to conversation. After model responds, `messageHistory` will be updated with both user message and model response. |
150
+
|`deleteMessage`|`(index: number) => void`| Deletes all messages starting with message on `index` position. After deletion `messageHistory` will be updated. |
151
+
|`generate`|`(messages: Message[], tools?: LLMTool[]) => Promise<void>`| Runs model to complete chat passed in `messages` argument. It doesn't manage conversation context. |
152
+
|`forward`|`(input: string) => Promise<void>`| Runs model inference with raw input string. You need to provide entire conversation and prompt (in correct format and with special tokens!) in input string to this method. It doesn't manage conversation context. It is intended for users that need access to the model itself without any wrapper. If you want simple chat with model consider using `sendMessage`. |
153
+
|`interrupt`|`() => void`| Function to interrupt the current inference. |
154
+
155
+
## Configuring the model
156
+
157
+
To configure model (i.e. change system prompt, load initial conversation history or manage tool calling) you can use
158
+
`configure` method. It accepts object with following fields:
135
159
136
160
**`chatConfig`** - Object configuring chat management, contains following properties:
137
161
@@ -149,22 +173,6 @@ Given computational constraints, our architecture is designed to support only on
149
173
150
174
-**`displayToolCalls`** - If set to true, JSON tool calls will be displayed in chat. If false, only answers will be displayed.
|`messageHistory`|`Message[]`| State of the generated response. This field is updated with each token generated by the model |
157
-
|`response`|`string`| State of the generated response. This field is updated with each token generated by the model |
158
-
|`isReady`|`boolean`| Indicates whether the model is ready |
159
-
|`isGenerating`|`boolean`| Indicates whether the model is currently generating a response |
160
-
|`downloadProgress`|`number`| Represents the download progress as a value between 0 and 1, indicating the extent of the model file retrieval. |
161
-
|`error`| <code>string | null</code> | Contains the error message if the model failed to load |
162
-
|`sendMessage`|`(message: string, tools?: LLMTool[]) => Promise<void>`| Method to add user message to conversation. After model responds, `messageHistory` will be updated with both user message and model response. |
163
-
|`deleteMessage`|`(index: number) => void`| Deletes all messages starting with message on `index` position. After deletion `messageHistory` will be updated. |
164
-
|`generate`|`(messages: Message[], tools?: LLMTool[]) => Promise<void>`| Runs model to complete chat passed in `messages` argument. It doesn't manage conversation context. |
165
-
|`forward`|`(input: string) => Promise<void>`| Runs model inference with raw input string. You need to provide entire conversation and prompt (in correct format and with special tokens!) in input string to this method. It doesn't manage conversation context. It is intended for users that need access to the model itself without any wrapper. If you want simple chat with model consider using `sendMessage`|
166
-
|`interrupt`|`() => void`| Function to interrupt the current inference |
167
-
168
176
## Sending a message
169
177
170
178
In order to send a message to the model, one can use the following code:
0 commit comments