vercel离线部署tldraw无限画布+免费ChatGPT 4o mini将简单线框转换成html页面

vercel离线部署tldraw无限画布+免费ChatGPT 4o mini将简单线框转换成html页面

github开源项目:
SawyerHood/draw-a-ui: 画示意图生成html
popjane/free_chatgpt_api: 🔥 公益免费的ChatGPT API,免费ChatGPT API,GPT4 API,可直连

一.获取免费ChatGPT API

点击进入 把项目fork到仓库,再点击 获取免费API ,需要使用github授权。

慎重保管,丢失无法找回

可以用于支持自定义chatgpt api接口的场景,自定义API接口地址:https://free.v36.cmhttps://free.v36.cm/v1

二.Vercel部署无限画布tldraw

原项目搞不懂怎么部署tldraw/tldraw: whiteboard / infinite canvas SDK,有懂的可以试试。

找到了一个基于tldraw开发的项目SawyerHood/draw-a-ui: 画示意图生成html,算是间接部署了tldraw。
image.png

但是这个项目的AI功能需要gpt Vision API,得加钱!!!免费gpt api无法使用,在免费gpt的帮助下实现了,它帮我白嫖它自己😍!!!

1.修改项目文件

SawyerHood/draw-a-ui: 画示意图生成html 叉到仓库

直接在github上找到draw-a-ui\app\api\toHtml\route.ts,修改项目内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { OpenAI } from "openai";

// 从环境变量中获取 API URL 和 API 密钥
const OPENAI_API_URL = process.env.OPENAI_API_URL; // 从环境变量中获取自定义 API URL
const OPENAI_API_KEY = process.env.OPENAI_API_KEY; // 从环境变量中获取 API 密钥

const systemPrompt = `You are an expert Tailwind developer with a strong understanding of web design principles.
A user will provide you with a low-fidelity wireframe of an application. Your task is to return a single HTML file
that uses Tailwind CSS to create a responsive and visually appealing website.
Feel free to make creative decisions to enhance the application's design and functionality.
If you need to insert an image, use placehold.co to generate a placeholder image.
Respond only with the complete HTML file, ensuring it is well-structured and includes necessary meta tags for responsiveness.`;

export async function POST(request: Request) {
// 创建 OpenAI 实例并设置自定义 API URL
const openai = new OpenAI({
apiKey: OPENAI_API_KEY, // 使用环境变量中的 API 密钥
baseURL: OPENAI_API_URL, // 使用环境变量中的自定义 API URL
});

try {
const { image } = await request.json();

const resp = await openai.chat.completions.create({
model: "gpt-4o-mini",
max_tokens: 4096,
messages: [
{
role: "system",
content: systemPrompt,
},
{
role: "user",
content: [
{
type: "image_url",
image_url: { url: image, detail: "high" },
},
{
type: "text",
text: "Turn this into a single html file using tailwind.",
},
],
},
],
});

return new Response(JSON.stringify(resp), {
headers: {
"content-type": "application/json; charset=UTF-8",
},
});
} catch (error) {
console.error("Error occurred while calling OpenAI API:", error);

// 返回通用错误消息
return new Response(JSON.stringify({ error: "An error occurred while processing your request." }), {
status: 500,
headers: {
"content-type": "application/json; charset=UTF-8",
},
});
}
}

2.部署到vercel

  1. 打开 Vercel ,选择github上刚刚叉进去的项目,直接开始部署,构建命令和环境变量等下再去添加

    image.png
  2. 部署失败很正常,进入项目设置,设置install command为npm install
    development command为 npm run dev --port 3000

  3. 设置环境变量

    • OPENAI_API_URL=https://free.v36.cm/v1
    • OPENAI_API_KEY=”sk-********”
    • PORT=3000
  4. 重新部署

我部署的项目地址:tldraw无限白板

image.png image.png image.png

这是我自己搭建的blog网站,用来记录和分享我自己研究的健身造型知识,类似于一个知识库。可以把这个网站分享给你身边的健身爱好者,转载或节选引,用务必注明为“李瑶的原创”,您的支持和尊重是我更新的动力!
理型健