Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chat-query
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
jaden
chat-query
Commits
907203ba
Commit
907203ba
authored
Jul 18, 2023
by
jaden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix bug: cancel、input text、check
parent
1118e560
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
190 additions
and
78 deletions
+190
-78
client/api/openAI.ts
client/api/openAI.ts
+10
-5
components/AITool/index.tsx
components/AITool/index.tsx
+128
-60
next-i18next.config.js
next-i18next.config.js
+19
-0
pages/actions/View/chatView.tsx
pages/actions/View/chatView.tsx
+26
-11
pages/actions/index.tsx
pages/actions/index.tsx
+7
-2
No files found.
client/api/openAI.ts
View file @
907203ba
...
@@ -34,7 +34,7 @@ type message = {
...
@@ -34,7 +34,7 @@ type message = {
export
default
class
OpenAI
{
export
default
class
OpenAI
{
static
async
request
(
static
async
request
(
messages
:
message
[],
messages
:
message
[],
onFinish
:
(
responseText
:
string
)
=>
any
,
onFinish
:
(
responseText
:
string
,
cancel
?:
boolean
)
=>
any
,
onUpdate
:
(
responseText
:
string
,
delta
:
string
)
=>
any
,
onUpdate
:
(
responseText
:
string
,
delta
:
string
)
=>
any
,
onError
:
(
e
:
Error
)
=>
any
,
onError
:
(
e
:
Error
)
=>
any
,
functions
:
any
[],
functions
:
any
[],
...
@@ -65,8 +65,12 @@ export default class OpenAI {
...
@@ -65,8 +65,12 @@ export default class OpenAI {
},
},
};
};
const
requestTimeoutId
=
setTimeout
(()
=>
controller
.
abort
(),
1000
*
120
);
const
requestTimeoutId
=
setTimeout
(()
=>
controller
.
abort
(),
1000
*
120
);
const
chatPath
=
'
/openai/v1/chat/completions
'
;
const
chatPath
=
'
/openai/v1/chat/completions
'
;
if
(
closeFn
)
{
if
(
closeFn
)
{
controller
.
signal
.
onabort
=
()
=>
{
onFinish
(
''
,
true
);
};
closeFn
.
current
=
()
=>
{
closeFn
.
current
=
()
=>
{
clearTimeout
(
requestTimeoutId
);
clearTimeout
(
requestTimeoutId
);
controller
.
abort
();
controller
.
abort
();
...
@@ -75,13 +79,15 @@ export default class OpenAI {
...
@@ -75,13 +79,15 @@ export default class OpenAI {
if
(
stream
)
{
if
(
stream
)
{
let
responseText
=
''
;
let
responseText
=
''
;
let
finished
=
false
;
let
finished
=
false
;
const
finish
=
()
=>
{
const
finish
=
(
cancel
?:
boolean
)
=>
{
if
(
!
finished
)
{
if
(
!
finished
)
{
onFinish
(
responseText
);
onFinish
(
responseText
,
cancel
);
finished
=
true
;
finished
=
true
;
}
}
};
};
controller
.
signal
.
onabort
=
finish
;
controller
.
signal
.
onabort
=
()
=>
{
finish
(
true
);
};
fetchEventSource
(
chatPath
,
{
fetchEventSource
(
chatPath
,
{
...
chatPayload
,
...
chatPayload
,
async
onopen
(
res
)
{
async
onopen
(
res
)
{
...
@@ -152,7 +158,6 @@ export default class OpenAI {
...
@@ -152,7 +158,6 @@ export default class OpenAI {
const
message
=
const
message
=
resJson
.
choices
?.
at
(
0
)?.
message
?.
content
??
resJson
.
choices
?.
at
(
0
)?.
message
?.
content
??
(
JSON
.
stringify
(
get
(
resJson
,
'
choices[0].message.function_call
'
))
||
''
);
(
JSON
.
stringify
(
get
(
resJson
,
'
choices[0].message.function_call
'
))
||
''
);
console
.
log
(
message
);
onFinish
(
message
);
onFinish
(
message
);
}
}
}
}
...
...
components/AITool/index.tsx
View file @
907203ba
This diff is collapsed.
Click to expand it.
next-i18next.config.js
View file @
907203ba
...
@@ -152,6 +152,9 @@ i18n.use(LanguageDetector)
...
@@ -152,6 +152,9 @@ i18n.use(LanguageDetector)
'
Execution succeeded
'
:
'
执行成功
'
,
'
Execution succeeded
'
:
'
执行成功
'
,
'
Analyzing requirements
'
:
'
分析需求中
'
,
'
Analyzing requirements
'
:
'
分析需求中
'
,
'
Creating query
'
:
'
创建查询中
'
,
'
Creating query
'
:
'
创建查询中
'
,
'
Query generation in progress
'
:
'
正在生成查询
'
,
'
Reviewing and checking if query aligns with requirements
'
:
'
正在审核查询是否满足需求
'
,
'
Hello! I an CHAT QUERY ai, please describe your business!
'
:
'
Hello! I an CHAT QUERY ai, please describe your business!
'
:
'
您好!我是 CHAT QUERY AI,请描述您的业务!
'
,
'
您好!我是 CHAT QUERY AI,请描述您的业务!
'
,
'
Connection Name
'
:
'
连接名称
'
,
'
Connection Name
'
:
'
连接名称
'
,
...
@@ -166,6 +169,13 @@ i18n.use(LanguageDetector)
...
@@ -166,6 +169,13 @@ i18n.use(LanguageDetector)
_QUERY_
:
'
_查询_
'
,
_QUERY_
:
'
_查询_
'
,
'
Failed to generate query
'
:
'
生成查询失败
'
,
'
Failed to generate query
'
:
'
生成查询失败
'
,
'
Error in query
'
:
'
错误查询
'
,
'
Error in query
'
:
'
错误查询
'
,
Cancel
:
'
取消
'
,
'
Cannot generate executable query from the requirement description, please continue to describe the requirement!
'
:
'
从需求描述中不能为您生成可执行的查询,请继续描述的需求!
'
,
'
Requirements and answers do not align
'
:
'
需求和回答没有对齐
'
,
'
Requirements and answers do not align, rethinking
'
:
'
需求和回答没有对齐,重新思考中
'
,
'
Reviewing requirements and answers
'
:
'
正在审查需求和回答
'
,
},
},
modal
:
{
modal
:
{
Import
:
'
导入
'
,
Import
:
'
导入
'
,
...
@@ -211,6 +221,15 @@ i18n.use(LanguageDetector)
...
@@ -211,6 +221,15 @@ i18n.use(LanguageDetector)
},
},
chatView
:
{
chatView
:
{
'
component display
'
:
'
组件显示
'
,
'
component display
'
:
'
组件显示
'
,
'
Function for processing data
'
:
'
处理数据的函数
'
,
'
Add component
'
:
'
添加组件
'
,
'
Code generation in progress, please wait...
'
:
'
代码生成中,请稍后...
'
,
'
Data processing
'
:
'
数据处理
'
,
'
Comment + Tab to generate function
'
:
'
注释 + Tab 生成函数
'
,
'
Execute function name
'
:
'
执行函数名称
'
,
'
No function description available
'
:
'
暂无函数描述
'
,
Run
:
'
运行
'
,
'
Execution successful
'
:
'
执行成功
'
,
},
},
},
},
},
},
...
...
pages/actions/View/chatView.tsx
View file @
907203ba
...
@@ -53,6 +53,7 @@ import 'systemjs';
...
@@ -53,6 +53,7 @@ import 'systemjs';
import
dayjs
from
'
dayjs
'
;
import
dayjs
from
'
dayjs
'
;
import
{
simple
}
from
'
acorn-walk
'
;
import
{
simple
}
from
'
acorn-walk
'
;
import
jsx
from
'
acorn-jsx
'
;
import
jsx
from
'
acorn-jsx
'
;
import
i18n
from
'
@/next-i18next.config
'
;
const
CollapseItem
=
Collapse
.
Item
;
const
CollapseItem
=
Collapse
.
Item
;
...
@@ -65,11 +66,16 @@ function Error() {
...
@@ -65,11 +66,16 @@ function Error() {
return
<
code
>
{
error
}
</
code
>;
return
<
code
>
{
error
}
</
code
>;
}
}
const
init
=
`/**
// const initText = i18n.getFixedT(i18n.language, 'chatView')('Function for processing data');
* @description 处理数据的函数
const
init
=
(
initText
:
string
):
string
=>
{
return
`/**
* @description
${
initText
}
* @param record<string,any> data
* @param record<string,any> data
*/
*/
`
;
`
;
};
async
function
getUMDPath
(
packageName
:
string
)
{
async
function
getUMDPath
(
packageName
:
string
)
{
const
response
=
await
fetch
(
`https://data.jsdelivr.com/v1/packages/npm/
${
packageName
}
`
);
const
response
=
await
fetch
(
`https://data.jsdelivr.com/v1/packages/npm/
${
packageName
}
`
);
const
packageJson
=
await
response
.
json
();
const
packageJson
=
await
response
.
json
();
...
@@ -140,6 +146,8 @@ async function loadUMDModuleBySystem(packageName: string) {
...
@@ -140,6 +146,8 @@ async function loadUMDModuleBySystem(packageName: string) {
function
ReactView
({
props
}:
{
props
:
Record
<
string
,
any
>
})
{
function
ReactView
({
props
}:
{
props
:
Record
<
string
,
any
>
})
{
const
{
code
}
=
useLiveContext
();
const
{
code
}
=
useLiveContext
();
const
{
t
}
=
useTranslation
(
'
chatView
'
);
return
(
return
(
<
div
>
<
div
>
<
div
className=
"flex justify-end my-[5px]"
>
<
div
className=
"flex justify-end my-[5px]"
>
...
@@ -161,7 +169,7 @@ function ReactView({ props }: { props: Record<string, any> }) {
...
@@ -161,7 +169,7 @@ function ReactView({ props }: { props: Record<string, any> }) {
}
}
}
}
}
}
>
>
<
IconPlus
/>
添加组件
<
IconPlus
/>
{
t
(
'
Add component
'
)
}
</
Button
>
</
Button
>
</
div
>
</
div
>
<
LivePreview
className=
"overflow-auto min-h-[350px]"
/>
<
LivePreview
className=
"overflow-auto min-h-[350px]"
/>
...
@@ -173,7 +181,7 @@ export function ChatView({
...
@@ -173,7 +181,7 @@ export function ChatView({
defaultNode
,
defaultNode
,
props
:
propsRaw
,
props
:
propsRaw
,
id
,
id
,
functions
=
init
,
functions
=
''
,
}:
{
}:
{
defaultNode
?:
ReactElement
;
defaultNode
?:
ReactElement
;
props
:
Record
<
string
,
any
>
;
props
:
Record
<
string
,
any
>
;
...
@@ -271,6 +279,7 @@ export function ChatView({
...
@@ -271,6 +279,7 @@ export function ChatView({
const
example
=
get
(
data
,
'
data.code
'
);
const
example
=
get
(
data
,
'
data.code
'
);
const
{
t
}
=
useTranslation
(
'
chatView
'
);
const
{
t
}
=
useTranslation
(
'
chatView
'
);
functions
=
functions
||
init
(
t
(
'
Function for processing data
'
));
const
Live
=
useMemo
(()
=>
{
const
Live
=
useMemo
(()
=>
{
let
node
;
let
node
;
...
@@ -323,7 +332,7 @@ export function ChatView({
...
@@ -323,7 +332,7 @@ export function ChatView({
const
position
=
editor
.
getPosition
()
!
;
const
position
=
editor
.
getPosition
()
!
;
const
lineNumber
=
position
.
lineNumber
;
const
lineNumber
=
position
.
lineNumber
;
const
column
=
position
.
column
;
const
column
=
position
.
column
;
const
insertText
=
'
代码生成中,请稍后...
'
;
const
insertText
=
` `
+
t
(
'
Code generation in progress, please wait...
'
)
;
const
op
=
{
const
op
=
{
range
:
new
monaco
.
Range
(
lineNumber
,
column
,
lineNumber
,
column
),
range
:
new
monaco
.
Range
(
lineNumber
,
column
,
lineNumber
,
column
),
text
:
insertText
,
text
:
insertText
,
...
@@ -406,9 +415,9 @@ export function ChatView({
...
@@ -406,9 +415,9 @@ export function ChatView({
<
CollapseItem
<
CollapseItem
header=
{
header=
{
<
div
>
<
div
>
数据处理
{
t
(
'
Data processing
'
)
}
<
span
className=
"text-[var(--pc)] mx-[10px] text-[12px]"
>
<
span
className=
"text-[var(--pc)] mx-[10px] text-[12px]"
>
(
注释 + Tab 生成函数
)
(
{
t
(
'
Comment + Tab to generate function
'
)
}
)
</
span
>
</
span
>
</
div
>
</
div
>
}
}
...
@@ -416,7 +425,7 @@ export function ChatView({
...
@@ -416,7 +425,7 @@ export function ChatView({
extra=
{
extra=
{
<
div
className=
"flex"
>
<
div
className=
"flex"
>
<
Select
<
Select
placeholder=
"执行函数名称"
placeholder=
{
t
(
'
Execute function name
'
)
}
size=
"mini"
size=
"mini"
allowClear
allowClear
style=
{
{
style=
{
{
...
@@ -465,7 +474,9 @@ export function ChatView({
...
@@ -465,7 +474,9 @@ export function ChatView({
{
get
(
{
get
(
item
,
item
,
'
comment
'
,
'
comment
'
,
'
暂无函数描述
'
t
(
'
No function description available
'
)
)
}
)
}
</
span
>
</
span
>
</
Tooltip
>
</
Tooltip
>
...
@@ -497,7 +508,7 @@ export function ChatView({
...
@@ -497,7 +508,7 @@ export function ChatView({
size=
"mini"
size=
"mini"
shape=
"round"
shape=
"round"
>
>
运行
{
t
(
'
Run
'
)
}
</
Button
>
</
Button
>
</
div
>
</
div
>
}
}
...
@@ -516,7 +527,11 @@ export function ChatView({
...
@@ -516,7 +527,11 @@ export function ChatView({
</
div
>
</
div
>
</>
</>
)
:
(
)
:
(
<
Alert
style=
{
{
marginBottom
:
20
}
}
type=
"success"
content=
"执行成功"
/>
<
Alert
style=
{
{
marginBottom
:
20
}
}
type=
"success"
content=
{
t
(
'
Execution successful
'
)
}
/>
)
}
)
}
<
Spin
loading=
{
isMutating
}
block
className=
"my-[20px]"
>
<
Spin
loading=
{
isMutating
}
block
className=
"my-[20px]"
>
{
example
&&
!
showTable
?
(
{
example
&&
!
showTable
?
(
...
...
pages/actions/index.tsx
View file @
907203ba
...
@@ -520,7 +520,9 @@ const MessageItemHOC = ({ setShowQueriesList, activeDb, currentModels, activeMod
...
@@ -520,7 +520,9 @@ const MessageItemHOC = ({ setShowQueriesList, activeDb, currentModels, activeMod
<
Alert
<
Alert
content=
{
content=
{
<
div
className=
"text-[#7e7d7d]"
>
<
div
className=
"text-[#7e7d7d]"
>
从需求描述中不能为您生成可执行的查询,请继续描述的需求!
{
t
(
'
Cannot generate executable query from the requirement description, please continue to describe the requirement!
'
)
}
</
div
>
</
div
>
}
}
/>
/>
...
@@ -656,7 +658,10 @@ export default function Actions() {
...
@@ -656,7 +658,10 @@ export default function Actions() {
try
{
try
{
const
data
=
await
getAllGraphs
();
const
data
=
await
getAllGraphs
();
if
(
data
&&
data
.
length
)
{
if
(
data
&&
data
.
length
)
{
data
.
sort
((
a
,
b
)
=>
b
.
createdAt
-
a
.
createdAt
);
data
.
sort
(
(
a
:
{
createdAt
:
number
},
b
:
{
createdAt
:
number
})
=>
b
.
createdAt
-
a
.
createdAt
);
setGraphs
(
data
);
setGraphs
(
data
);
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
...
...
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