Skip to content

Commit 6eb62b5

Browse files
authored
fix: bug (#729)
* fix: bug * fix: rm ngtools
1 parent 70a52ac commit 6eb62b5

File tree

16 files changed

+103
-71
lines changed

16 files changed

+103
-71
lines changed

app/components/MonacoEditor/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useCallback, useEffect, useMemo, useRef } from 'react';
2-
// eslint-disable-next-line import/no-extraneous-dependencies
32
import * as monaco from 'monaco-editor';
43
import type { editor as TMonacoEditor } from 'monaco-editor';
54
import Editor, { useMonaco, loader, type Monaco } from '@monaco-editor/react';

app/config/locale/en-US.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,5 +564,7 @@ export default {
564564
start: 'Start',
565565
aiImport: 'AI Import',
566566
pleaseConfigLLMFirst: 'Please configure LLM API first',
567+
tokenTip: "The current token consumption is an estimated value, and there may be some differences from the actual consumption in the end.",
568+
fileRequired: 'Please select the file',
567569
},
568570
};

app/config/locale/zh-CN.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,5 +542,8 @@ export default {
542542
previous: '上一步',
543543
start: '开始',
544544
aiImport: 'AI 导入',
545+
pleaseConfigLLMFirst: '请先配置 LLM 接口地址',
546+
tokenTip: '当前 token 消耗为预估值,最终消耗可能与实际消耗有所差异。',
547+
fileRequired: '请先选择文件',
545548
},
546549
};

app/pages/Console/OutputBox/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ const OutputBox = (props: IProps) => {
329329
children: <div className={styles.errContainer}>{message}</div>,
330330
},
331331
].filter(Boolean);
332-
}, [gql, data, dataSource, columns, fullscreen]);
332+
}, [gql, data, dataSource, columns, fullscreen, tab]);
333333
const onFullScreen = () => {
334334
setFullscreen(!fullscreen);
335335
};

