mirror of
https://github.com/yuruotong1/autoMate.git
synced 2025-12-26 05:16:21 +08:00
能够在代码编辑框中展示代码
This commit is contained in:
parent
aa22bdc3d9
commit
1682819e7d
@ -45,7 +45,7 @@ ${code}
|
||||
代码中的函数一定是python内置函数或我提供的【函数】,不要使用其他函数。
|
||||
############
|
||||
# 回复格式 #
|
||||
[python代码]
|
||||
只回复python代码
|
||||
#############
|
||||
# 例子 #
|
||||
1. print("abc")
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { useStore } from "@renderer/store/useStore";
|
||||
import { requireAlignmentPrompt, programmerPrompt } from "./prompt";
|
||||
import { requireAlignmentPrompt, programmerPrompt, extraCodePrompt } from "./prompt";
|
||||
import useOpenai from "./useOpenai";
|
||||
|
||||
export async function useChat(chat_messages: Array<any>){
|
||||
export default ()=>{
|
||||
const setCode = useStore(state=>state.setCode)
|
||||
const getResponse=(chat_messages: Array<any>)=>{
|
||||
// const setCode = useStore(state=>state.setCode)
|
||||
const messages = chat_messages.map((m) => {
|
||||
return {
|
||||
role: m.role,
|
||||
@ -17,9 +19,11 @@ export async function useChat(chat_messages: Array<any>){
|
||||
});
|
||||
const callBack = (allContent: string) => {
|
||||
|
||||
const programmerCallBack = (allContent: string) => {
|
||||
console.log("allContent", allContent)
|
||||
setCode(allContent)
|
||||
const programmerCallBack = (allContent: string) => {
|
||||
allContent = allContent.replace(/^```python/, "").replace(/^```/, "").replace(/```$/, "").trim()
|
||||
setCode(allContent)
|
||||
|
||||
|
||||
}
|
||||
if (allContent.includes("【自动化方案】")) {
|
||||
useOpenai(programmerPrompt(), [{
|
||||
@ -30,7 +34,10 @@ export async function useChat(chat_messages: Array<any>){
|
||||
console.log("Response does not contain '【自动化方案】'");
|
||||
}
|
||||
}
|
||||
const response = await useOpenai(requireAlignmentPrompt(), messages, callBack)
|
||||
const response = useOpenai(requireAlignmentPrompt(), messages, callBack)
|
||||
return response
|
||||
}
|
||||
return {getResponse}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { ProChat } from '@ant-design/pro-chat';
|
||||
import {useChat} from '@renderer/hooks/useChat';
|
||||
import useChat from '@renderer/hooks/useChat';
|
||||
import { useTheme } from 'antd-style';
|
||||
import "./chat-page.scss"
|
||||
import Code from './Code';
|
||||
export const Chat = () => {
|
||||
const {getResponse} = useChat()
|
||||
|
||||
const theme = useTheme();
|
||||
// const run = async ()=>{
|
||||
// const response = await useChat([{ role: 'user', content: '你好' }])
|
||||
@ -18,7 +20,7 @@ export const Chat = () => {
|
||||
<div className='text-black'>你好,我叫智子,你的智能Agent助手,有什么要求可以随时吩咐!</div>
|
||||
}
|
||||
request={async (messages) => {
|
||||
const response = await useChat(messages)
|
||||
const response = await getResponse(messages)
|
||||
console.log('response', response)
|
||||
// 使用 Message 作为参数发送请求
|
||||
return response// 支持流式和非流式
|
||||
|
||||
@ -4,7 +4,7 @@ import { useStore } from '@renderer/store/useStore';
|
||||
// import { StreamLanguage } from '@codemirror/language';
|
||||
export default function Code() {
|
||||
const code = useStore(state=>state.code)
|
||||
|
||||
|
||||
return (
|
||||
<CodeMirror
|
||||
theme="dark"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user