feat: 更新依赖项,重构 fetch 逻辑,添加工具路由和代理功能
This commit is contained in:
@@ -2,6 +2,24 @@ import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
||||
import { createAnthropic } from '@ai-sdk/anthropic';
|
||||
import { generateText } from 'ai';
|
||||
import 'dotenv/config';
|
||||
import util from 'node:util';
|
||||
// 保存原始 fetch 引用
|
||||
const originalFetch = fetch;
|
||||
|
||||
export const defaultFetch = {
|
||||
fetch: async (input: string | URL | Request, init?: BunFetchRequestInit) => {
|
||||
console.log('请求 URL:', input);
|
||||
console.log('请求选项:', init);
|
||||
|
||||
const response = await originalFetch(input, init); // 调用原始 fetch
|
||||
|
||||
console.log('响应状态:', response.status);
|
||||
const responseBody = await response.clone().text(); // 使用 clone 避免消耗原始 response
|
||||
console.log('响应体:', responseBody);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export function resolveEnvVars(value: string): string {
|
||||
return value.replace(/{env:([^}]+)}/g, (_, varName) => {
|
||||
@@ -19,6 +37,8 @@ export const models = {
|
||||
'MiniMax-M2.1': 'MiniMax-M2.1',
|
||||
'qwen3-coder-plus': 'qwen3-coder-plus',
|
||||
'hunyuan-a13b': 'hunyuan-a13b',
|
||||
'qwen-plus': 'qwen-plus',
|
||||
'auto': 'AUTO_Models',
|
||||
}
|
||||
export const bailian = createOpenAICompatible({
|
||||
baseURL: 'https://coding.dashscope.aliyuncs.com/v1',
|
||||
@@ -36,6 +56,7 @@ export const minimax = createAnthropic({
|
||||
baseURL: 'https://api.minimaxi.com/anthropic/v1',
|
||||
name: 'custom-minimax',
|
||||
apiKey: process.env.MINIMAX_API_KEY!,
|
||||
fetch: defaultFetch.fetch as any
|
||||
});
|
||||
|
||||
export const doubao = createOpenAICompatible({
|
||||
@@ -44,8 +65,20 @@ export const doubao = createOpenAICompatible({
|
||||
apiKey: process.env.DOUBAO_API_KEY!,
|
||||
});
|
||||
|
||||
|
||||
export const cnb = createOpenAICompatible({
|
||||
baseURL: resolveEnvVars('https://api.cnb.cool/{env:CNB_REPO_SLUG}/-/ai/'),
|
||||
baseURL: 'https://api.cnb.cool/kevisual/kevisual/-/ai/',
|
||||
// baseURL: resolveEnvVars('https://api.cnb.cool/{env:CNB_REPO_SLUG}/-/ai/'),
|
||||
name: 'custom-cnb',
|
||||
apiKey: process.env.CNB_API_KEY!,
|
||||
fetch: defaultFetch.fetch as any
|
||||
});
|
||||
export const proxyCnb = createOpenAICompatible({
|
||||
baseURL: 'http://localhost:4005/api',
|
||||
name: 'proxy-cnb',
|
||||
apiKey: process.env.CNB_API_KEY!,
|
||||
});
|
||||
|
||||
export const showMore = (obj: any) => {
|
||||
return util.inspect(obj, { depth: null, colors: true });
|
||||
}
|
||||
Reference in New Issue
Block a user