chore: add tests for kevisual and common environment variable resolution
This commit is contained in:
51
test/common.ts
Normal file
51
test/common.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { Kevisual } from '../src/provider/index';
|
||||||
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
||||||
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
||||||
|
import { generateText } from 'ai';
|
||||||
|
|
||||||
|
export function resolveEnvVars(value: string): string {
|
||||||
|
return value.replace(/{env:([^}]+)}/g, (_, varName) => {
|
||||||
|
const envValue = process.env[varName];
|
||||||
|
if (!envValue) {
|
||||||
|
throw new Error(`Environment variable ${varName} is not set`);
|
||||||
|
}
|
||||||
|
return envValue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export const models = {
|
||||||
|
'doubao-ark-code-latest': 'doubao-ark-code-latest',
|
||||||
|
'GLM-4.7': 'GLM-4.7',
|
||||||
|
'MiniMax-M2.1': 'MiniMax-M2.1',
|
||||||
|
'qwen3-coder-plus': 'qwen3-coder-plus',
|
||||||
|
'hunyuan-a13b': 'hunyuan-a13b',
|
||||||
|
}
|
||||||
|
export const bailian = createOpenAICompatible({
|
||||||
|
baseURL: 'https://coding.dashscope.aliyuncs.com/v1',
|
||||||
|
name: 'custom-bailian',
|
||||||
|
apiKey: process.env.BAILIAN_CODE_API_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const zhipu = createOpenAICompatible({
|
||||||
|
baseURL: 'https://open.bigmodel.cn/api/coding/paas/v4',
|
||||||
|
name: 'custom-zhipu',
|
||||||
|
apiKey: process.env.ZHIPU_API_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const minimax = createAnthropic({
|
||||||
|
baseURL: 'https://api.minimaxi.com/anthropic/v1',
|
||||||
|
name: 'custom-minimax',
|
||||||
|
apiKey: process.env.MINIMAX_API_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const doubao = createOpenAICompatible({
|
||||||
|
baseURL: 'https://ark.cn-beijing.volces.com/api/coding/v3',
|
||||||
|
name: 'custom-doubao',
|
||||||
|
apiKey: process.env.DOUBAO_API_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
export const cnb = createOpenAICompatible({
|
||||||
|
baseURL: resolveEnvVars('https://api.cnb.cool/{env:CNB_REPO_SLUG}/-/ai/'),
|
||||||
|
name: 'custom-cnb',
|
||||||
|
apiKey: process.env.CNB_API_KEY!,
|
||||||
|
});
|
||||||
34
test/kevisual.ts
Normal file
34
test/kevisual.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
||||||
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
||||||
|
import { generateText } from 'ai';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
|
// 使用 custom-kevisual provider (聚合了多个模型)
|
||||||
|
const kevisual = createOpenAICompatible({
|
||||||
|
baseURL: 'https://newapi.kevisual.cn/v1',
|
||||||
|
name: 'custom-kevisual',
|
||||||
|
apiKey: process.env.KEVISUAL_NEW_API_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
const kevisualAnthropic = createAnthropic({
|
||||||
|
baseURL: "https://newapi.kevisual.cn/v1",
|
||||||
|
apiKey: process.env.KEVISUAL_NEW_API_KEY!,
|
||||||
|
})
|
||||||
|
|
||||||
|
// 测试所有可用模型
|
||||||
|
// const models = ['qwen3-coder-plus', 'ark-code-latest', 'GLM-4.7', 'MiniMax-M2.1'];
|
||||||
|
const models = ['MiniMax-M2.5'];
|
||||||
|
|
||||||
|
for (const model of models) {
|
||||||
|
console.log(`\n=== Testing model: ${model} ===`);
|
||||||
|
try {
|
||||||
|
const { text } = await generateText({
|
||||||
|
// model: kevisualAnthropic(model),
|
||||||
|
model: kevisual(model),
|
||||||
|
prompt: 'Say hello in one sentence.',
|
||||||
|
});
|
||||||
|
console.log(`Response: ${text}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user