Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Administrator
/
chatgpt.ai-pro.org
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
3
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
d150f036
authored
2024-08-15 14:18:45 +0800
by
Marwin Cañeta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
#31531 - Apply tokenization logic on other LLMs
1 parent
25e620d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
11 deletions
index.js
index.js
View file @
d150f03
...
...
@@ -280,6 +280,7 @@ async function runOpensource(req, res) {
const
validate
=
await
validation
(
aiwp_app_id
,
req
,
res
);
if
(
!
validate
)
return
;
const
{
IS_FREE_USER
,
aiwp_logged_in
,
TRIED_USAGE
}
=
validate
;
let
usage
=
{};
try
{
let
error_msg
=
""
;
...
...
@@ -304,6 +305,7 @@ async function runOpensource(req, res) {
input
=
response
.
data
.
choices
[
0
].
message
.
content
}
usage
=
response
.
data
.
usage
}
catch
(
e
)
{
let
error_msg
=
e
.
response
.
data
.
error
.
message
?
e
.
response
.
data
.
error
.
message
:
''
;
if
(
error_msg
.
indexOf
(
'maximum context length'
)
>=
0
)
{
...
...
@@ -312,20 +314,10 @@ async function runOpensource(req, res) {
// console.log(e.response);
}
}
finally
{
let
usage
=
{};
let
enc
=
null
;
try
{
enc
=
encodingForModel
(
'gpt-3.5-turbo'
);
usage
.
prompt_tokens
=
(
enc
.
encode
(
query_prompt
)).
length
;
usage
.
completion_tokens
=
(
enc
.
encode
(
input
)).
length
;
usage
.
total_tokens
=
usage
.
prompt_tokens
+
usage
.
completion_tokens
;
}
catch
(
e
)
{
console
.
log
(
'Error encoding prompt text'
,
e
);
}
let
usage_params
=
{
"aiwp_logged_in"
:
aiwp_logged_in
,
"app"
:
"chatbot+"
,
"prompt_token"
:
usage
.
prompt_tokens
,
"total_token"
:
usage
.
total_tokens
,
"aiwp_app_id"
:
aiwp_app_id
,
"usage_tries"
:
TRIED_USAGE
};
if
(
IS_FREE_USER
)
{
await
setUsage
(
usage_params
);
}
else
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment