Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-language bindings for tiktoken using polywrap wasm wrapper #36

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "1"
members = [
"tiktoken-rs",
"bindings/wrap"
]

[workspace.package]
Expand Down
26 changes: 26 additions & 0 deletions bindings/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

__pycache__/
.pytest_cache/
1 change: 1 addition & 0 deletions bindings/python/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.15.0
5 changes: 5 additions & 0 deletions bindings/python/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.formatting.provider": "black",
"python.analysis.typeCheckingMode": "strict",
"python.defaultInterpreterPath": "/Users/niraj/Library/Caches/pypoetry/virtualenvs/tiktoken-OAolDqPj-py3.10"
}
11 changes: 11 additions & 0 deletions bindings/python/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "template-app-python",
"private": true,
"scripts": {
"codegen": "npx polywrap codegen",
"test": "poetry run python -m tiktoken"
},
"devDependencies": {
"polywrap": "0.11.3"
}
}
2,059 changes: 2,059 additions & 0 deletions bindings/python/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions bindings/python/polywrap.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import * into Tiktoken from "fs/../wrap/build"
6 changes: 6 additions & 0 deletions bindings/python/polywrap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format: 0.4.0
project:
name: Tiktoken
type: app/python
source:
schema: ./polywrap.graphql
13 changes: 13 additions & 0 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "tiktoken"
version = "0.1.0"
description = "Python Tiktoken SDK"
authors = ["Cesar <[email protected]>", "Niraj <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
polywrap = "0.1.2"
5 changes: 5 additions & 0 deletions bindings/python/tiktoken/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .wrap import Tiktoken

__all__ = [
"Tiktoken",
]
21 changes: 21 additions & 0 deletions bindings/python/tiktoken/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .wrap import Tiktoken, TiktokenTokenizer


if __name__ == "__main__":
tiktoken = Tiktoken()

print("encode...")
encoded = tiktoken.encode_with_special_tokens({
"tokenizer": TiktokenTokenizer.P50kBase,
"text": "This is a test with a lot of spaces"
})

print("decode...")
decoded = tiktoken.decode({
"tokenizer": TiktokenTokenizer.P50kBase,
"tokens": encoded
})

print("encoded:", encoded)
print("decoded:", decoded)
assert decoded == "This is a test with a lot of spaces"
1 change: 1 addition & 0 deletions bindings/python/tiktoken/wrap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .types import *
Loading