rc-plugin/utils/openai-builder.js
zhiyu1998 75d10fbd45 🦄 refactor: 优化 OpenaiBuilder 类和工具模块代码结构
- 移除 utils/openai-builder.js 中不再使用的 import 语句和方法
- 简化 apps/tools.js 中的下载队列逻辑,直接执行下载任务
- 移除 package.json 中不再使用的依赖项
- 确保代码清晰和功能正常运行,提升代码可维护性
- 优化哔哩哔哩视频下载流程,提高下载效率和稳定性
- 修复潜在的文件路径问题,确保文件操作安全有效
- 移除冗余的上传至小飞机逻辑,简化代码结构
- 优化视频预览功能,提升用户体验和操作便捷性
2024-09-19 21:42:45 +08:00

72 lines
1.7 KiB
JavaScript

import axios from "axios";
export class OpenaiBuilder {
constructor() {
this.baseURL = "https://api.moonshot.cn"; // 默认模型
this.apiKey = ""; // 默认API密钥
this.prompt = "描述一下这个图片"; // 默认提示
this.model = 'claude-3-haiku-20240307'
this.path = ''; // 上传文件的路径
}
setBaseURL(baseURL) {
this.baseURL = baseURL;
return this;
}
setApiKey(apiKey) {
this.apiKey = apiKey;
return this;
}
setPrompt(prompt) {
this.prompt = prompt;
return this;
}
setModel(model) {
this.model = model;
return this;
}
setPath(path) {
this.path = path;
return this;
}
async build() {
// logger.info(this.baseURL, this.apiKey)
// 创建客户端
this.client = axios.create({
baseURL: this.baseURL,
timeout: 10000,
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + this.apiKey
}
});
return this;
}
async kimi(query) {
// 请求Kimi
const completion = await this.client.post("/v1/chat/completions", {
model: "moonshot-v1-8k",
messages: [
{
"role": "system",
"content": this.prompt,
},
{
role: "user",
content: query
},
],
});
return {
"model": "月之暗面 Kimi",
"ans": completion.choices[0].message.content
}
}
}