Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webapp-conversation
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
webapp-conversation
Commits
4fa6b2c2
Commit
4fa6b2c2
authored
Aug 28, 2023
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
just add
parent
a96399ee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
4 deletions
+21
-4
common.ts
app/api/utils/common.ts
+2
-1
index.tsx
app/components/index.tsx
+3
-0
index.ts
config/index.ts
+2
-2
base.ts
service/base.ts
+10
-1
index.ts
service/index.ts
+4
-0
No files found.
app/api/utils/common.ts
View file @
4fa6b2c2
import
{
type
NextRequest
}
from
'next/server'
import
{
type
NextRequest
}
from
'next/server'
import
{
ChatClient
}
from
'dify-client'
import
{
ChatClient
,
DifyClient
}
from
'dify-client'
import
{
v4
}
from
'uuid'
import
{
v4
}
from
'uuid'
import
{
API_KEY
,
API_URL
,
APP_ID
}
from
'@/config'
import
{
API_KEY
,
API_URL
,
APP_ID
}
from
'@/config'
...
@@ -19,3 +19,4 @@ export const setSession = (sessionId: string) => {
...
@@ -19,3 +19,4 @@ export const setSession = (sessionId: string) => {
}
}
export
const
client
=
new
ChatClient
(
API_KEY
,
API_URL
||
undefined
)
export
const
client
=
new
ChatClient
(
API_KEY
,
API_URL
||
undefined
)
export
const
commonClient
=
new
ChatClient
(
API_KEY
,
API_URL
||
undefined
)
app/components/index.tsx
View file @
4fa6b2c2
...
@@ -19,6 +19,7 @@ import Loading from '@/app/components/base/loading'
...
@@ -19,6 +19,7 @@ import Loading from '@/app/components/base/loading'
import
{
replaceVarWithValues
,
userInputsFormToPromptVariables
}
from
'@/utils/prompt'
import
{
replaceVarWithValues
,
userInputsFormToPromptVariables
}
from
'@/utils/prompt'
import
AppUnavailable
from
'@/app/components/app-unavailable'
import
AppUnavailable
from
'@/app/components/app-unavailable'
import
{
API_KEY
,
APP_ID
,
APP_INFO
,
isShowPrompt
,
promptTemplate
}
from
'@/config'
import
{
API_KEY
,
APP_ID
,
APP_INFO
,
isShowPrompt
,
promptTemplate
}
from
'@/config'
import
{
checkOrSetAccessToken
}
from
'@/utils/access-token'
const
Main
:
FC
=
()
=>
{
const
Main
:
FC
=
()
=>
{
const
{
t
}
=
useTranslation
()
const
{
t
}
=
useTranslation
()
...
@@ -197,6 +198,8 @@ const Main: FC = () => {
...
@@ -197,6 +198,8 @@ const Main: FC = () => {
return
return
}
}
(
async
()
=>
{
(
async
()
=>
{
await
checkOrSetAccessToken
()
try
{
try
{
const
[
conversationData
,
appParams
]
=
await
Promise
.
all
([
fetchConversations
(),
fetchAppParams
()])
const
[
conversationData
,
appParams
]
=
await
Promise
.
all
([
fetchConversations
(),
fetchAppParams
()])
...
...
config/index.ts
View file @
4fa6b2c2
import
type
{
AppInfo
}
from
'@/types/app'
import
type
{
AppInfo
}
from
'@/types/app'
export
const
APP_ID
=
''
export
const
APP_ID
=
'
3caee4a2-273e-4686-b53e-59b4aaee8006
'
export
const
API_KEY
=
''
export
const
API_KEY
=
'
app-j0LqnaHykYouvz8PnYgldWcM
'
export
const
API_URL
=
''
export
const
API_URL
=
''
export
const
APP_INFO
:
AppInfo
=
{
export
const
APP_INFO
:
AppInfo
=
{
title
:
'Chat APP'
,
title
:
'Chat APP'
,
...
...
service/base.ts
View file @
4fa6b2c2
import
{
API_PREFIX
}
from
'@/config'
import
{
API_PREFIX
,
APP_ID
}
from
'@/config'
import
Toast
from
'@/app/components/base/toast'
import
Toast
from
'@/app/components/base/toast'
const
TIME_OUT
=
100000
const
TIME_OUT
=
100000
...
@@ -102,7 +102,16 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
...
@@ -102,7 +102,16 @@ const handleStream = (response: any, onData: IOnData, onCompleted?: IOnCompleted
const
baseFetch
=
(
url
:
string
,
fetchOptions
:
any
,
{
needAllResponseContent
}:
IOtherOptions
)
=>
{
const
baseFetch
=
(
url
:
string
,
fetchOptions
:
any
,
{
needAllResponseContent
}:
IOtherOptions
)
=>
{
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
const
options
=
Object
.
assign
({},
baseOptions
,
fetchOptions
)
const
sharedToken
=
APP_ID
const
accessToken
=
localStorage
.
getItem
(
'token'
)
||
JSON
.
stringify
({
[
sharedToken
]:
''
})
let
accessTokenJson
=
{
[
sharedToken
]:
''
}
try
{
accessTokenJson
=
JSON
.
parse
(
accessToken
)
}
catch
(
e
)
{
}
options
.
headers
.
set
(
'Authorization'
,
`Bearer
${
accessTokenJson
[
sharedToken
]}
`
)
const
urlPrefix
=
API_PREFIX
const
urlPrefix
=
API_PREFIX
let
urlWithPrefix
=
`
${
urlPrefix
}${
url
.
startsWith
(
'/'
)
?
url
:
`/
${
url
}
`
}
`
let
urlWithPrefix
=
`
${
urlPrefix
}${
url
.
startsWith
(
'/'
)
?
url
:
`/
${
url
}
`
}
`
...
...
service/index.ts
View file @
4fa6b2c2
...
@@ -31,3 +31,7 @@ export const fetchAppParams = async () => {
...
@@ -31,3 +31,7 @@ export const fetchAppParams = async () => {
export
const
updateFeedback
=
async
({
url
,
body
}:
{
url
:
string
;
body
:
Feedbacktype
})
=>
{
export
const
updateFeedback
=
async
({
url
,
body
}:
{
url
:
string
;
body
:
Feedbacktype
})
=>
{
return
post
(
url
,
{
body
})
return
post
(
url
,
{
body
})
}
}
export
const
fetchAccessToken
=
async
(
appId
:
string
)
=>
{
return
get
(
'/passport'
)
as
Promise
<
{
access_token
:
string
}
>
}
\ No newline at end of file
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