Skip to content

Commit

Permalink
plan count and replace invalid chars (#29)
Browse files Browse the repository at this point in the history
* fix: user oneapi

* fix: training queue

* fix: qa queue

* perf: remove space chars

* replace invalid chars
  • Loading branch information
c121914yu authored Feb 27, 2024
1 parent 964edba commit fe9dd36
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 473 deletions.
1 change: 1 addition & 0 deletions docSite/content/docs/development/upgrading/469.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ curl --location --request POST 'https://{{host}}/api/init/v469' \
3. 优化 - 问题补全。增加英文类型。同时可以设置为单独模块,方便复用。
4. 优化 - 重写了计量模式
5. 修复 - 标注功能。
6. 修复 - qa生成线程计数错误。
2 changes: 1 addition & 1 deletion docSite/content/docs/workflow/examples/dalle3.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Body:

Headers:

`Authorization: sk-xxx`
`Authorization: Bearer sk-xxx`

Response:

Expand Down
4 changes: 2 additions & 2 deletions packages/global/core/ai/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { LLMModelItemType, VectorModelItemType } from './model.d';

export const defaultQAModels: LLMModelItemType[] = [
{
model: 'gpt-3.5-turbo-16k',
name: 'gpt-3.5-turbo-16k',
model: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo',
maxContext: 16000,
maxResponse: 16000,
quoteMaxToken: 13000,
Expand Down
3 changes: 2 additions & 1 deletion packages/service/core/ai/embedding/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VectorModelItemType } from '@fastgpt/global/core/ai/model.d';
import { getAIApi } from '../config';
import { replaceValidChars } from '../../chat/utils';

type GetVectorProps = {
model: VectorModelItemType;
Expand Down Expand Up @@ -36,7 +37,7 @@ export async function getVectorsByText({ model, input }: GetVectorProps) {
}

return {
charsLength: input.length,
charsLength: replaceValidChars(input).length,
vectors: await Promise.all(res.data.map((item) => unityDimensional(item.embedding)))
};
});
Expand Down
8 changes: 6 additions & 2 deletions packages/service/core/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ export function ChatContextFilter({
return [...systemPrompts, ...chats];
}

export const replaceValidChars = (str: string) => {
const reg = /[\s\r\n]+/g;
return str.replace(reg, '');
};
export const countMessagesChars = (messages: ChatItemType[]) => {
return messages.reduce((sum, item) => sum + item.value.length, 0);
return messages.reduce((sum, item) => sum + replaceValidChars(item.value).length, 0);
};
export const countGptMessagesChars = (messages: ChatMessageItemType[]) =>
messages.reduce((sum, item) => sum + item.content.length, 0);
messages.reduce((sum, item) => sum + replaceValidChars(item.content).length, 0);

/**
string to vision model. Follow the markdown code block rule for interception:
Expand Down
Loading

0 comments on commit fe9dd36

Please sign in to comment.