Files changed (1) hide show
  1. Aaa +206 -0
Aaa ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>OpenAI API Request Tester</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ max-width: 800px;
11
+ margin: 0 auto;
12
+ padding: 20px;
13
+ background-color: #f0f0f0;
14
+ }
15
+ h1, h2 {
16
+ color: #333;
17
+ text-align: center;
18
+ }
19
+ .input-group {
20
+ margin-bottom: 15px;
21
+ }
22
+ label {
23
+ display: block;
24
+ margin-bottom: 5px;
25
+ font-weight: bold;
26
+ color: #555;
27
+ }
28
+ textarea, input[type="text"] {
29
+ width: 100%;
30
+ padding: 8px;
31
+ border: 1px solid #ddd;
32
+ border-radius: 4px;
33
+ box-sizing: border-box;
34
+ }
35
+ textarea {
36
+ height: 100px;
37
+ resize: vertical;
38
+ }
39
+ button {
40
+ display: block;
41
+ width: 100%;
42
+ padding: 10px;
43
+ background-color: #4CAF50;
44
+ color: white;
45
+ border: none;
46
+ border-radius: 4px;
47
+ cursor: pointer;
48
+ font-size: 16px;
49
+ }
50
+ button:hover {
51
+ background-color: #45a049;
52
+ }
53
+ #results, #progress, #successfulUrls {
54
+ margin-top: 20px;
55
+ padding: 10px;
56
+ background-color: white;
57
+ border-radius: 4px;
58
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
59
+ }
60
+ .success {
61
+ color: green;
62
+ }
63
+ .error {
64
+ color: red;
65
+ }
66
+ .copyable {
67
+ cursor: pointer;
68
+ color: blue;
69
+ text-decoration: underline;
70
+ }
71
+ </style>
72
+ </head>
73
+ <body>
74
+ <h1>OpenAI API Request Tester</h1>
75
+ <div class="input-group">
76
+ <label for="baseUrls">Base URLs:</label>
77
+ <textarea id="baseUrls" placeholder="Enter base URLs, one per line">http://45.159.211.109:7777
78
+ http://45.159.208.90:8444
79
+ http://118.25.198.103:8444
80
+ http://45.159.208.220:5555
81
+ http://194.36.209.120:8444
82
+ http://198.144.180.166:8444</textarea>
83
+ </div>
84
+ <div class="input-group">
85
+ <label for="apiKey">API Key:</label>
86
+ <input type="text" id="apiKey" placeholder="Enter API Key" value="aaa">
87
+ </div>
88
+ <div class="input-group">
89
+ <label for="model">Model:</label>
90
+ <input type="text" id="model" value="claude-3-haiku-20240307">
91
+ </div>
92
+ <div class="input-group">
93
+ <label for="prompt">Prompt:</label>
94
+ <input type="text" id="prompt" value="hi">
95
+ </div>
96
+ <button onclick="testUrls()">Test URLs</button>
97
+ <div id="progress"></div>
98
+ <div id="results"></div>
99
+ <h2>Successful URLs (Status 200)</h2>
100
+ <div id="successfulUrls"></div>
101
+
102
+ <script>
103
+ async function openaiRequest(prompt, baseUrl, apiKey, model) {
104
+ const headers = {
105
+ 'Content-Type': 'application/json',
106
+ 'Authorization': `Bearer ${apiKey}`
107
+ };
108
+
109
+ const body = {
110
+ model: model,
111
+ messages: [
112
+ {
113
+ role: "user",
114
+ content: prompt
115
+ }
116
+ ]
117
+ };
118
+
119
+ const controller = new AbortController();
120
+ const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 seconds timeout
121
+
122
+ try {
123
+ const response = await fetch(`${baseUrl}/v1/chat/completions`, {
124
+ method: 'POST',
125
+ headers: headers,
126
+ body: JSON.stringify(body),
127
+ signal: controller.signal
128
+ });
129
+ clearTimeout(timeoutId);
130
+
131
+ if (response.status === 200) {
132
+ const data = await response.json();
133
+ return {
134
+ status: response.status,
135
+ ok: response.ok,
136
+ text: data.choices[0].message.content
137
+ };
138
+ }
139
+
140
+ return {
141
+ status: response.status,
142
+ ok: response.ok
143
+ };
144
+ } catch (error) {
145
+ clearTimeout(timeoutId);
146
+ console.error('Error:', error);
147
+ return {
148
+ status: 'Error',
149
+ ok: false,
150
+ error: error.name === 'AbortError' ? 'Request timed out' : error.message
151
+ };
152
+ }
153
+ }
154
+
155
+ async function testUrls() {
156
+ const baseUrls = document.getElementById('baseUrls').value.split('\n').filter(url => url.trim() !== '');
157
+ const apiKey = document.getElementById('apiKey').value;
158
+ const model = document.getElementById('model').value;
159
+ const prompt = document.getElementById('prompt').value;
160
+ const resultsDiv = document.getElementById('results');
161
+ const progressDiv = document.getElementById('progress');
162
+ const successfulUrlsDiv = document.getElementById('successfulUrls');
163
+ resultsDiv.innerHTML = '';
164
+ progressDiv.innerHTML = '';
165
+ successfulUrlsDiv.innerHTML = '';
166
+
167
+ const successfulUrls = [];
168
+
169
+ for (const baseUrl of baseUrls) {
170
+ progressDiv.innerHTML = `正在检测 ${baseUrl}...`;
171
+ const result = await openaiRequest(prompt, baseUrl.trim(), apiKey, model);
172
+ const statusClass = result.ok ? 'success' : 'error';
173
+ let statusText = result.status;
174
+ if (result.error) {
175
+ statusText += ` (${result.error})`;
176
+ }
177
+ if (result.text) {
178
+ statusText += `<br>回复: ${result.text}`;
179
+ }
180
+ resultsDiv.innerHTML += `<p>${baseUrl}: <span class="${statusClass}">${statusText}</span></p>`;
181
+
182
+ if (result.status === 200) {
183
+ successfulUrls.push(baseUrl.trim());
184
+ }
185
+ }
186
+ progressDiv.innerHTML = '检测完成!';
187
+
188
+ if (successfulUrls.length > 0) {
189
+ successfulUrlsDiv.innerHTML = successfulUrls.map(url =>
190
+ `<p><span class="copyable" onclick="copyToClipboard('${url}')">${url}</span></p>`
191
+ ).join('');
192
+ } else {
193
+ successfulUrlsDiv.innerHTML = '<p>没有状态码为200的URL</p>';
194
+ }
195
+ }
196
+
197
+ function copyToClipboard(text) {
198
+ navigator.clipboard.writeText(text).then(() => {
199
+ alert('URL已复制到剪贴板');
200
+ }).catch(err => {
201
+ console.error('无法复制URL: ', err);
202
+ });
203
+ }
204
+ </script>
205
+ </body>
206
+ </html>