Repository navigation
Expand file tree
/
Copy pathtest-example.js
More file actions
132 lines (113 loc) · 3.34 KB
/
Copy pathtest-example.js
File metadata and controls
132 lines (113 loc) · 3.34 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Simple test example for the Qwen Worker
// This shows how to use the worker once deployed
const testRequest = {
model: "qwen3-coder-plus",
messages: [
{
role: "user",
content: "Write a simple Hello World function in Python"
}
],
stream: false
};
// Test with new models
const testRequestFlash = {
model: "qwen3-coder-flash",
messages: [
{
role: "user",
content: "Write a simple Hello World function in Python"
}
],
stream: false
};
const testRequestVision = {
model: "vision-model",
messages: [
{
role: "user",
content: "Describe this image if you can see it"
}
],
stream: false
};
// Example cURL command (replace with your worker URL)
const curlCommand = `curl -X POST https://your-worker.your-subdomain.workers.dev/v1/chat/completions \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer sk-your-api-key-here" \\
-d '${JSON.stringify(testRequest, null, 2)}'`;
console.log("Example cURL command:");
console.log(curlCommand);
// Example JavaScript usage
console.log("\nExample JavaScript usage:");
console.log(`
const response = await fetch('https://your-worker.workers.dev/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key-here'
},
body: JSON.stringify(${JSON.stringify(testRequest, null, 2)})
});
const result = await response.json();
console.log(result.choices[0].message.content);
`);
// Example with new models
console.log(`
// Example with qwen3-coder-flash model
const responseFlash = await fetch('https://your-worker.workers.dev/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key-here'
},
body: JSON.stringify(${JSON.stringify(testRequestFlash, null, 2)})
});
const resultFlash = await responseFlash.json();
console.log(resultFlash.choices[0].message.content);
`);
console.log(`
// Example with vision-model
const responseVision = await fetch('https://your-worker.workers.dev/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-your-api-key-here'
},
body: JSON.stringify(${JSON.stringify(testRequestVision, null, 2)})
});
const resultVision = await responseVision.json();
console.log(resultVision.choices[0].message.content);
`);
// Example Python OpenAI SDK usage
console.log("Example Python OpenAI SDK usage:");
console.log(`
from openai import OpenAI
client = OpenAI(
base_url='https://your-worker.workers.dev/v1',
api_key='sk-your-api-key-here'
)
response = client.chat.completions.create(
model='qwen3-coder-plus',
messages=[
{'role': 'user', 'content': 'Write a simple Hello World function in Python'}
]
)
print(response.choices[0].message.content)
# Example with qwen3-coder-flash model
response_flash = client.chat.completions.create(
model='qwen3-coder-flash',
messages=[
{'role': 'user', 'content': 'Write a simple Hello World function in Python'}
]
)
print(response_flash.choices[0].message.content)
# Example with vision-model
response_vision = client.chat.completions.create(
model='vision-model',
messages=[
{'role': 'user', 'content': 'Describe this image if you can see it'}
]
)
print(response_vision.choices[0].message.content)
`);