app/pages/Import/AIImport/Create.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useStore } from '@app/stores';
22
import { useI18n } from '@vesoft-inc/i18n';
3-
import { Button, Form, Input, Modal, Radio, Select, message } from 'antd';
3+
import { Button, Form, Input, Modal, Radio, Select, Tooltip, message } from 'antd';
44
import { observer } from 'mobx-react-lite';
55
import Icon from '@app/components/Icon';
66
import { useEffect, useMemo, useState } from 'react';
@@ -62,6 +62,10 @@ const Create = observer((props: { visible: boolean; onCancel: () => void }) => {
6262

6363
const onConfirm = async () => {
6464
const values = form.getFieldsValue();
65+
if (!values.file) {
66+
message.error(intl.get('llm.fileRequired'));
67+
return;
68+
}
6569
post('/api/llm/import/job')({
6670
type,
6771
...values,
@@ -85,20 +89,22 @@ const Create = observer((props: { visible: boolean; onCancel: () => void }) => {
8589
setStep(0);
8690
}}
8791
>
88-
<Icon type="icon-vesoft-numeric-1-circle" />
92+
<Icon type={step === 0 ? "icon-vesoft-numeric-1-circle":"icon-vesoft-check-circle-filled"} />
8993
{intl.get('llm.setup')}
9094
</div>
9195
<span />
92-
<div>
96+
<div style={{color:step===0?'#888':'#0D8BFF'}} >
9397
<Icon type="icon-vesoft-numeric-2-circle" />
9498
{intl.get('llm.confirm')}
9599
</div>
96100
</div>
97-
{tokens !== 0 && (
98-
<div className={styles.tokenNum}>
99-
<span style={{ fontSize: 10, transform: 'translate(0px,1px)' }}>🅣</span> prompt token: ~
101+
{tokens !== 0 && type!=="filePath" && (
102+
<Tooltip title={intl.get("llm.tokenTip")} placement="bottom">
103+
<div className={styles.tokenNum}>
104+
<span style={{ fontSize: 14, transform: 'translate(0px,1px)' }}>🅣</span> prompt token: ~
100105
{Math.ceil(tokens / 10000)}w
101-
</div>
106+
</div>
107+
</Tooltip>
102108
)}
103109
<Form form={form} layout="vertical" style={{ display: step === 0 ? 'block' : 'none' }}>
104110
<Form.Item label={intl.get('llm.file')} required>

app/pages/Import/AIImport/index.module.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@
6464
gap: 5px;
6565
justify-content: center;
6666
color: #71717A;
67+
z-index: 9;
6768
}

app/pages/Import/TaskList/TaskItem/AIImportItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const AIImportItem = observer((props: IProps) => {
124124
>
125125
{intl.get('llm.aiImport')}
126126
</span>
127-
{llmJob.space}
127+
{llmJob.job_id}
128128
{llmJob.status === ILLMStatus.Success && (
129129
<span className={styles.completeInfo}>
130130
<CheckCircleFilled />

app/pages/Import/TaskList/TaskItem/LogModal/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ const LogModal = (props: IProps) => {
4949
const handleLogDownload = () => currentLog && downloadTaskLog({ id, name: currentLog });
5050

5151
const readLog = async () => {
52-
const data = await getLogDetail(task);
52+
const data = await getLogDetail({
53+
id:task.id
54+
});
5355
handleLogData(data);
5456
};
5557

app/pages/LLMBot/chat.module.less

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
p {
3434
margin: 5px 0;
3535
line-height: 25px;
36-
letter-spacing: 2px;
36+
37+
pre {
38+
margin: 0;
39+
white-space: break-spaces;
40+
max-width: 100%;
41+
}
3742
}
3843
}
3944
}
@@ -63,32 +68,6 @@
6368
position: relative;
6469
min-width: 360px;
6570

66-
:global {
67-
.CodeMirror {
68-
background-color: #092332;
69-
color: #AAAAAA
70-
}
71-
72-
.CodeMirror-gutters {
73-
background-color: #092332;
74-
color: #AAAAAA;
75-
border: none;
76-
color: #828282;
77-
}
78-
79-
.CodeMirror-cursor {
80-
border-color: #828282;
81-
}
82-
83-
.cm-keyword {
84-
color: #19DBFF;
85-
}
86-
87-
.cm-def {
88-
color: #AE9AFF;
89-
}
90-
}
91-
9271
>div {
9372
margin: 10px 0;
9473
}

app/pages/LLMBot/chat.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Button, Input } from 'antd';
2-
import { useEffect, useRef, useState } from 'react';
1+
import { Button, Input, message } from 'antd';
2+
import { useCallback, useEffect, useRef, useState } from 'react';
33
import ws from '@app/utils/websocket';
44
import { debounce } from 'lodash';
55
import rootStore from '@app/stores';
@@ -31,9 +31,12 @@ function Chat() {
3131
});
3232
setMessages(newMessages);
3333
const callback = (res) => {
34+
if (res.code !== 0) {
35+
resetPending(newMessages,res.message);
36+
return;
37+
}
3438
if (res.message.done) {
35-
newMessages[newMessages.length - 1].status = 'done';
36-
setPending(false);
39+
resetPending(newMessages);
3740
return;
3841
}
3942
try {
@@ -58,7 +61,7 @@ function Chat() {
5861
}
5962
setMessages([...newMessages]);
6063
} catch (e) {
61-
setPending(false);
64+
resetPending(newMessages,e.message+"\n response: \n"+JSON.stringify(res.message,null,2));
6265
}
6366
};
6467
const sendMessages = [
@@ -69,14 +72,26 @@ function Chat() {
6972
})),
7073
];
7174
const systemPrompt = await rootStore.llm.getDocPrompt(currentInput, sendMessages);
72-
ws.runChat({
75+
await ws.runChat({
7376
req: {
7477
stream: true,
7578
messages: [{ role: 'system', content: systemPrompt }, ...sendMessages, { role: 'user', content: currentInput }],
7679
},
7780
callback,
81+
}).catch((e) => {
82+
message.error(e.message);
83+
resetPending(newMessages,e.message);
7884
});
7985
}, 200);
86+
const resetPending = useCallback((messages,msg?:string) => {
87+
setPending(false);
88+
setMessages(messages.map((item) => {
89+
if(item.status !== 'pending') return item;
90+
item.status = 'done';
91+
item.content = msg ?(`[error] ${msg}`): item.content;
92+
return item;
93+
}))
94+
},[])
8095

8196
useEffect(() => {
8297
if (contentRef.current) {
@@ -96,7 +111,9 @@ function Chat() {
96111
const gqls = message.content.split(/```\w*\n([^`]+)```/);
97112
return gqls.map((item, index) => {
98113
if (index % 2 === 0) {
99-
return <p key={index}>{item}</p>;
114+
return <p key={index}>
115+
<pre>{item}</pre>
116+
</p>;
100117
} else {
101118
item = item.replace(/^(\n|ngql|gql|cypher)/g, '').replace(/\n$/g, '');
102119
item = item.replace(/\n\n/, '\n');

app/stores/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class ImportStore {
341341
trackEvent('import', 'download_task_log');
342342
};
343343

344-
getLogDetail = async (params: ITaskItem) => {
344+
getLogDetail = async (params: any) => {
345345
const { code, data } = await service.getLogDetail(params);
346346
if (code === 0) {
347347
return data;

package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@monaco-editor/react": "^4.6.0",
2323
"@vesoft-inc/force-graph": "2.0.7",
2424
"@vesoft-inc/i18n": "^1.0.1",
25-
"@vesoft-inc/icons": "^1.2.0",
25+
"@vesoft-inc/icons": "^1.7.0",
2626
"@vesoft-inc/nebula-explain-graph": "^1.0.3",
2727
"@vesoft-inc/veditor": "^4.4.12",
2828
"antd": "^5.8.4",
@@ -103,7 +103,7 @@
103103
"lint-staged": {
104104
"./app/**/*.{js,jsx,ts,tsx}": [
105105
"npx prettier --write",
106-
"eslint './app/**/*.{js,jsx,ts,tsx}' --fix"
106+
"eslint './app/**/*.{js,jsx,ts,tsx}' --fix --quiet"
107107
]
108108
},
109109
"ci": {

server/api/studio/internal/service/llm/import.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package llm
22

33
import (
44
"fmt"
5+
"hash/fnv"
56
"os"
67
"path/filepath"
8+
"strconv"
79
"time"
810

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

21+
func hashString(s string) string {
22+
h := fnv.New64a()
23+
h.Write([]byte(s))
24+
return strconv.FormatUint(h.Sum64(), 8)
25+
}
1926
func (g *llmService) AddImportJob(req *types.LLMImportRequest) (resp *types.LLMResponse, err error) {
2027
auth := g.ctx.Value(auth.CtxKeyUserInfo{}).(*auth.AuthData)
2128
config := db.LLMConfig{
@@ -40,7 +47,7 @@ func (g *llmService) AddImportJob(req *types.LLMImportRequest) (resp *types.LLMR
4047
Host: config.Host,
4148
UserName: config.UserName,
4249
UserPrompt: req.UserPrompt,
43-
JobID: space + "_" + time.Now().Format("20060102150405000"),
50+
JobID: time.Now().Format("20060102150405000") + "_" + hashString(space),
4451
}
4552
task := &db.TaskInfo{
4653
BID: job.JobID,

server/api/studio/pkg/llm/importjob.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func (i *ImportJob) MakeGQLFile(filePath string) ([]string, error) {
467467

468468
for key, field := range typeSchema {
469469
value, ok := props[key]
470-
if !ok {
470+
if !ok || value == nil {
471471
if field.Nullable {
472472
continue
473473
} else {
@@ -483,9 +483,13 @@ func (i *ImportJob) MakeGQLFile(filePath string) ([]string, error) {
483483
valueStr += ","
484484
}
485485
if strings.Contains(strings.ToLower(field.DataType), "string") {
486-
valueStr += fmt.Sprintf(`"%v"`, value)
486+
valueStr += fmt.Sprintf(`"%s"`, value)
487487
} else {
488-
valueStr += fmt.Sprintf(`%v`, value)
488+
if value == nil {
489+
valueStr += "null"
490+
} else {
491+
valueStr += fmt.Sprintf(`%s`, value)
492+
}
489493
}
490494
}
491495

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

587+
func replaceBackslash(s string) string {
588+
return strings.ReplaceAll(s, "\\", "\\\\")
589+
}
590+
583591
func (i *ImportJob) MakeSchema() error {
584592
schema := Schema{
585593
Space: i.LLMJob.Space,
586594
}
587-
gql := fmt.Sprintf("DESCRIBE SPACE `%s`", i.LLMJob.Space)
595+
gql := fmt.Sprintf("DESCRIBE SPACE `%s`", replaceBackslash(i.LLMJob.Space))
588596
spaceInfo, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
589597
if err != nil {
590598
return err
@@ -612,7 +620,7 @@ func (i *ImportJob) MakeSchema() error {
612620
tag := NodeType{
613621
Type: row["Name"].(string),
614622
}
615-
gql = fmt.Sprintf("DESCRIBE TAG `%s`", tag.Type)
623+
gql = fmt.Sprintf("DESCRIBE TAG `%s`", replaceBackslash(tag.Type))
616624
res, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
617625
if err != nil {
618626
return err
@@ -649,7 +657,7 @@ func (i *ImportJob) MakeSchema() error {
649657
edge := EdgeType{
650658
Type: row["Name"].(string),
651659
}
652-
gql = fmt.Sprintf("DESCRIBE EDGE `%s`", edge.Type)
660+
gql = fmt.Sprintf("DESCRIBE EDGE `%s`", replaceBackslash(edge.Type))
653661
res, err := client.Execute(i.NSID, i.LLMJob.Space, []string{gql})
654662
if err != nil {
655663
return err

0 commit comments

Comments
 (0)