-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (23 loc) · 906 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (23 loc) · 906 Bytes
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
const form = document.getElementById("graphql-form");
const queryInput = document.getElementById("query");
const resultDisplay = document.getElementById("result");
// 👇 修改为你的 Cloudflare Worker GraphQL URL
const GRAPHQL_ENDPOINT = "https://api.hengweiz.top/graphql";
form.addEventListener("submit", async (e) => {
e.preventDefault();
const query = queryInput.value;
const res = await fetch(GRAPHQL_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
query: `query Chat($model: String!, $messages: [MessageInput!]!) {
chat(model: $model, messages: $messages)
}`,
variables: {"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"今天天气怎么样"}]}
})
});
const data = await res.json();
resultDisplay.textContent = JSON.stringify(data, null, 2);
});