react-native-nobodywho 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Nobodywho.podspec +2 -2
- package/README.md +16 -13
- package/generated/cpp/nobodywho.cpp +496 -3
- package/generated/cpp/nobodywho.hpp +8 -0
- package/generated/ts/nobodywho-ffi.ts +10 -1
- package/generated/ts/nobodywho.ts +180 -102
- package/package.json +1 -1
- package/src/chat.ts +5 -3
- package/src/cross_encoder.ts +6 -1
- package/src/encoder.ts +6 -1
- package/src/message.ts +49 -35
- package/src/model.ts +7 -0
- package/src/wrapper.ts +3 -4
package/src/message.ts
CHANGED
|
@@ -1,75 +1,89 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Message as InternalMessage,
|
|
3
3
|
Message_Tags,
|
|
4
|
-
Role,
|
|
5
4
|
type Asset,
|
|
6
5
|
type ToolCall,
|
|
7
6
|
} from "../generated/ts/nobodywho";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
* A chat message. The
|
|
11
|
-
* `toolCalls` or `name` determines the message type:
|
|
9
|
+
* A chat message. The variant determines the message type:
|
|
12
10
|
*
|
|
13
|
-
* - **User
|
|
14
|
-
* - **
|
|
15
|
-
* - **
|
|
11
|
+
* - **User message:** `{ role: "user", content, assets? }`
|
|
12
|
+
* - **Assistant message:** `{ role: "assistant", content }`
|
|
13
|
+
* - **Assistant tool call:** `{ role: "assistant", content, toolCalls }`
|
|
14
|
+
* - **System message:** `{ role: "system", content }`
|
|
15
|
+
* - **Tool response:** `{ role: "tool", name, content }`
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
18
18
|
* ```typescript
|
|
19
19
|
* const history = await chat.getChatHistory();
|
|
20
20
|
* for (const msg of history) {
|
|
21
|
-
* if ("
|
|
22
|
-
* console.log("Tool calls:", msg.toolCalls);
|
|
23
|
-
* } else if ("name" in msg) {
|
|
21
|
+
* if (msg.role === "tool") {
|
|
24
22
|
* console.log("Tool response:", msg.name, msg.content);
|
|
23
|
+
* } else if (msg.role === "assistant" && "toolCalls" in msg) {
|
|
24
|
+
* console.log("Tool calls:", msg.toolCalls);
|
|
25
25
|
* } else {
|
|
26
26
|
* console.log(msg.role, msg.content);
|
|
27
27
|
* }
|
|
28
28
|
* }
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export type
|
|
32
|
-
| { role:
|
|
33
|
-
| { role:
|
|
34
|
-
| { role:
|
|
31
|
+
export type Message =
|
|
32
|
+
| { role: "user"; content: string; assets?: Asset[] }
|
|
33
|
+
| { role: "assistant"; content: string }
|
|
34
|
+
| { role: "assistant"; content: string; toolCalls: ToolCall[] }
|
|
35
|
+
| { role: "system"; content: string }
|
|
36
|
+
| { role: "tool"; name: string; content: string };
|
|
35
37
|
|
|
36
|
-
/** @internal Convert internal Message to
|
|
37
|
-
export function fromInternal(msg: InternalMessage):
|
|
38
|
-
if (msg.tag === Message_Tags.
|
|
39
|
-
const {
|
|
38
|
+
/** @internal Convert internal Message to Message */
|
|
39
|
+
export function fromInternal(msg: InternalMessage): Message {
|
|
40
|
+
if (msg.tag === Message_Tags.User) {
|
|
41
|
+
const { content, assets } = msg.inner;
|
|
40
42
|
return {
|
|
41
|
-
role:
|
|
43
|
+
role: "user",
|
|
42
44
|
content,
|
|
43
45
|
...(assets.length > 0 ? { assets } : {}),
|
|
44
46
|
};
|
|
45
|
-
} else if (msg.tag === Message_Tags.
|
|
46
|
-
const {
|
|
47
|
-
|
|
47
|
+
} else if (msg.tag === Message_Tags.Assistant) {
|
|
48
|
+
const { content, toolCalls } = msg.inner;
|
|
49
|
+
if (toolCalls != null && toolCalls.length > 0) {
|
|
50
|
+
return { role: "assistant", content, toolCalls };
|
|
51
|
+
}
|
|
52
|
+
return { role: "assistant", content };
|
|
53
|
+
} else if (msg.tag === Message_Tags.System) {
|
|
54
|
+
const { content } = msg.inner;
|
|
55
|
+
return { role: "system", content };
|
|
48
56
|
} else {
|
|
49
|
-
const {
|
|
50
|
-
return { role:
|
|
57
|
+
const { name, content } = msg.inner;
|
|
58
|
+
return { role: "tool", name, content };
|
|
51
59
|
}
|
|
52
60
|
}
|
|
53
61
|
|
|
54
|
-
/** @internal Convert
|
|
55
|
-
export function toInternal(msg:
|
|
56
|
-
if ("
|
|
57
|
-
return new InternalMessage.
|
|
58
|
-
|
|
62
|
+
/** @internal Convert Message to internal Message */
|
|
63
|
+
export function toInternal(msg: Message): InternalMessage {
|
|
64
|
+
if (msg.role === "user") {
|
|
65
|
+
return new InternalMessage.User({
|
|
66
|
+
content: msg.content,
|
|
67
|
+
assets: msg.assets ?? [],
|
|
68
|
+
});
|
|
69
|
+
} else if (msg.role === "assistant" && "toolCalls" in msg) {
|
|
70
|
+
return new InternalMessage.Assistant({
|
|
59
71
|
content: msg.content,
|
|
60
72
|
toolCalls: msg.toolCalls,
|
|
61
73
|
});
|
|
62
|
-
} else if ("
|
|
63
|
-
return new InternalMessage.
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
} else if (msg.role === "assistant") {
|
|
75
|
+
return new InternalMessage.Assistant({
|
|
76
|
+
content: msg.content,
|
|
77
|
+
toolCalls: null,
|
|
78
|
+
});
|
|
79
|
+
} else if (msg.role === "system") {
|
|
80
|
+
return new InternalMessage.System({
|
|
66
81
|
content: msg.content,
|
|
67
82
|
});
|
|
68
83
|
} else {
|
|
69
|
-
return new InternalMessage.
|
|
70
|
-
|
|
84
|
+
return new InternalMessage.Tool({
|
|
85
|
+
name: msg.name,
|
|
71
86
|
content: msg.content,
|
|
72
|
-
assets: msg.assets ?? [],
|
|
73
87
|
});
|
|
74
88
|
}
|
|
75
89
|
}
|
package/src/model.ts
CHANGED
|
@@ -39,16 +39,23 @@ export class Model {
|
|
|
39
39
|
* @param opts.modelPath - Path to the GGUF model file, or a `hf://owner/repo/file.gguf` / `https://` URL to download and cache automatically
|
|
40
40
|
* @param opts.useGpu - Use GPU acceleration if available (default: true)
|
|
41
41
|
* @param opts.projectionModelPath - Path to a multimodal projector file for vision models
|
|
42
|
+
* @param opts.onDownloadProgress - Invoked with `(downloaded, total)` byte counts while a remote model is being downloaded. Throttled to ~10 Hz with a guaranteed final emit on completion. Not invoked for cached/local files.
|
|
42
43
|
*/
|
|
43
44
|
static async load(opts: {
|
|
44
45
|
modelPath: string;
|
|
45
46
|
useGpu?: boolean;
|
|
46
47
|
projectionModelPath?: string;
|
|
48
|
+
onDownloadProgress?: (downloaded: number, total: number) => void;
|
|
47
49
|
}): Promise<Model> {
|
|
50
|
+
const cb = opts.onDownloadProgress;
|
|
51
|
+
const progressCallback = cb
|
|
52
|
+
? { onDownloadProgress: (d: bigint, t: bigint) => cb(Number(d), Number(t)) }
|
|
53
|
+
: undefined;
|
|
48
54
|
const inner = await loadModel(
|
|
49
55
|
opts.modelPath,
|
|
50
56
|
opts.useGpu ?? true,
|
|
51
57
|
opts.projectionModelPath,
|
|
58
|
+
progressCallback,
|
|
52
59
|
);
|
|
53
60
|
return new Model(inner);
|
|
54
61
|
}
|
package/src/wrapper.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This is the public entry point. It re-exports the public API:
|
|
5
5
|
* - Wrapper classes: Model, Chat, Encoder, CrossEncoder, Tool, TokenStream, Prompt
|
|
6
|
-
* - Direct re-exports: SamplerBuilder, SamplerConfig
|
|
7
|
-
* - Types:
|
|
6
|
+
* - Direct re-exports: SamplerBuilder, SamplerConfig
|
|
7
|
+
* - Types: Message, Asset, ToolCall
|
|
8
8
|
* - Utilities: SamplerPresets, cosineSimilarity
|
|
9
9
|
*
|
|
10
10
|
* This file is NOT generated — it is safe to edit.
|
|
@@ -20,13 +20,12 @@ export { Tool } from "./tool";
|
|
|
20
20
|
export { TokenStream } from "./streaming";
|
|
21
21
|
|
|
22
22
|
// Message types
|
|
23
|
-
export type {
|
|
23
|
+
export type { Message } from "./message";
|
|
24
24
|
|
|
25
25
|
// Re-export types that don't need wrapping.
|
|
26
26
|
export {
|
|
27
27
|
SamplerBuilder,
|
|
28
28
|
SamplerConfig,
|
|
29
|
-
Role,
|
|
30
29
|
cosineSimilarity,
|
|
31
30
|
} from "./index";
|
|
32
31
|
|