Skip to content

Commit

Permalink
feat: remove generate implement (#3131)
Browse files Browse the repository at this point in the history
  • Loading branch information
pipiiiiii authored Oct 20, 2023
1 parent b8cb6e2 commit e30afbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
32 changes: 5 additions & 27 deletions packages/ai-native/src/browser/ai-chat.view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cls from 'classnames';
import { observer } from 'mobx-react-lite';
import * as React from 'react';
// @ts-ignore
Expand Down Expand Up @@ -57,33 +56,12 @@ export const AiChatView = observer(() => {
const [, updateState] = React.useState<any>();
// 项目生成
const generateProject = React.useCallback(async () => {
await aiProjectGenerateService.clearWorkspace();

const loadingText = createMessageByAI(<div>项目生成中,请稍后....</div>);
// 项目分析结果
const { language, framework } = aiProjectGenerateService.requirements!;
const languageReply = createMessageByAI(
<AiReply text={`项目语言为:${language}\n使用框架:${framework}`} immediately={true} />,
);
setMessageListData([languageReply, loadingText]);

const filePathList = await aiProjectGenerateService.generateProjectStructure();
const structureReply = createMessageByAI(
<AiReply text={`项目结构为:\n${filePathList.join('\n')}`} immediately={true} />,
);
setMessageListData([languageReply, structureReply, loadingText]);

const generatedFilePathList: string[] = [];
await aiProjectGenerateService.generateFile(filePathList, (file: string) => {
const currentFileReply = createMessageByAI(<AiReply text={`正在生成文件:${file}`} />);
const generatedReply = createMessageByAI(<AiReply text={`已生成文件:\n${generatedFilePathList.join('\n')}`} />);
setMessageListData([languageReply, structureReply, generatedReply, currentFileReply, loadingText]);
generatedFilePathList.push(file);
aiProjectGenerateService.start((messageList) => {
const aiMessageList = messageList.map(({ message, immediately }) => createMessageByAI(
<AiReply text={message} immediately={immediately} />,
));
setMessageListData([...aiMessageList]);
});

const successMessage = createMessageByAI(<div>项目生成完毕</div>);
setMessageListData([languageReply, structureReply, successMessage]);
localStorage.removeItem('ai-generate');
}, []);

React.useEffect(() => {
Expand Down
19 changes: 2 additions & 17 deletions packages/ai-native/src/browser/ai-project/generate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,7 @@ export class AiProjectGenerateService {
return this._requirements;
}

/**
* 生成项目目录结构
* ['src/app/main/demo.java', 'src/app/test/demo.jsva']
* @returns
*/
public async generateProjectStructure(): Promise<string[]> {
return [];
}
/**
* 生成文件
* @param filePathList 文件列表,完整路径
* @param callback 回调函数,用来触发聊天输出
*/
public async generateFile(filePathList: string[], callback: (path: string) => void) {}

public async clearWorkspace() {
await this.aiBackService.clearWorkspace();
public async start(callback: (messageList: Array<{ message: string; immediately?: boolean }>) => void) {
callback([]);
}
}

0 comments on commit e30afbb

Please sign in to comment.