training queue
This commit is contained in:
@@ -145,7 +145,7 @@ export const fileDownload = ({
|
||||
* slideLen - The size of the before and after Text
|
||||
* maxLen > slideLen
|
||||
*/
|
||||
export const splitText_token = ({
|
||||
export const splitText_token = async ({
|
||||
text,
|
||||
maxLen,
|
||||
slideLen
|
||||
@@ -154,32 +154,39 @@ export const splitText_token = ({
|
||||
maxLen: number;
|
||||
slideLen: number;
|
||||
}) => {
|
||||
const enc = getOpenAiEncMap()['gpt-3.5-turbo'];
|
||||
// filter empty text. encode sentence
|
||||
const encodeText = enc.encode(text);
|
||||
try {
|
||||
const enc = getOpenAiEncMap()['gpt-3.5-turbo'];
|
||||
// filter empty text. encode sentence
|
||||
const encodeText = enc.encode(text);
|
||||
|
||||
const chunks: string[] = [];
|
||||
let tokens = 0;
|
||||
const chunks: string[] = [];
|
||||
let tokens = 0;
|
||||
|
||||
let startIndex = 0;
|
||||
let endIndex = Math.min(startIndex + maxLen, encodeText.length);
|
||||
let chunkEncodeArr = encodeText.slice(startIndex, endIndex);
|
||||
let startIndex = 0;
|
||||
let endIndex = Math.min(startIndex + maxLen, encodeText.length);
|
||||
let chunkEncodeArr = encodeText.slice(startIndex, endIndex);
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
while (startIndex < encodeText.length) {
|
||||
tokens += chunkEncodeArr.length;
|
||||
chunks.push(decoder.decode(enc.decode(chunkEncodeArr)));
|
||||
while (startIndex < encodeText.length) {
|
||||
tokens += chunkEncodeArr.length;
|
||||
chunks.push(decoder.decode(enc.decode(chunkEncodeArr)));
|
||||
|
||||
startIndex += maxLen - slideLen;
|
||||
endIndex = Math.min(startIndex + maxLen, encodeText.length);
|
||||
chunkEncodeArr = encodeText.slice(Math.min(encodeText.length - slideLen, startIndex), endIndex);
|
||||
startIndex += maxLen - slideLen;
|
||||
endIndex = Math.min(startIndex + maxLen, encodeText.length);
|
||||
chunkEncodeArr = encodeText.slice(
|
||||
Math.min(encodeText.length - slideLen, startIndex),
|
||||
endIndex
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
chunks,
|
||||
tokens
|
||||
};
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
return {
|
||||
chunks,
|
||||
tokens
|
||||
};
|
||||
};
|
||||
|
||||
export const fileToBase64 = (file: File) => {
|
||||
|
||||
@@ -26,7 +26,7 @@ export const authGoogleToken = async (data: {
|
||||
const res = await axios.post<{ score?: number }>(
|
||||
`https://www.recaptcha.net/recaptcha/api/siteverify?${Obj2Query(data)}`
|
||||
);
|
||||
if (res.data.score && res.data.score >= 0.9) {
|
||||
if (res.data.score && res.data.score >= 0.5) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
return Promise.reject('非法环境');
|
||||
|
||||
Reference in New Issue
Block a user