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
52ac4455
authored
Sep 07, 2024
by
Archer
Committed by
GitHub
Sep 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: mobild sso login (#2636)
* fix: mobild sso login * feat: max call tool times
parent
d45cb2f8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
15 deletions
+64
-15
packages/service/core/workflow/dispatch/agent/runTool/index.ts
+1
-0
packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts
+21
-5
projects/app/src/pages/login/provider.tsx
+8
-3
projects/app/src/pages/login/sso.tsx
+34
-7
No files found.
packages/service/core/workflow/dispatch/agent/runTool/index.ts
View file @
52ac4455
...
@@ -134,6 +134,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
...
@@ -134,6 +134,7 @@ export const dispatchRunTools = async (props: DispatchToolModuleProps): Promise<
...
props
,
...
props
,
toolNodes
,
toolNodes
,
toolModel
,
toolModel
,
maxRunToolTimes
:
30
,
messages
:
adaptMessages
messages
:
adaptMessages
});
});
}
}
...
...
packages/service/core/workflow/dispatch/agent/runTool/toolChoice.ts
View file @
52ac4455
...
@@ -45,13 +45,12 @@ export const runToolWithToolChoice = async (
...
@@ -45,13 +45,12 @@ export const runToolWithToolChoice = async (
messages
:
ChatCompletionMessageParam
[];
messages
:
ChatCompletionMessageParam
[];
toolNodes
:
ToolNodeItemType
[];
toolNodes
:
ToolNodeItemType
[];
toolModel
:
LLMModelItemType
;
toolModel
:
LLMModelItemType
;
maxRunToolTimes
:
number
;
},
},
response
?:
RunToolResponse
response
?:
RunToolResponse
):
Promise
<
RunToolResponse
>
=>
{
):
Promise
<
RunToolResponse
>
=>
{
const
{
messages
,
toolNodes
,
toolModel
,
maxRunToolTimes
,
...
workflowProps
}
=
props
;
const
{
const
{
toolModel
,
toolNodes
,
messages
,
res
,
res
,
requestOrigin
,
requestOrigin
,
runtimeNodes
,
runtimeNodes
,
...
@@ -59,7 +58,12 @@ export const runToolWithToolChoice = async (
...
@@ -59,7 +58,12 @@ export const runToolWithToolChoice = async (
stream
,
stream
,
workflowStreamResponse
,
workflowStreamResponse
,
params
:
{
temperature
=
0
,
maxToken
=
4000
,
aiChatVision
}
params
:
{
temperature
=
0
,
maxToken
=
4000
,
aiChatVision
}
}
=
props
;
}
=
workflowProps
;
if
(
maxRunToolTimes
<=
0
&&
response
)
{
return
response
;
}
const
assistantResponses
=
response
?.
assistantResponses
||
[];
const
assistantResponses
=
response
?.
assistantResponses
||
[];
const
tools
:
ChatCompletionTool
[]
=
toolNodes
.
map
((
item
)
=>
{
const
tools
:
ChatCompletionTool
[]
=
toolNodes
.
map
((
item
)
=>
{
...
@@ -196,7 +200,7 @@ export const runToolWithToolChoice = async (
...
@@ -196,7 +200,7 @@ export const runToolWithToolChoice = async (
})();
})();
const
toolRunResponse
=
await
dispatchWorkFlow
({
const
toolRunResponse
=
await
dispatchWorkFlow
({
...
p
rops
,
...
workflowP
rops
,
isToolCall
:
true
,
isToolCall
:
true
,
runtimeNodes
:
runtimeNodes
.
map
((
item
)
=>
runtimeNodes
:
runtimeNodes
.
map
((
item
)
=>
item
.
nodeId
===
toolNode
.
nodeId
item
.
nodeId
===
toolNode
.
nodeId
...
@@ -252,11 +256,22 @@ export const runToolWithToolChoice = async (
...
@@ -252,11 +256,22 @@ export const runToolWithToolChoice = async (
role
:
ChatCompletionRequestMessageRoleEnum
.
Assistant
,
role
:
ChatCompletionRequestMessageRoleEnum
.
Assistant
,
tool_calls
:
toolCalls
tool_calls
:
toolCalls
};
};
/*
...
user
assistant: tool data
*/
const
concatToolMessages
=
[
const
concatToolMessages
=
[
...
requestMessages
,
...
requestMessages
,
assistantToolMsgParams
assistantToolMsgParams
]
as
ChatCompletionMessageParam
[];
]
as
ChatCompletionMessageParam
[];
const
tokens
=
await
countGptMessagesTokens
(
concatToolMessages
,
tools
);
const
tokens
=
await
countGptMessagesTokens
(
concatToolMessages
,
tools
);
/*
...
user
assistant: tool data
tool: tool response
*/
const
completeMessages
=
[
const
completeMessages
=
[
...
concatToolMessages
,
...
concatToolMessages
,
...
toolsRunResponse
.
map
((
item
)
=>
item
?.
toolMsgParams
)
...
toolsRunResponse
.
map
((
item
)
=>
item
?.
toolMsgParams
)
...
@@ -314,6 +329,7 @@ export const runToolWithToolChoice = async (
...
@@ -314,6 +329,7 @@ export const runToolWithToolChoice = async (
return
runToolWithToolChoice
(
return
runToolWithToolChoice
(
{
{
...
props
,
...
props
,
maxRunToolTimes
:
maxRunToolTimes
-
1
,
messages
:
completeMessages
messages
:
completeMessages
},
},
{
{
...
...
projects/app/src/pages/login/provider.tsx
View file @
52ac4455
import
React
,
{
useCallback
,
useEffect
}
from
'react'
;
import
React
,
{
useCallback
,
useEffect
,
useRef
}
from
'react'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
{
useSystemStore
}
from
'@/web/common/system/useSystemStore'
;
import
type
{
ResLogin
}
from
'@/global/support/api/userRes.d'
;
import
type
{
ResLogin
}
from
'@/global/support/api/userRes.d'
;
...
@@ -20,6 +20,7 @@ const provider = () => {
...
@@ -20,6 +20,7 @@ const provider = () => {
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
code
,
state
,
error
}
=
router
.
query
as
{
code
:
string
;
state
:
string
;
error
?:
string
};
const
{
code
,
state
,
error
}
=
router
.
query
as
{
code
:
string
;
state
:
string
;
error
?:
string
};
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
const
loading
=
useRef
(
false
);
const
loginSuccess
=
useCallback
(
const
loginSuccess
=
useCallback
(
(
res
:
ResLogin
)
=>
{
(
res
:
ResLogin
)
=>
{
...
@@ -41,6 +42,10 @@ const provider = () => {
...
@@ -41,6 +42,10 @@ const provider = () => {
const
authCode
=
useCallback
(
const
authCode
=
useCallback
(
async
(
code
:
string
)
=>
{
async
(
code
:
string
)
=>
{
if
(
loading
.
current
)
return
;
loading
.
current
=
true
;
if
(
!
loginStore
)
{
if
(
!
loginStore
)
{
router
.
replace
(
'/login'
);
router
.
replace
(
'/login'
);
return
;
return
;
...
@@ -73,7 +78,7 @@ const provider = () => {
...
@@ -73,7 +78,7 @@ const provider = () => {
},
1000
);
},
1000
);
}
}
},
},
[
loginStore
,
loginSuccess
,
router
,
toast
]
[
loginStore
,
loginSuccess
,
router
,
t
,
t
oast
]
);
);
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -103,7 +108,7 @@ const provider = () => {
...
@@ -103,7 +108,7 @@ const provider = () => {
}
else
{
}
else
{
authCode
(
code
);
authCode
(
code
);
}
}
},
[]);
},
[
authCode
,
code
,
error
,
loginStore
,
router
,
state
,
t
,
toast
]);
return
<
Loading
/>;
return
<
Loading
/>;
};
};
...
...
projects/app/src/pages/login/sso.tsx
View file @
52ac4455
import
React
,
{
useCallback
,
useEffect
,
useMemo
}
from
'react'
;
import
React
,
{
useCallback
,
useEffect
,
useMemo
,
useRef
}
from
'react'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
type
{
ResLogin
}
from
'@/global/support/api/userRes.d'
;
import
type
{
ResLogin
}
from
'@/global/support/api/userRes.d'
;
import
{
useChatStore
}
from
'@/web/core/chat/context/storeChat'
;
import
{
useChatStore
}
from
'@/web/core/chat/context/storeChat'
;
...
@@ -7,8 +7,9 @@ import { clearToken, setToken } from '@/web/support/user/auth';
...
@@ -7,8 +7,9 @@ import { clearToken, setToken } from '@/web/support/user/auth';
import
{
ssoLogin
}
from
'@/web/support/user/api'
;
import
{
ssoLogin
}
from
'@/web/support/user/api'
;
import
Loading
from
'@fastgpt/web/components/common/MyLoading'
;
import
Loading
from
'@fastgpt/web/components/common/MyLoading'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useTranslation
}
from
'next-i18next'
;
import
{
useRequest2
}
from
'@fastgpt/web/hooks/useRequest'
;
import
{
serviceSideProps
}
from
'@/web/common/utils/i18n'
;
import
{
serviceSideProps
}
from
'@/web/common/utils/i18n'
;
import
{
useToast
}
from
'@fastgpt/web/hooks/useToast'
;
import
{
getErrText
}
from
'@fastgpt/global/common/error/utils'
;
const
provider
=
()
=>
{
const
provider
=
()
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
...
@@ -16,6 +17,8 @@ const provider = () => {
...
@@ -16,6 +17,8 @@ const provider = () => {
const
{
setUserInfo
}
=
useUserStore
();
const
{
setUserInfo
}
=
useUserStore
();
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
query
}
=
router
;
const
{
query
}
=
router
;
const
loading
=
useRef
(
false
);
const
{
toast
}
=
useToast
();
const
loginSuccess
=
useCallback
(
const
loginSuccess
=
useCallback
(
(
res
:
ResLogin
)
=>
{
(
res
:
ResLogin
)
=>
{
...
@@ -30,17 +33,41 @@ const provider = () => {
...
@@ -30,17 +33,41 @@ const provider = () => {
[
setLastChatId
,
setLastChatAppId
,
setUserInfo
,
router
]
[
setLastChatId
,
setLastChatAppId
,
setUserInfo
,
router
]
);
);
const
{
run
:
handleSSO
}
=
useRequest2
(()
=>
ssoLogin
(
query
),
{
const
handleSSO
=
useCallback
(
async
()
=>
{
onSuccess
:
loginSuccess
,
if
(
loading
.
current
)
return
;
errorToast
:
t
(
'common:support.user.login.error'
)
loading
.
current
=
true
;
});
try
{
const
res
=
await
ssoLogin
(
query
);
if
(
!
res
)
{
toast
({
status
:
'warning'
,
title
:
t
(
'common:support.user.login.error'
)
});
return
setTimeout
(()
=>
{
router
.
replace
(
'/login'
);
},
1000
);
}
loginSuccess
(
res
);
}
catch
(
error
)
{
toast
({
status
:
'warning'
,
title
:
getErrText
(
error
,
t
(
'common:support.user.login.error'
))
});
setTimeout
(()
=>
{
router
.
replace
(
'/login'
);
},
1000
);
}
},
[
loginSuccess
,
query
,
router
,
t
,
toast
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
query
&&
Object
.
keys
(
query
).
length
>
0
)
{
if
(
query
&&
Object
.
keys
(
query
).
length
>
0
)
{
clearToken
();
clearToken
();
handleSSO
();
handleSSO
();
}
}
},
[]);
},
[
handleSSO
,
query
]);
return
<
Loading
/>;
return
<
Loading
/>;
};
};
...
...
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