-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
78 lines (72 loc) · 2.15 KB
/
index.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
export async function onRequest({ request, params, env }) {
if (request.method === 'OPTIONS') {
return new Response(null, {
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '86400',
},
});
}
try {
const body = await request.clone().json();
const image = body.image;
const messages = [
{
role: 'user',
content: [
{
type: 'text',
text: `Convert the provided image into Markdown format.
Ensure that all content from the page is included, such as headers, footers, subtexts, images (with alt text if possible), tables, and any other elements.
Requirements:
- Output Only Markdown: Return solely the Markdown content without any additional explanations or comments.
- No Delimiters: Do not use code fences or delimiters like \`\`\`markdown.
- Complete Content: Do not omit any part of the page, including headers, footers, and subtext.
- Return the table content in the form of a markdown table.
`,
},
{
type: 'image_url',
image_url: {
url: image,
},
},
],
},
];
const res = await fetch(env.BASE_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: env.TOKEN,
},
eo: {
timeoutSetting: {
connectTimeout: 60000,
readTimeout: 60000,
writeTimeout: 60000,
},
},
body: JSON.stringify({
model: 'hunyuan-vision',
messages: messages,
}),
});
const resJSON = await res.json();
return new Response(JSON.stringify(resJSON.data), {
headers: {
'content-type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*',
},
});
} catch (err) {
return new Response(JSON.stringify({ error: err.message }), {
headers: {
'content-type': 'application/json; charset=UTF-8',
'Access-Control-Allow-Origin': '*',
},
});
}
}