mirror of
https://github.com/yuruotong1/autoMate.git
synced 2026-03-22 13:07:17 +08:00
增加代码生成(未完成,报hook错误)
This commit is contained in:
28
package-lock.json
generated
28
package-lock.json
generated
@@ -10,7 +10,7 @@
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@ai-sdk/openai": "^0.0.33",
|
||||
"@ant-design/pro-chat": "^1.2.0",
|
||||
"@ant-design/pro-chat": "^1.14.2",
|
||||
"@ant-design/pro-editor": "^1.2.1",
|
||||
"@codemirror/lang-python": "^6.1.6",
|
||||
"@electron-toolkit/preload": "^3.0.0",
|
||||
@@ -312,30 +312,30 @@
|
||||
"integrity": "sha512-vHbT+zJEVzllwP+CM+ul7reTEfBR0vgxFe7+lREAsAA7YGsYpboiq2sQNeQeRvh09GfQgs/GyFEvZpJ9cLXpXA=="
|
||||
},
|
||||
"node_modules/@ant-design/pro-chat": {
|
||||
"version": "1.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@ant-design/pro-chat/-/pro-chat-1.14.1.tgz",
|
||||
"integrity": "sha512-Ws8XTKPwRa6KU31X/3ghCAVHvWLYc/ZoEgV4NpsiJojFep/rGQb0g6rhI4TbtUY1FSHk8u87CYFL0/VVOE2KcA==",
|
||||
"version": "1.14.2",
|
||||
"resolved": "https://registry.npmjs.org/@ant-design/pro-chat/-/pro-chat-1.14.2.tgz",
|
||||
"integrity": "sha512-9pq++mXtXr5GsqNSpwEDoGXTSbdvXGRX0l7MFHz0Llt9ABqUtsSVkE4TNTY+fqw4+rcyKbG/QSByaQEgcz4i+w==",
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^5.3.0",
|
||||
"@ant-design/icons": "^5.3.7",
|
||||
"@ant-design/pro-editor": "latest",
|
||||
"@babel/runtime": "^7.23.9",
|
||||
"@babel/runtime": "^7.24.7",
|
||||
"@emotion/react": "^11.11.4",
|
||||
"@testing-library/jest-dom": "^6.4.2",
|
||||
"@testing-library/jest-dom": "^6.4.6",
|
||||
"copy-to-clipboard": "^3.3.3",
|
||||
"dayjs": "^1.11.10",
|
||||
"dayjs": "^1.11.11",
|
||||
"emoji-regex": "^10.3.0",
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"immer": "^10.0.3",
|
||||
"immer": "^10.1.1",
|
||||
"lodash-es": "^4.17.21",
|
||||
"lucide-react": "^0.288.0",
|
||||
"nanoid": "^5.0.6",
|
||||
"nanoid": "^5.0.7",
|
||||
"polished": "^4.3.1",
|
||||
"rc-resize-observer": "^1.4.0",
|
||||
"rc-util": "^5.38.2",
|
||||
"react-intersection-observer": "^9.8.1",
|
||||
"react-layout-kit": "^1.7.4",
|
||||
"rc-util": "^5.43.0",
|
||||
"react-intersection-observer": "^9.10.3",
|
||||
"react-layout-kit": "^1.9.0",
|
||||
"react-markdown": "^8.0.7",
|
||||
"zustand": "^4.5.1",
|
||||
"zustand": "^4.5.2",
|
||||
"zustand-utils": "^1.3.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"dependencies": {
|
||||
"@ai-sdk/openai": "^0.0.33",
|
||||
"openai": "^4.24.7",
|
||||
"@ant-design/pro-chat": "^1.2.0",
|
||||
"@ant-design/pro-chat": "^1.14.2",
|
||||
"@ant-design/pro-editor": "^1.2.1",
|
||||
"@codemirror/lang-python": "^6.1.6",
|
||||
"@electron-toolkit/preload": "^3.0.0",
|
||||
|
||||
@@ -3,7 +3,6 @@ import { NavLink, useFetcher} from "react-router-dom"
|
||||
import styles from "./styles.module.scss"
|
||||
import { useStore } from "@renderer/store/useStore"
|
||||
import useCategory from "@renderer/hooks/useCategory"
|
||||
import useContent from "@renderer/hooks/useContent"
|
||||
interface Props {
|
||||
category: CategoryType
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { requireAlignmentPrompt } from "./prompt";
|
||||
import { useStore } from "@renderer/store/useStore";
|
||||
import { requireAlignmentPrompt, programmerPrompt } from "./prompt";
|
||||
import useOpenai from "./useOpenai";
|
||||
|
||||
export async function useChat(chat_messages: Array<any>){
|
||||
const setCode = useStore(state=>state.setCode)
|
||||
const messages = chat_messages.map((m) => {
|
||||
return {
|
||||
role: m.role,
|
||||
@@ -13,7 +15,22 @@ export async function useChat(chat_messages: Array<any>){
|
||||
role: 'system',
|
||||
content: requireAlignmentPrompt()
|
||||
});
|
||||
const response = await useOpenai(requireAlignmentPrompt(), messages)
|
||||
const callBack = (allContent: string) => {
|
||||
|
||||
const programmerCallBack = (allContent: string) => {
|
||||
console.log("allContent", allContent)
|
||||
setCode(allContent)
|
||||
}
|
||||
if (allContent.includes("【自动化方案】")) {
|
||||
useOpenai(programmerPrompt(), [{
|
||||
role: "user",
|
||||
content: allContent
|
||||
}], programmerCallBack)
|
||||
} else {
|
||||
console.log("Response does not contain '【自动化方案】'");
|
||||
}
|
||||
}
|
||||
const response = await useOpenai(requireAlignmentPrompt(), messages, callBack)
|
||||
return response
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createOpenAI } from "@ai-sdk/openai"
|
||||
import { streamText } from "ai"
|
||||
|
||||
export default async (systemPrompt: string, chatMessages: Array<Record<string, any>>, callback: (allContent: string) => void) => {
|
||||
export default async (systemPrompt: string, chatMessages: Array<Record<string, any>>, callback?: (allContent: string) => void) => {
|
||||
const configType = (await window.api.getConfig()) as ConfigType
|
||||
const config = JSON.parse(configType.content) as ConfigDataType
|
||||
const messages = chatMessages.map((m) => {
|
||||
@@ -32,17 +32,19 @@ export default async (systemPrompt: string, chatMessages: Array<Record<string, a
|
||||
|
||||
const readableStream = new ReadableStream({
|
||||
async start(controller) {
|
||||
let res = ""
|
||||
function push() {
|
||||
let res = ""
|
||||
reader
|
||||
.read()
|
||||
.then(({ done, value }) => {
|
||||
if (done) {
|
||||
controller.close();
|
||||
callback(res)
|
||||
if (callback) {
|
||||
callback(res);
|
||||
}
|
||||
return;
|
||||
}
|
||||
res += value
|
||||
res += value;
|
||||
controller.enqueue(encoder.encode(value));
|
||||
push();
|
||||
})
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { python } from '@codemirror/lang-python';
|
||||
import { useStore } from '@renderer/store/useStore';
|
||||
// import { StreamLanguage } from '@codemirror/language';
|
||||
export default function Code() {
|
||||
const code = useStore(state=>state.code)
|
||||
|
||||
return (
|
||||
<CodeMirror
|
||||
@@ -9,7 +11,7 @@ export default function Code() {
|
||||
className="w-full h-full fixed overflow-auto"
|
||||
height="100%"
|
||||
width='400px'
|
||||
value={""}
|
||||
value={code}
|
||||
extensions={[python()]}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -9,7 +9,9 @@ interface StateProps{
|
||||
selectId: number,
|
||||
setSelectId: (selectId: number) => void,
|
||||
editCategoryId: number,
|
||||
setEditCategoryId: (id: number) => void
|
||||
setEditCategoryId: (id: number) => void,
|
||||
code: string,
|
||||
setCode: (code: string) => void
|
||||
}
|
||||
export const useStore = create<StateProps>((set) => ({
|
||||
data: [],
|
||||
@@ -21,7 +23,9 @@ export const useStore = create<StateProps>((set) => ({
|
||||
selectId: 0,
|
||||
setSelectId: (selectId) => set({selectId}),
|
||||
editCategoryId: 0,
|
||||
setEditCategoryId: (editCategoryId) => set({editCategoryId})
|
||||
setEditCategoryId: (editCategoryId) => set({editCategoryId}),
|
||||
code: "",
|
||||
setCode: (code) => set({code})
|
||||
}))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user