ratapi
v1.0.0
Published
RatAPI是一个Node.js模块,用于调用各种常用API
Downloads
63
Readme
RatAPI
一个快速调用API的npm包,基于Axios实现HTTP请求,方便Node.js项目调用各种常用API。
安装
使用pnpm安装:
pnpm add ratapi使用npm安装:
npm install ratapi使用示例
初始化
const ratapi = require('ratapi');调用DeepSeek V3.2 API
async function example() {
try {
const result = await ratapi.deepSeek('你好,世界!', {
system: '你是一个智能助手',
type: 'text'
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();调用快手可图绘画API
async function example() {
try {
const result = await ratapi.ksDraw('一只可爱的小猫', {
size: '512x512',
guidance: 7.5,
batch: 1
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();调用必应新闻资讯API
async function example() {
try {
const result = await ratapi.bingNews({
page: 5,
type: 'json'
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();调用聚合语音生成API
async function example() {
try {
const result = await ratapi.voiceGenerate('欢迎使用RatAPI', {
voice: '标准女声',
format: 'mp3',
download: false
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();通用GET请求
async function example() {
try {
const result = await ratapi.get('example.php', {
param1: 'value1',
param2: 'value2'
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();通用POST请求
async function example() {
try {
const result = await ratapi.post('example.php', {
param1: 'value1',
param2: 'value2'
});
console.log(result);
} catch (error) {
console.error(error);
}
}
example();API文档
deepSeek(question, options)
调用DeepSeek V3.2 API
question(string): 提问内容options(object): 可选参数system(string): 模型提示词type(string): 支持text和json两种返回方式,不填写默认text,填true为纯文本输出
- 返回值: Promise - API响应内容
ksDraw(msg, options)
调用快手可图绘画API
msg(string): 绘画内容options(object): 可选参数size(string): 图像大小,支持256x256, 512x512, 768x768, 1024x1024, 1536x1536。默认1024x1024大小guidance(number): 【1-10任选,默认7.5】控制生成的图像与给定提示之间的匹配程度batch(number): 输出的图像数量,最大支持4张,默认为1张
- 返回值: Promise - API响应内容
bingNews(options)
调用必应新闻资讯API
options(object): 可选参数page(string): 获取的新闻数量,支持1-100个或者auto获取全部,不填写默认返回前10个type(string): 返回的数据格式,支持json和text,不填写默认返回json格式
- 返回值: Promise - API响应内容
voiceGenerate(msg, options)
调用聚合语音生成API
msg(string): 生成内容options(object): 可选参数voice(string): 语音生成的音色,不填写任何参数会输出支持的所有语音列表,默认使用标准女声format(string): 语音转化格式,支持mp3和wav,不填写默认返回mp3download(boolean): 语音返回格式,支持true(直接返回下载音频)和false(直接返回json数据),不填写默认为false
- 返回值: Promise - API响应内容
get(endpoint, params)
通用GET请求方法
endpoint(string): API端点params(object): 请求参数- 返回值: Promise - API响应内容
post(endpoint, data)
通用POST请求方法
endpoint(string): API端点data(object): 请求数据- 返回值: Promise - API响应内容
测试
运行测试:
pnpm test或
npm test注意事项
- 本包基于yunzhiapi.cn提供的API接口,使用前请确保您了解并遵守相关API的使用条款
- 部分API可能需要申请API密钥,请根据实际情况进行配置
- 如有任何问题,请提交issue或联系作者
许可证
MIT
