Skip to content

Commit b676862

Browse files
committed
wip
1 parent f522ba2 commit b676862

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <ReactCommon/CallInvoker.h>
4+
#include <string>
5+
#include <tokenizers-cpp/tokenizers_cpp.h>
6+
7+
namespace rnexecutorch {
8+
using namespace facebook;
9+
10+
class TokenizerModule {
11+
public:
12+
std::unique_ptr<tokenizers::Tokenizer> tokenizer;
13+
TokenizerModule(std::string source,
14+
std::shared_ptr<react::CallInvoker> callInvoker);
15+
std::vector<int32_t> encode(std::string s);
16+
std::string decode(std::vector<int32_t> vec);
17+
int getMemoryLowerBound();
18+
};
19+
} // namespace rnexecutorch
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { ResourceSource } from '../../types/common';
2+
import { ResourceFetcher } from '../../utils/ResourceFetcher';
3+
4+
export class NewTokenizerModule {
5+
nativeModule: any;
6+
7+
async load(
8+
modelSource: ResourceSource,
9+
onDownloadProgressCallback: (_: number) => void = () => {}
10+
): Promise<void> {
11+
const paths = await ResourceFetcher.fetchMultipleResources(
12+
onDownloadProgressCallback,
13+
modelSource
14+
);
15+
console.log(paths);
16+
this.nativeModule = global.loadTokenizerModule(paths[0] || '');
17+
}
18+
19+
async encode(s: string) {
20+
return await this.nativeModule.encode(s);
21+
}
22+
23+
async decode(tokens: number[]) {
24+
return await this.nativeModule.decode(tokens);
25+
}
26+
}

0 commit comments

Comments
 (0)