Skip to content

Commit ea7d108

Browse files
committed
updated id
1 parent 4ea776b commit ea7d108

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import fetch from "node-fetch";
55
dotenv.config();
66

77
if (!process.env.DIFY_API_URL) throw new Error("DIFY API URL is required.");
8-
8+
function generateId() {
9+
let result = '';
10+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
11+
for (let i = 0; i < 29; i++) {
12+
result += characters.charAt(Math.floor(Math.random() * characters.length));
13+
}
14+
return result;
15+
}
916
const app = express();
1017
app.use(bodyParser.json());
1118

@@ -221,7 +228,7 @@ app.post("/v1/chat/completions", async (req, res) => {
221228
.json({ error: "An error occurred while processing the request." });
222229
} else if (messageEnded) {
223230
res.json({
224-
id: `chatcmpl-${Date.now()}`,
231+
id: `chatcmpl-${generateId()}`,
225232
object: "chat.completion",
226233
created: Math.floor(Date.now() / 1000),
227234
model: data.model,

0 commit comments

Comments
 (0)