Demo:清冷仙子哦齁齁齁.xyz
例如:
山间清
泉潺潺流过,恰逢
戊日,村民依俗取水祈福。
能解出:
你好,世界!
为了能活得久一点,选择闭源
这里贴出核心代码(注意前端要把括号替换为换行符):
import type { ChatCompletion } from "openai/resources.js";
import { httpAction } from "./_generated/server";
import OpenAI from 'openai';
export default httpAction(async (_, req) => {
try {
const word = new URL(req.url).searchParams.get('word');
if (!word) return new Response("Missing 'word' parameter", {
status: 400
});
const [w0, w1] = word
if (!w0 || !w1) return new Response("Length must be 2", {
status: 400
});
const openai = new OpenAI({
baseURL: "https://apis.iflow.cn/v1",
apiKey: "你的 apiKey" // todo 填写 apiKey
});
for (;;) {
const completion: ChatCompletion = await openai.chat.completions.create({
model: "qwen3-max",
messages: [
{
"role": "system",
"content": `你是句子生成器,按用户的要求输出一个句子,必须避免敏感。现在是${new Date()}。`
},
{
"role": "user",
"content": `用“${w0}”“${w1}”造句,“${w0}”在前“${w1}”在后,但不能放在句首。如果可以,减少以“他”开头,实在不行也没办法。`
}
],
});
const content = completion.choices[0]?.message.content
if (!content || !content.includes(w0) || !content.includes(w1) || content.startsWith(w0) || content.indexOf(w0) > content.indexOf(w1)) continue;
const newHeaders = new Headers();
newHeaders.set('Access-Control-Allow-Origin', 'https://saozi5-75am.ipfs.4everland.app');
return new Response(content.replace(w0, `「${w0}」`).replace(w1, `「${w1}」`), {
headers: newHeaders
});
}
} catch (e) {
return new Response(String(e), {
status: 500
});
}
})

