Skip to content
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
16 changes: 11 additions & 5 deletions packages/site-components/src/components/td-ai-button/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ let sdkInstance;
let isGeneratingDemo = false;
let regExp = {
vue: /```vue(?:\w+)?\s*([\s\S]*?)```/g,
react: /```jsx(?:\w+)?\s*([\s\S]*?)```/g,
'mobile-vue': /```vue(?:\w+)?\s*([\s\S]*?)```/g,
'mobile-react': /```jsx(?:\w+)?\s*([\s\S]*?)```/g,
};

let frameworkKeys = {
Expand All @@ -18,10 +21,11 @@ let frameworkKeys = {
let promptForGenerateDemo = {
react: '请为我生成 ${component} 组件 ${selectedText} 属性的使用示例',
vue: '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,采用 script setup 语法糖',
miniprogram: '请按照微信原生小程序代码规范,为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,输出完整可用的代码片段,包括 wxml、wxss(可选)、js(可选)、json(可选)等文件',
miniprogram:
'请按照微信原生小程序代码规范,为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,输出完整可用的代码片段,包括 wxml、wxss(可选)、js(可选)、json(可选)等文件',
'mobile-vue': '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例,采用 script setup 语法糖',
'mobile-react': "请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例"
}
'mobile-react': '请为我生成 ${component} 组件的 ${selectedText} 属性的使用示例',
};

const generatePrompt = (framework, component, selectedText) => {
const template = promptForGenerateDemo[framework];
Expand Down Expand Up @@ -141,11 +145,13 @@ const webChatInteraction = (framework, demoRequestBody) => {
let match;
while ((match = codeRegex.exec(payload.content)) !== null) {
const code = match[1];
const fileExtension = framework.includes('react') ? 'tsx' : 'vue';
const fileName = `src/demo.${fileExtension}`;
body = {
...body,
files: {
...body.files,
'src/demo.vue': {
[fileName]: {
content: code,
},
},
Expand All @@ -161,7 +167,7 @@ const webChatInteraction = (framework, demoRequestBody) => {
})
.then((x) => x.json())
.then(({ sandbox_id: sandboxId }) => {
window.open(`https://codesandbox.io/s/${sandboxId}?file=/src/demo.vue`);
window.open(`https://codesandbox.io/s/${sandboxId}?file=/${fileName}`);
});
}
});
Expand Down