first commit

This commit is contained in:
2026-06-09 14:50:53 +08:00
commit 6aebc60bfd
55 changed files with 3126 additions and 0 deletions

9
src/302ai/__test__.js Normal file
View File

@@ -0,0 +1,9 @@
import { get302AiReply } from './index.js'
// 测试 302 ai api
async function testMessage() {
const message = await get302AiReply('hello')
console.log('🌸🌸🌸 / message: ', message)
}
testMessage()

41
src/302ai/index.js Normal file
View File

@@ -0,0 +1,41 @@
import axios from 'axios'
import dotenv from 'dotenv'
dotenv.config()
const env = dotenv.config().parsed
const key = env._302AI_API_KEY
const model = env._302AI_MODEL ? env._302AI_MODEL : 'gpt-4o-mini'
function setConfig(prompt) {
return {
method: 'post',
url: 'https://api.302.ai/v1/chat/completions',
headers: {
Accept: 'application/json',
Authorization: `Bearer ${key}`,
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'application/json',
},
data: JSON.stringify({
model: model,
messages: [
{
role: 'user',
content: prompt,
},
],
}),
}
}
export async function get302AiReply(prompt) {
try {
const config = setConfig(prompt)
const response = await axios(config)
const { choices } = response.data
return choices[0].message.content
} catch (error) {
console.error(error.code)
console.error(error.message)
}
}