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
3e321e59
Commit
3e321e59
authored
Jul 13, 2023
by
jaden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve: improve
parent
2b091cd3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
18 deletions
+58
-18
client/api/openAI.ts
client/api/openAI.ts
+8
-0
components/AITool/index.tsx
components/AITool/index.tsx
+41
-15
pages/actions/View/chatView.tsx
pages/actions/View/chatView.tsx
+8
-3
pages/actions/index.tsx
pages/actions/index.tsx
+1
-0
No files found.
client/api/openAI.ts
View file @
3e321e59
...
@@ -2,6 +2,7 @@ import getConfig from 'next/config';
...
@@ -2,6 +2,7 @@ import getConfig from 'next/config';
import
{
backendApi
}
from
'
.
'
;
import
{
backendApi
}
from
'
.
'
;
import
{
getModel
}
from
'
@/utils/gpt
'
;
import
{
getModel
}
from
'
@/utils/gpt
'
;
import
{
fetchEventSource
,
EventStreamContentType
}
from
'
@microsoft/fetch-event-source
'
;
import
{
fetchEventSource
,
EventStreamContentType
}
from
'
@microsoft/fetch-event-source
'
;
import
{
MutableRefObject
,
SetStateAction
}
from
'
react
'
;
export
interface
View
{
export
interface
View
{
type
:
'
schema
'
|
'
table
'
;
type
:
'
schema
'
|
'
table
'
;
...
@@ -35,6 +36,7 @@ export default class OpenAI {
...
@@ -35,6 +36,7 @@ export default class OpenAI {
onFinish
:
(
responseText
:
string
)
=>
any
,
onFinish
:
(
responseText
:
string
)
=>
any
,
onUpdate
:
(
responseText
:
string
,
delta
:
string
)
=>
any
,
onUpdate
:
(
responseText
:
string
,
delta
:
string
)
=>
any
,
onError
:
(
e
:
Error
)
=>
any
,
onError
:
(
e
:
Error
)
=>
any
,
closeFn
?:
MutableRefObject
<
any
>
,
stream
:
boolean
=
true
stream
:
boolean
=
true
)
{
)
{
const
requestPayload
=
{
const
requestPayload
=
{
...
@@ -59,6 +61,12 @@ export default class OpenAI {
...
@@ -59,6 +61,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
)
{
closeFn
.
current
=
()
=>
{
clearTimeout
(
requestTimeoutId
);
controller
.
abort
();
};
}
if
(
stream
)
{
if
(
stream
)
{
let
responseText
=
''
;
let
responseText
=
''
;
let
finished
=
false
;
let
finished
=
false
;
...
...
components/AITool/index.tsx
View file @
3e321e59
...
@@ -49,6 +49,7 @@ type AIProps = {
...
@@ -49,6 +49,7 @@ type AIProps = {
searchFlag
?:
RegExp
;
searchFlag
?:
RegExp
;
inputProps
?:
Record
<
string
,
any
>
;
inputProps
?:
Record
<
string
,
any
>
;
SendButton
?:
({
inputRef
}:
{
inputRef
:
any
})
=>
JSX
.
Element
;
SendButton
?:
({
inputRef
}:
{
inputRef
:
any
})
=>
JSX
.
Element
;
noHistory
?:
boolean
;
};
};
export
function
AIWrapper
({
export
function
AIWrapper
({
...
@@ -66,6 +67,7 @@ export function AIWrapper({
...
@@ -66,6 +67,7 @@ export function AIWrapper({
searchFlag
=
/^
\/
/
,
searchFlag
=
/^
\/
/
,
inputProps
=
{},
inputProps
=
{},
SendButton
,
SendButton
,
noHistory
,
}:
AIProps
)
{
}:
AIProps
)
{
const
input
=
useRef
<
any
>
();
const
input
=
useRef
<
any
>
();
const
scrollContainer
=
useRef
<
any
>
();
const
scrollContainer
=
useRef
<
any
>
();
...
@@ -87,16 +89,30 @@ export function AIWrapper({
...
@@ -87,16 +89,30 @@ export function AIWrapper({
},
},
]);
]);
setCurrentAssistantMessage
(
''
);
setCurrentAssistantMessage
(
''
);
toView
();
// return clearContext;
// return clearContext;
},
[
currentAssistantMessage
,
loading
]);
},
[
currentAssistantMessage
,
loading
]);
const
closeRef
=
useRef
<
any
>
();
const
close
=
()
=>
{
closeRef
.
current
&&
closeRef
.
current
();
// setCurrentAssistantMessage('');
// requestAnimationFrame(() => {
// setLoading(false);
// });
};
const
toView
=
useCallback
(
const
toView
=
useCallback
(
debounce
(()
=>
{
debounce
(
scrollContainer
&&
()
=>
{
scrollContainer
?.
current
?.
scrollIntoView
({
scrollContainer
&&
behavior
:
'
smooth
'
,
scrollContainer
?.
current
?.
scrollIntoView
({
block
:
'
end
'
,
behavior
:
'
smooth
'
,
});
block
:
'
end
'
,
},
50
),
});
},
50
,
{
maxWait
:
500
}
),
[]
[]
);
);
const
handleButtonClick
=
useCallback
(
const
handleButtonClick
=
useCallback
(
...
@@ -119,14 +135,20 @@ export function AIWrapper({
...
@@ -119,14 +135,20 @@ export function AIWrapper({
setLoading
(
true
);
setLoading
(
true
);
toView
();
toView
();
OpenAI
.
request
(
OpenAI
.
request
(
initMessageList
,
noHistory
?
initMessageList
.
slice
(
0
,
startView
).
concat
({
role
:
'
user
'
,
content
:
inputValue
,
})
:
initMessageList
,
currentAssistantMessageStr
=>
{
currentAssistantMessageStr
=>
{
setTinking
(
true
);
//
setTinking(true);
setTimeout
(()
=>
{
//
setTimeout(() => {
setLoading
(
false
);
setLoading
(
false
);
setTinking
(
false
);
//
setTinking(false);
setTimeout
(
toView
,
100
);
setTimeout
(
toView
,
100
);
},
10
00
);
// }, 1
00);
setCurrentAssistantMessage
(
currentAssistantMessageStr
);
setCurrentAssistantMessage
(
currentAssistantMessageStr
);
callBack
&&
callBack
(
currentAssistantMessageStr
);
callBack
&&
callBack
(
currentAssistantMessageStr
);
doneFx
&&
doneFx
(
currentAssistantMessageStr
);
doneFx
&&
doneFx
(
currentAssistantMessageStr
);
...
@@ -141,7 +163,8 @@ export function AIWrapper({
...
@@ -141,7 +163,8 @@ export function AIWrapper({
title
:
'
No Response
'
,
title
:
'
No Response
'
,
content
:
undefined
,
content
:
undefined
,
});
});
}
},
closeRef
);
);
},
},
[
[
...
@@ -466,6 +489,9 @@ export function AIWrapper({
...
@@ -466,6 +489,9 @@ export function AIWrapper({
? `
$
{
t
(
'
Analyzing requirements
'
)}...
`
? `
$
{
t
(
'
Analyzing requirements
'
)}...
`
: `
$
{
t
(
'
Creating query
'
)}...
`}
: `
$
{
t
(
'
Creating query
'
)}...
`}
</div>
</div>
<Button className="shadow" onClick={close} size="mini" shape="round">
取消
</Button>
</div>
</div>
) : (
) : (
<Comment
<Comment
...
...
pages/actions/View/chatView.tsx
View file @
3e321e59
...
@@ -351,8 +351,13 @@ export function ChatView({
...
@@ -351,8 +351,13 @@ export function ChatView({
text
:
line
,
text
:
line
,
};
};
const
op2
=
{
const
op2
=
{
range
:
new
monaco
.
Range
(
nextLineNumber
,
1
,
nextLineNumber
,
1
),
range
:
new
monaco
.
Range
(
text
:
insertText
.
trim
()
+
'
\n\n
'
,
lineNumber
,
column
+
insertText
.
length
,
nextLineNumber
,
1
),
text
:
'
\n
'
+
insertText
.
trim
()
+
'
\n\n
'
,
};
};
editor
.
executeEdits
(
'
insertSnippet
'
,
[
op1
,
op2
]);
editor
.
executeEdits
(
'
insertSnippet
'
,
[
op1
,
op2
]);
...
@@ -397,7 +402,7 @@ export function ChatView({
...
@@ -397,7 +402,7 @@ export function ChatView({
)
}
)
}
</
div
>
</
div
>
<
div
className=
"w-full mb-[20px]"
>
<
div
className=
"w-full mb-[20px]"
>
<
Collapse
style=
{
{
maxWidth
:
1180
}
}
>
<
Collapse
>
<
CollapseItem
<
CollapseItem
header=
{
header=
{
<
div
>
<
div
>
...
...
pages/actions/index.tsx
View file @
3e321e59
...
@@ -805,6 +805,7 @@ INSERT INTO users (email, name) VALUES ($email$, $name$);
...
@@ -805,6 +805,7 @@ INSERT INTO users (email, name) VALUES ($email$, $name$);
>
>
<
Content
>
<
Content
>
<
AI
<
AI
noHistory
quickTip=
{
queryTip
}
quickTip=
{
queryTip
}
welcome=
{
welcome=
{
<>
<>
...
...
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