Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chatGLM
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
刘坚-丰林-DEV
chatGLM
Commits
6a27fa97
Commit
6a27fa97
authored
Apr 16, 2023
by
文旺-丰林-DEV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chat add promptword api
parent
8b542a3f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
96 deletions
+62
-96
content.tsx
src/pages/Chat/components/content.tsx
+42
-94
index.tsx
src/pages/Chat/index.tsx
+5
-2
api.ts
src/services/chatGLM/api.ts
+15
-0
No files found.
src/pages/Chat/components/content.tsx
View file @
6a27fa97
import
{
Row
,
Col
,
Grid
}
from
'antd'
;
import
type
{
FC
}
from
'react'
;
import
styles
from
'./content.less'
;
import
ProductionCard
from
'./productionCard'
;
const
{
useBreakpoint
}
=
Grid
;
interface
ChatFirstContentProps
{
onChange
?:
(
text
:
string
)
=>
void
;
}
const
ChatFirstContent
:
FC
<
ChatFirstContentProps
>
=
(
props
)
=>
{
const
{
onChange
}
=
props
;
const
screen
=
useBreakpoint
();
const
isMobile
=
screen
.
xs
;
const
cardList
=
[
{
title
:
'市场营销'
,
content
:
'请为我编写一个杨过大战钢铁侠的额电影脚本,要足够精彩,细节丰富,好像好莱坞大片,有场景有对话,叨叨剧本要求'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
title
:
'技术文档'
,
content
:
'请为我们的新款智能手表撰写一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
title
:
'灵感提示'
,
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
{
content
:
'请为我们的新款智能手表一份产品说明书,包括功能,使用方法和注意事项'
,
onclick
:
(
text
:
string
)
=>
{
onChange
&&
onChange
(
text
);
},
},
];
return
(
<
div
className=
{
styles
.
CardContent
}
>
<
Row
gutter=
{
1
}
>
{
cardList
.
map
((
item
,
index
)
=>
{
return
(
<
Col
lg=
{
8
}
md=
{
12
}
span=
{
8
}
xs=
{
24
}
sm=
{
16
}
key=
{
`${item.title}-card-${index}`
}
>
<
Row
justify=
{
isMobile
&&
'center'
}
className=
{
styles
.
cardPadding
}
>
<
ProductionCard
title=
{
item
.
title
}
content=
{
item
.
content
}
onChange=
{
item
.
onclick
}
/>
</
Row
>
</
Col
>
);
})
}
</
Row
>
</
div
>
);
};
export
default
ChatFirstContent
;
import
{
Row
,
Col
,
Grid
}
from
'antd'
;
import
type
{
FC
}
from
'react'
;
import
styles
from
'./content.less'
;
import
ProductionCard
from
'./productionCard'
;
import
{
IPromptWord
}
from
'@/services/chatGLM/api'
;
const
{
useBreakpoint
}
=
Grid
;
interface
ChatFirstContentProps
{
list
:
IPromptWord
[];
onChange
?:
(
text
:
string
)
=>
void
;
}
const
ChatFirstContent
:
FC
<
ChatFirstContentProps
>
=
(
props
)
=>
{
const
{
onChange
,
list
}
=
props
;
const
screen
=
useBreakpoint
();
const
isMobile
=
screen
.
xs
;
return
(
<
div
className=
{
styles
.
CardContent
}
>
<
Row
gutter=
{
1
}
>
{
list
.
map
((
item
,
index
)
=>
{
return
(
<
Col
lg=
{
8
}
md=
{
12
}
span=
{
8
}
xs=
{
24
}
sm=
{
16
}
key=
{
`${item.title}-card-${index}`
}
>
<
Row
justify=
{
isMobile
&&
'center'
}
className=
{
styles
.
cardPadding
}
>
<
ProductionCard
title=
{
item
.
title
}
content=
{
item
.
content
}
onChange=
{
()
=>
{
onChange
&&
onChange
(
item
.
content
);
}
}
/>
</
Row
>
</
Col
>
);
})
}
</
Row
>
</
div
>
);
};
export
default
ChatFirstContent
;
src/pages/Chat/index.tsx
View file @
6a27fa97
...
...
@@ -16,7 +16,7 @@ import { history } from 'umi';
import
LoginModal
from
'@/components/loginModal'
;
import
NewSession
from
'@/components/newSession'
;
import
{
useWebSocket
,
useRequest
}
from
'ahooks'
;
import
{
GetChatGLMToken
}
from
'@/services/chatGLM/api'
;
import
{
GetChatGLMToken
,
GetPromptList
}
from
'@/services/chatGLM/api'
;
const
{
useBreakpoint
}
=
Grid
;
const
{
Title
}
=
Typography
;
...
...
@@ -36,12 +36,15 @@ const Chat: React.FC = () => {
const
[
form
]
=
Form
.
useForm
();
const
[
selectSiderTabs
,
setSelectSiderTabs
]
=
useState
(
''
);
const
{
data
:
glmToken
}
=
useRequest
(
GetChatGLMToken
);
const
{
data
:
promptList
,
loading
:
promptLoading
}
=
useRequest
(
GetPromptList
);
const
[
answer
,
setAnswer
]
=
useState
(
''
);
const
[
loading
,
setLoading
]
=
useState
(
true
);
const
messageHistory
=
useRef
<
IHistory
[]
>
([]);
const
{
sendMessage
}
=
useWebSocket
(
'wss://glm-api.baibaomen.com/ws'
,
{
onMessage
:
(
event
)
=>
{
const
text
=
event
.
data
;
console
.
log
(
text
);
if
(
text
==
'{{BBMCPLT}}'
)
{
setLoading
(
false
);
}
else
{
...
...
@@ -251,7 +254,7 @@ const Chat: React.FC = () => {
)
:
(
<
div
className=
{
classNames
(
isMobile
&&
styles
.
mobileContent
)
}
>
<
Item
name=
"firstInput"
>
<
ChatFirstContent
/>
<
ChatFirstContent
list=
{
promptList
?.
items
||
[]
}
/>
</
Item
>
</
div
>
)
}
...
...
src/services/chatGLM/api.ts
View file @
6a27fa97
...
...
@@ -32,6 +32,10 @@ export function loginChatGLM(options: ILoginParams) {
});
}
export
interface
IPromptWord
{
title
:
string
;
content
:
string
;
}
export
function
GetChatGLMToken
():
Promise
<
string
>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/user/token'
,
{
method
:
'POST'
,
...
...
@@ -39,6 +43,17 @@ export function GetChatGLMToken(): Promise<string> {
});
}
export
function
GetPromptList
():
Promise
<
{
items
:
IPromptWord
[]
}
>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/promptwords/page'
,
{
method
:
'POST'
,
headers
:
{
Authorization
:
'Bearer '
+
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
''
)?.
token
,
'Content-Type'
:
'application/json'
,
},
body
:
JSON
.
stringify
({
pageIndex
:
0
,
pageSize
:
10
}),
});
}
type
History
=
[
string
,
string
];
interface
ITalkParams
{
prompt
:
string
;
...
...
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