Skip to content

Commit fff77f3

Browse files
committed
chore: update readme
1 parent 932a3be commit fff77f3

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

README.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,78 @@ curl -X POST http://localhost:3000/v1/images/generations \
284284
"n": 2,
285285
"size": "1024x1024"
286286
}'
287-
```
287+
```
288+
289+
### 使用 OpenAI SDK 测试
290+
291+
```javascript
292+
import OpenAI from 'openai';
293+
294+
const client = new OpenAI({
295+
baseURL: 'http://localhost:3000/v1',
296+
apiKey: 'mock-key' // 可以是任意值
297+
});
298+
299+
// 测试聊天完成
300+
const completion = await client.chat.completions.create({
301+
model: 'mock-gpt-thinking',
302+
messages: [{ role: 'user', content: '你好' }]
303+
});
304+
305+
console.log(completion.choices[0].message.content);
306+
307+
// 测试流式聊天
308+
const stream = await client.chat.completions.create({
309+
model: 'mock-gpt-thinking',
310+
messages: [{ role: 'user', content: '你好' }],
311+
stream: true
312+
});
313+
314+
for await (const chunk of stream) {
315+
const content = chunk.choices[0]?.delta?.content || '';
316+
process.stdout.write(content);
317+
}
318+
319+
// 测试图像生成
320+
const image = await client.images.generate({
321+
model: 'gpt-4o-image',
322+
prompt: '一只可爱的橘猫',
323+
n: 1,
324+
size: '1024x1024'
325+
});
326+
327+
console.log(image.data[0].url);
328+
```
329+
330+
## 🤝 贡献
331+
332+
欢迎提交 Issue 和 Pull Request!
333+
334+
1. Fork 本项目
335+
2. 创建特性分支:`git checkout -b feature/AmazingFeature`
336+
3. 提交更改:`git commit -m 'Add some AmazingFeature'`
337+
4. 推送到分支:`git push origin feature/AmazingFeature`
338+
5. 提交 Pull Request
339+
340+
## 📄 许可证
341+
342+
本项目使用 MIT 许可证。详见 [LICENSE](LICENSE) 文件。
343+
344+
## 🔗 相关链接
345+
346+
- [OpenAI API 文档](https://platform.openai.com/docs/api-reference)
347+
- [Express.js](https://expressjs.com/)
348+
- [TypeScript](https://www.typescriptlang.org/)
349+
350+
## 💡 使用场景
351+
352+
- **前端开发**: 无需等待后端 API,快速开发和测试 AI 功能
353+
- **API 集成测试**: 验证应用程序与 OpenAI API 的集成
354+
- **演示和原型**: 创建不依赖真实 AI 服务的演示
355+
- **开发调试**: 调试流式响应、函数调用等复杂场景
356+
- **成本控制**: 避免开发阶段的 API 调用费用
357+
- **离线开发**: 在没有网络的情况下开发 AI 应用
358+
359+
## 🎉 结语
360+
361+
Mock OpenAI API 让您能够快速、可靠地开发和测试 AI 应用,无需担心 API 配额、网络连接或费用问题。开始您的 AI 应用开发之旅吧!

0 commit comments

Comments
 (0)