Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug #729

Merged
merged 5 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/components/MonacoEditor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import * as monaco from 'monaco-editor';
import type { editor as TMonacoEditor } from 'monaco-editor';
import Editor, { useMonaco, loader, type Monaco } from '@monaco-editor/react';
Expand Down
2 changes: 2 additions & 0 deletions app/config/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,5 +564,7 @@ export default {
start: 'Start',
aiImport: 'AI Import',
pleaseConfigLLMFirst: 'Please configure LLM API first',
tokenTip: "The current token consumption is an estimated value, and there may be some differences from the actual consumption in the end.",
fileRequired: 'Please select the file',
},
};
3 changes: 3 additions & 0 deletions app/config/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,5 +542,8 @@ export default {
previous: '上一步',
start: '开始',
aiImport: 'AI 导入',
pleaseConfigLLMFirst: '请先配置 LLM 接口地址',
tokenTip: '当前 token 消耗为预估值,最终消耗可能与实际消耗有所差异。',
fileRequired: '请先选择文件',
},
};
2 changes: 1 addition & 1 deletion app/pages/Console/OutputBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ const OutputBox = (props: IProps) => {
children: <div className={styles.errContainer}>{message}</div>,
},
].filter(Boolean);
}, [gql, data, dataSource, columns, fullscreen]);
}, [gql, data, dataSource, columns, fullscreen, tab]);
const onFullScreen = () => {
setFullscreen(!fullscreen);
};
Expand Down
20 changes: 13 additions & 7 deletions app/pages/Import/AIImport/Create.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useStore } from '@app/stores';
import { useI18n } from '@vesoft-inc/i18n';
import { Button, Form, Input, Modal, Radio, Select, message } from 'antd';
import { Button, Form, Input, Modal, Radio, Select, Tooltip, message } from 'antd';
import { observer } from 'mobx-react-lite';
import Icon from '@app/components/Icon';
import { useEffect, useMemo, useState } from 'react';
Expand Down Expand Up @@ -62,6 +62,10 @@ const Create = observer((props: { visible: boolean; onCancel: () => void }) => {

const onConfirm = async () => {
const values = form.getFieldsValue();
if (!values.file) {
message.error(intl.get('llm.fileRequired'));
return;
}
post('/api/llm/import/job')({
type,
...values,
Expand All @@ -85,20 +89,22 @@ const Create = observer((props: { visible: boolean; onCancel: () => void }) => {
setStep(0);
}}
>
<Icon type="icon-vesoft-numeric-1-circle" />
<Icon type={step === 0 ? "icon-vesoft-numeric-1-circle":"icon-vesoft-check-circle-filled"} />
{intl.get('llm.setup')}
</div>
<span />
<div>
<div style={{color:step===0?'#888':'#0D8BFF'}} >
<Icon type="icon-vesoft-numeric-2-circle" />
{intl.get('llm.confirm')}
</div>
</div>
{tokens !== 0 && (
<div className={styles.tokenNum}>
<span style={{ fontSize: 10, transform: 'translate(0px,1px)' }}>🅣</span> prompt token: ~
{tokens !== 0 && type!=="filePath" && (
<Tooltip title={intl.get("llm.tokenTip")} placement="bottom">
<div className={styles.tokenNum}>
<span style={{ fontSize: 14, transform: 'translate(0px,1px)' }}>🅣</span> prompt token: ~
{Math.ceil(tokens / 10000)}w
</div>
</div>
</Tooltip>
)}
<Form form={form} layout="vertical" style={{ display: step === 0 ? 'block' : 'none' }}>
<Form.Item label={intl.get('llm.file')} required>
Expand Down
1 change: 1 addition & 0 deletions app/pages/Import/AIImport/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@
gap: 5px;
justify-content: center;
color: #71717A;
z-index: 9;
}
2 changes: 1 addition & 1 deletion app/pages/Import/TaskList/TaskItem/AIImportItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const AIImportItem = observer((props: IProps) => {
>
{intl.get('llm.aiImport')}
</span>
{llmJob.space}
{llmJob.job_id}
{llmJob.status === ILLMStatus.Success && (
<span className={styles.completeInfo}>
<CheckCircleFilled />
Expand Down
4 changes: 3 additions & 1 deletion app/pages/Import/TaskList/TaskItem/LogModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const LogModal = (props: IProps) => {
const handleLogDownload = () => currentLog && downloadTaskLog({ id, name: currentLog });

const readLog = async () => {
const data = await getLogDetail(task);
const data = await getLogDetail({
id:task.id
});
handleLogData(data);
};

Expand Down
33 changes: 6 additions & 27 deletions app/pages/LLMBot/chat.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
p {
margin: 5px 0;
line-height: 25px;
letter-spacing: 2px;

pre {
margin: 0;
white-space: break-spaces;
max-width: 100%;
}
}
}
}
Expand Down Expand Up @@ -63,32 +68,6 @@
position: relative;
min-width: 360px;

:global {
.CodeMirror {
background-color: #092332;
color: #AAAAAA
}

.CodeMirror-gutters {
background-color: #092332;
color: #AAAAAA;
border: none;
color: #828282;
}

.CodeMirror-cursor {
border-color: #828282;
}

.cm-keyword {
color: #19DBFF;
}

.cm-def {
color: #AE9AFF;
}
}

>div {
margin: 10px 0;
}
Expand Down
31 changes: 24 additions & 7 deletions app/pages/LLMBot/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Input } from 'antd';
import { useEffect, useRef, useState } from 'react';
import { Button, Input, message } from 'antd';
import { useCallback, useEffect, useRef, useState } from 'react';
import ws from '@app/utils/websocket';
import { debounce } from 'lodash';
import rootStore from '@app/stores';
Expand Down Expand Up @@ -31,9 +31,12 @@ function Chat() {
});
setMessages(newMessages);
const callback = (res) => {
if (res.code !== 0) {
resetPending(newMessages,res.message);
return;
}
if (res.message.done) {
newMessages[newMessages.length - 1].status = 'done';
setPending(false);
resetPending(newMessages);
return;
}
try {
Expand All @@ -58,7 +61,7 @@ function Chat() {
}
setMessages([...newMessages]);
} catch (e) {
setPending(false);
resetPending(newMessages,e.message+"\n response: \n"+JSON.stringify(res.message,null,2));
}
};
const sendMessages = [
Expand All @@ -69,14 +72,26 @@ function Chat() {
})),
];
const systemPrompt = await rootStore.llm.getDocPrompt(currentInput, sendMessages);
ws.runChat({
await ws.runChat({
req: {
stream: true,
messages: [{ role: 'system', content: systemPrompt }, ...sendMessages, { role: 'user', content: currentInput }],
},
callback,
}).catch((e) => {
message.error(e.message);
resetPending(newMessages,e.message);
});
}, 200);
const resetPending = useCallback((messages,msg?:string) => {
setPending(false);
setMessages(messages.map((item) => {
if(item.status !== 'pending') return item;
item.status = 'done';
item.content = msg ?(`[error] ${msg}`): item.content;
return item;
}))
},[])

useEffect(() => {
if (contentRef.current) {
Expand All @@ -96,7 +111,9 @@ function Chat() {
const gqls = message.content.split(/```\w*\n([^`]+)```/);
return gqls.map((item, index) => {
if (index % 2 === 0) {
return <p key={index}>{item}</p>;
return <p key={index}>
<pre>{item}</pre>
</p>;
} else {
item = item.replace(/^(\n|ngql|gql|cypher)/g, '').replace(/\n$/g, '');
item = item.replace(/\n\n/, '\n');
Expand Down
2 changes: 1 addition & 1 deletion app/stores/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class ImportStore {
trackEvent('import', 'download_task_log');
};

getLogDetail = async (params: ITaskItem) => {
getLogDetail = async (params: any) => {
const { code, data } = await service.getLogDetail(params);
if (code === 0) {
return data;
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@monaco-editor/react": "^4.6.0",
"@vesoft-inc/force-graph": "2.0.7",
"@vesoft-inc/i18n": "^1.0.1",
"@vesoft-inc/icons": "^1.2.0",
"@vesoft-inc/icons": "^1.7.0",
"@vesoft-inc/nebula-explain-graph": "^1.0.3",
"@vesoft-inc/veditor": "^4.4.12",
"antd": "^5.8.4",
Expand Down Expand Up @@ -103,7 +103,7 @@
"lint-staged": {
"./app/**/*.{js,jsx,ts,tsx}": [
"npx prettier --write",
"eslint './app/**/*.{js,jsx,ts,tsx}' --fix"
"eslint './app/**/*.{js,jsx,ts,tsx}' --fix --quiet"
]
},
"ci": {
Expand Down
9 changes: 8 additions & 1 deletion server/api/studio/internal/service/llm/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package llm

import (
"fmt"
"hash/fnv"
"os"
"path/filepath"
"strconv"
"time"

"github.com/vesoft-inc/go-pkg/response"
Expand All @@ -16,6 +18,11 @@ import (
"gorm.io/datatypes"
)

func hashString(s string) string {
h := fnv.New64a()
h.Write([]byte(s))
return strconv.FormatUint(h.Sum64(), 8)
}
func (g *llmService) AddImportJob(req *types.LLMImportRequest) (resp *types.LLMResponse, err error) {
auth := g.ctx.Value(auth.CtxKeyUserInfo{}).(*auth.AuthData)
config := db.LLMConfig{
Expand All @@ -40,7 +47,7 @@ func (g *llmService) AddImportJob(req *types.LLMImportRequest) (resp *types.LLMR
Host: config.Host,
UserName: config.UserName,
UserPrompt: req.UserPrompt,
JobID: space + "_" + time.Now().Format("20060102150405000"),
JobID: time.Now().Format("20060102150405000") + "_" + hashString(space),
}
task := &db.TaskInfo{
BID: job.JobID,
Expand Down
20 changes: 14 additions & 6 deletions server/api/studio/pkg/llm/importjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func (i *ImportJob) MakeGQLFile(filePath string) ([]string, error) {

for key, field := range typeSchema {
value, ok := props[key]
if !ok {
if !ok || value == nil {
if field.Nullable {
continue
} else {
Expand All @@ -483,9 +483,13 @@ func (i *ImportJob) MakeGQLFile(filePath string) ([]string, error) {
valueStr += ","
}
if strings.Contains(strings.ToLower(field.DataType), "string") {
valueStr += fmt.Sprintf(`"%v"`, value)
valueStr += fmt.Sprintf(`"%s"`, value)
} else {
valueStr += fmt.Sprintf(`%v`, value)
if value == nil {
valueStr += "null"
} else {
valueStr += fmt.Sprintf(`%s`, value)
}
}
}

Expand Down Expand Up @@ -580,11 +584,15 @@ func (i *ImportJob) RunGQLFile(gqls []string) error {
return nil
}

func replaceBackslash(s string) string {
return strings.ReplaceAll(s, "\\", "\\\\")
}

func (i *ImportJob) MakeSchema() error {
schema := Schema{
Space: i.LLMJob.Space,
}
gql := fmt.Sprintf("DESCRIBE SPACE `%s`", i.LLMJob.Space)
gql := fmt.Sprintf("DESCRIBE SPACE `%s`", replaceBackslash(i.LLMJob.Space))
spaceInfo, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
if err != nil {
return err
Expand Down Expand Up @@ -612,7 +620,7 @@ func (i *ImportJob) MakeSchema() error {
tag := NodeType{
Type: row["Name"].(string),
}
gql = fmt.Sprintf("DESCRIBE TAG `%s`", tag.Type)
gql = fmt.Sprintf("DESCRIBE TAG `%s`", replaceBackslash(tag.Type))
res, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
if err != nil {
return err
Expand Down Expand Up @@ -649,7 +657,7 @@ func (i *ImportJob) MakeSchema() error {
edge := EdgeType{
Type: row["Name"].(string),
}
gql = fmt.Sprintf("DESCRIBE EDGE `%s`", edge.Type)
gql = fmt.Sprintf("DESCRIBE EDGE `%s`", replaceBackslash(edge.Type))
res, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
if err != nil {
return err
Expand Down
Loading