Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
3e088f22
Commit
3e088f22
authored
1 year ago
by
timothycarambat
Browse files
Options
Downloads
Patches
Plain Diff
fix: Patch tiktoken method missing
resolves #541
parent
d95d1a9d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/utils/helpers/chat/index.js
+1
-1
1 addition, 1 deletion
server/utils/helpers/chat/index.js
server/utils/helpers/tiktoken.js
+10
-3
10 additions, 3 deletions
server/utils/helpers/tiktoken.js
with
11 additions
and
4 deletions
server/utils/helpers/chat/index.js
+
1
−
1
View file @
3e088f22
...
@@ -300,7 +300,7 @@ function cannonball({
...
@@ -300,7 +300,7 @@ function cannonball({
// if the delta is the token difference between where our prompt is in size
// if the delta is the token difference between where our prompt is in size
// and where we ideally need to land.
// and where we ideally need to land.
const
delta
=
initialInputSize
-
targetTokenSize
;
const
delta
=
initialInputSize
-
targetTokenSize
;
const
tokenChunks
=
tokenManager
.
count
FromString
(
input
);
const
tokenChunks
=
tokenManager
.
tokens
FromString
(
input
);
const
middleIdx
=
Math
.
floor
(
tokenChunks
.
length
/
2
);
const
middleIdx
=
Math
.
floor
(
tokenChunks
.
length
/
2
);
// middle truncate the text going left and right of midpoint
// middle truncate the text going left and right of midpoint
...
...
This diff is collapsed.
Click to expand it.
server/utils/helpers/tiktoken.js
+
10
−
3
View file @
3e088f22
...
@@ -15,15 +15,22 @@ class TokenManager {
...
@@ -15,15 +15,22 @@ class TokenManager {
}
}
}
}
// Pass in an empty array of disallowedSpecials to handle all tokens as text and to be tokenized.
// https://github.com/openai/tiktoken/blob/9e79899bc248d5313c7dd73562b5e211d728723d/tiktoken/core.py#L91C20-L91C38
// Returns number[]
tokensFromString
(
input
=
""
)
{
const
tokens
=
this
.
encoder
.
encode
(
input
,
undefined
,
[]);
return
tokens
;
}
bytesFromTokens
(
tokens
=
[])
{
bytesFromTokens
(
tokens
=
[])
{
const
bytes
=
this
.
encoder
.
decode
(
tokens
);
const
bytes
=
this
.
encoder
.
decode
(
tokens
);
return
bytes
;
return
bytes
;
}
}
// Pass in an empty array of disallowedSpecials to handle all tokens as text and to be tokenized.
// Returns number
// https://github.com/openai/tiktoken/blob/9e79899bc248d5313c7dd73562b5e211d728723d/tiktoken/core.py#L91C20-L91C38
countFromString
(
input
=
""
)
{
countFromString
(
input
=
""
)
{
const
tokens
=
this
.
encoder
.
encode
(
input
,
undefined
,
[]
);
const
tokens
=
this
.
tokensFromString
(
input
);
return
tokens
.
length
;
return
tokens
.
length
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment