AI的API
查询第三方AI的API接口模型
在线使用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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API模型查询</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 40px;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
h1 {
color: #2c3e50;
text-align: center;
margin-bottom: 30px;
font-size: 2.5em;
}
.input-container {
background-color: #ffffff;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
input, button {
display: block;
width: 100%;
padding: 12px;
margin: 15px 0;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
transition: all 0.3s ease;
}
input:focus {
border-color: #3498db;
box-shadow: 0 0 5px rgba(52, 152, 219, 0.5);
outline: none;
}
button {
background-color: #3498db;
color: white;
border: none;
cursor: pointer;
font-weight: bold;
}
button:hover {
background-color: #2980b9;
}
#result {
margin-top: 30px;
background-color: #ffffff;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
ul {
list-style-type: none;
padding: 0;
}
li {
padding: 12px;
background-color: #f8f9fa;
margin-bottom: 8px;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s ease;
}
li:hover {
background-color: #e9ecef;
}
.copy-button {
background-color: #2ecc71;
color: white;
border: none;
padding: 12px 24px;
border-radius: 4px;
cursor: pointer;
margin-top: 15px;
font-weight: bold;
}
.copy-button:hover {
background-color: #27ae60;
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 20px auto;
display: none;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.error-message {
color: #e74c3c;
background-color: #fdf3f2;
border: 1px solid #e74c3c;
padding: 10px;
border-radius: 4px;
margin-top: 15px;
}
@media (max-width: 600px) {
body {
padding: 20px;
}
h1 {
font-size: 2em;
}
.input-container, #result {
padding: 20px;
}
}
.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background-color: #34495e;
color: white;
padding: 10px 20px;
border-radius: 4px;
display: none;
}
</style>
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🤖</text></svg>">
</head>
<body>
<h1>API模型查询</h1>
<div class="input-container">
<input type="text" id="urlInput" placeholder="请输入URL地址" title="例如:api.openai.com">
<input type="text" id="apiKeyInput" placeholder="请输入API密钥" title="请输入您的API密钥">
<button onclick="getModels()" aria-label="查询可用模型">查询可用模型</button>
</div>
<div id="result"></div>
<div id="loader" class="loader"></div>
<div id="toast" class="toast"></div>
<script>
let modelsList = [];
async function getModels() {
let url = document.getElementById('urlInput').value.trim();
const apiKey = document.getElementById('apiKeyInput').value.trim();
const resultDiv = document.getElementById('result');
const loader = document.getElementById('loader');
if (!url || !apiKey) {
resultDiv.innerHTML = '<p style="color: #e74c3c;">请填写URL和API密钥</p>';
return;
}
// 如果URL不以http://或https://开头,则添加https://
if (!/^https?:\/\//i.test(url)) {
url = 'https://' + url;
}
loader.style.display = 'block';
try {
const response = await fetch(url + '/v1/models', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
modelsList = data.data.map(model => model.id);
resultDiv.innerHTML = `<h2>可用模型 (${modelsList.length}):</h2>` +
'<ul>' + modelsList.map(model => `<li onclick="copyModel('${model}')">${model}</li>`).join('') + '</ul>' +
'<button class="copy-button" onclick="copyModels()">复制模型列表</button>';
} catch (error) {
resultDiv.innerHTML = `<div class="error-message">错误: ${error.message}</div>`;
} finally {
loader.style.display = 'none';
}
}
function copyModels() {
const modelString = modelsList.join(',');
copyToClipboard(modelString, '模型列表已复制到剪贴板!');
}
function copyModel(model) {
copyToClipboard(model, `模型 "${model}" 已复制到剪贴板!`);
}
async function copyToClipboard(text, successMessage) {
try {
await navigator.clipboard.writeText(text);
showToast(successMessage);
} catch (err) {
console.error('无法复制文本: ', err);
showToast('复制失败,请手动复制。');
}
}
function showToast(message) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.style.display = 'block';
setTimeout(() => {
toast.style.display = 'none';
}, 3000);
}
document.addEventListener('DOMContentLoaded', () => {
const apiKeyInput = document.getElementById('apiKeyInput');
apiKeyInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
getModels();
}
});
});
</script>
</body>
</html>