Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
048f5a2d
authored
Dec 11, 2024
by
Archer
Committed by
GitHub
Dec 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: emb page cannot save lng;feat: Add classify error log (#3367)
* fix: emb page cannot save lng * perf: i18n check
parent
096afef6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
16 deletions
+29
-16
packages/service/core/workflow/dispatch/agent/classifyQuestion.ts
+6
-1
packages/web/hooks/useI18n.ts
+23
-15
No files found.
packages/service/core/workflow/dispatch/agent/classifyQuestion.ts
View file @
048f5a2d
...
@@ -18,6 +18,7 @@ import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt';
...
@@ -18,6 +18,7 @@ import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt';
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
getHandleId
}
from
'@fastgpt/global/core/workflow/utils'
;
import
{
loadRequestMessages
}
from
'../../../chat/utils'
;
import
{
loadRequestMessages
}
from
'../../../chat/utils'
;
import
{
llmCompletionsBodyFormat
}
from
'../../../ai/utils'
;
import
{
llmCompletionsBodyFormat
}
from
'../../../ai/utils'
;
import
{
addLog
}
from
'../../../../common/system/log'
;
type
Props
=
ModuleDispatchProps
<
{
type
Props
=
ModuleDispatchProps
<
{
[
NodeInputKeyEnum
.
aiModel
]:
string
;
[
NodeInputKeyEnum
.
aiModel
]:
string
;
...
@@ -65,7 +66,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
...
@@ -65,7 +66,7 @@ export const dispatchClassifyQuestion = async (props: Props): Promise<CQResponse
return
{
return
{
[
NodeOutputKeyEnum
.
cqResult
]:
result
.
value
,
[
NodeOutputKeyEnum
.
cqResult
]:
result
.
value
,
[
DispatchNodeResponseKeyEnum
.
skipHandleId
]:
agents
[
DispatchNodeResponseKeyEnum
.
skipHandleId
]:
agents
.
filter
((
item
)
=>
item
.
key
!==
arg
?.
type
)
.
filter
((
item
)
=>
item
.
key
!==
result
.
key
)
.
map
((
item
)
=>
getHandleId
(
nodeId
,
'source'
,
item
.
key
)),
.
map
((
item
)
=>
getHandleId
(
nodeId
,
'source'
,
item
.
key
)),
[
DispatchNodeResponseKeyEnum
.
nodeResponse
]:
{
[
DispatchNodeResponseKeyEnum
.
nodeResponse
]:
{
totalPoints
:
user
.
openaiAccount
?.
key
?
0
:
totalPoints
,
totalPoints
:
user
.
openaiAccount
?.
key
?
0
:
totalPoints
,
...
@@ -142,6 +143,10 @@ const completions = async ({
...
@@ -142,6 +143,10 @@ const completions = async ({
agents
.
find
((
item
)
=>
answer
.
includes
(
item
.
value
))?.
key
||
agents
.
find
((
item
)
=>
answer
.
includes
(
item
.
value
))?.
key
||
''
;
''
;
if
(
!
id
)
{
addLog
.
warn
(
'Classify error'
,
{
answer
});
}
return
{
return
{
tokens
:
await
countMessagesTokens
(
messages
),
tokens
:
await
countMessagesTokens
(
messages
),
arg
:
{
type
:
id
}
arg
:
{
type
:
id
}
...
...
packages/web/hooks/useI18n.ts
View file @
048f5a2d
import
Cookies
,
{
CookieAttributes
}
from
'js-cookie'
;
import
Cookies
from
'js-cookie'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
LangEnum
}
from
'../../../projects/app/src/web/common/utils/i18n'
;
import
{
LangEnum
}
from
'../../../projects/app/src/web/common/utils/i18n'
;
const
setCookie
=
(
key
:
string
,
value
:
string
,
options
?:
CookieAttributes
)
=>
{
const
LANG_KEY
=
'NEXT_LOCALE'
;
Cookies
.
set
(
key
,
value
,
options
);
const
isInIframe
=
()
=>
{
try
{
return
window
.
self
!==
window
.
top
;
}
catch
(
e
)
{
return
true
;
}
};
};
const
getCookie
=
(
key
:
string
)
=>
{
const
setLang
=
(
value
:
string
)
=>
{
return
Cookies
.
get
(
key
);
if
(
isInIframe
())
{
localStorage
.
setItem
(
LANG_KEY
,
value
);
}
else
{
// 不在 iframe 中,同时使用 Cookie 和 localStorage
Cookies
.
set
(
LANG_KEY
,
value
,
{
expires
:
30
});
localStorage
.
setItem
(
LANG_KEY
,
value
);
}
};
const
getLang
=
()
=>
{
return
localStorage
.
getItem
(
LANG_KEY
)
||
Cookies
.
get
(
LANG_KEY
);
};
};
const
LANG_KEY
=
'NEXT_LOCALE'
;
export
const
useI18nLng
=
()
=>
{
export
const
useI18nLng
=
()
=>
{
const
{
i18n
}
=
useTranslation
();
const
{
i18n
}
=
useTranslation
();
...
@@ -26,23 +38,19 @@ export const useI18nLng = () => {
...
@@ -26,23 +38,19 @@ export const useI18nLng = () => {
const
onChangeLng
=
async
(
lng
:
string
)
=>
{
const
onChangeLng
=
async
(
lng
:
string
)
=>
{
const
lang
=
languageMap
[
lng
]
||
'en'
;
const
lang
=
languageMap
[
lng
]
||
'en'
;
const
prevLang
=
getLang
();
setCookie
(
LANG_KEY
,
lang
,
{
setLang
(
lang
);
expires
:
30
});
const
currentLng
=
i18n
?.
language
;
if
(
!
currentLng
)
return
;
await
i18n
?.
changeLanguage
?.(
lang
);
await
i18n
?.
changeLanguage
?.(
lang
);
if
(
currentL
ng
!==
lang
)
{
if
(
prevLang
&&
prevLa
ng
!==
lang
)
{
window
?.
location
?.
reload
?.();
window
?.
location
?.
reload
?.();
}
}
};
};
const
setUserDefaultLng
=
()
=>
{
const
setUserDefaultLng
=
()
=>
{
if
(
!
navigator
||
!
localStorage
)
return
;
if
(
!
navigator
||
!
localStorage
)
return
;
if
(
get
Cookie
(
LANG_KEY
))
return
onChangeLng
(
getCookie
(
LANG_KEY
)
as
string
);
if
(
get
Lang
())
return
onChangeLng
(
getLang
(
)
as
string
);
const
lang
=
languageMap
[
navigator
.
language
]
||
'en'
;
const
lang
=
languageMap
[
navigator
.
language
]
||
'en'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment