@keo-ai/axiom 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -179,6 +179,7 @@ for await (const chunk of LLM.streamPredict({ model: 'qwen3.7-max', prompt: '讲
179
179
  - `deepseek-v4-pro`
180
180
  - `deepseek-v4-flash`
181
181
  - `kimi-k2.6`
182
+ - `glm-5.1`
182
183
  - `qwen-vl-plus`
183
184
 
184
185
  > 目前所有模型均路由到百炼 Provider。后续接入其他厂商时,通过 `MODEL_REGISTRY` 扩展映射即可。
@@ -47,14 +47,16 @@ function createLLMCaller(options) {
47
47
  call(messages, tools, callOptions) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
49
  var _a, _b;
50
- const data = yield (0, llm_provider_1.callChatCompletions)(options.baseUrl, options.apiKey, {
50
+ const body = (0, llm_provider_1.adaptRequestForModel)({
51
51
  model: (_a = callOptions === null || callOptions === void 0 ? void 0 : callOptions.model) !== null && _a !== void 0 ? _a : options.defaultModel,
52
52
  messages: toOpenAIMessages(messages),
53
53
  temperature: callOptions === null || callOptions === void 0 ? void 0 : callOptions.temperature,
54
54
  max_tokens: callOptions === null || callOptions === void 0 ? void 0 : callOptions.maxTokens,
55
55
  top_p: callOptions === null || callOptions === void 0 ? void 0 : callOptions.topP,
56
56
  tools: tools.length > 0 ? toOpenAITools(tools) : undefined,
57
- }, 'llm');
57
+ reasoning_effort: callOptions === null || callOptions === void 0 ? void 0 : callOptions.reasoningEffort,
58
+ });
59
+ const data = yield (0, llm_provider_1.callChatCompletions)(options.baseUrl, options.apiKey, body, 'llm');
58
60
  const choice = data.choices[0];
59
61
  return {
60
62
  content: choice.message.content,
@@ -45,8 +45,8 @@ class BailianProvider {
45
45
  generate(request) {
46
46
  return __awaiter(this, void 0, void 0, function* () {
47
47
  var _a;
48
- const body = this.buildRequestBody(request);
49
- const data = yield (0, index_1.callChatCompletions)(this.config.baseUrl, this.config.apiKey, Object.assign(Object.assign({}, body), { stream: false }), this.name);
48
+ const body = (0, index_1.adaptRequestForModel)(Object.assign(Object.assign({}, this.buildRequestBody(request)), { stream: false }));
49
+ const data = yield (0, index_1.callChatCompletions)(this.config.baseUrl, this.config.apiKey, body, this.name);
50
50
  const choice = data.choices[0];
51
51
  return {
52
52
  content: choice.message.content,
@@ -71,7 +71,7 @@ class BailianProvider {
71
71
  return __asyncGenerator(this, arguments, function* stream_1() {
72
72
  var _a, _b;
73
73
  const url = `${this.config.baseUrl}/chat/completions`;
74
- const body = this.buildRequestBody(request);
74
+ const body = (0, index_1.adaptRequestForModel)(Object.assign(Object.assign({}, this.buildRequestBody(request)), { stream: true }));
75
75
  let response;
76
76
  try {
77
77
  response = yield __await(fetch(url, {
@@ -80,7 +80,7 @@ class BailianProvider {
80
80
  'Content-Type': 'application/json',
81
81
  Authorization: `Bearer ${this.config.apiKey}`,
82
82
  },
83
- body: JSON.stringify(Object.assign(Object.assign({}, body), { stream: true })),
83
+ body: JSON.stringify(body),
84
84
  }));
85
85
  }
86
86
  catch (cause) {
@@ -170,5 +170,6 @@ BailianProvider.SUPPORTED_MODELS = new Set([
170
170
  'deepseek-v4-pro',
171
171
  'deepseek-v4-flash',
172
172
  'kimi-k2.6',
173
+ 'glm-5.1',
173
174
  'qwen-vl-plus',
174
175
  ]);
@@ -34,6 +34,7 @@ export interface OpenAIChatRequest {
34
34
  type: 'text' | 'json_object';
35
35
  };
36
36
  stream?: boolean;
37
+ reasoning_effort?: 'low' | 'medium' | 'high';
37
38
  }
38
39
  export interface OpenAIChatResponse {
39
40
  choices: Array<{
@@ -63,9 +64,14 @@ export interface OpenAIChatResponse {
63
64
  * 业务层(请求体组装、结果转换)由调用方负责。
64
65
  */
65
66
  export declare function callChatCompletions(baseUrl: string, apiKey: string, body: OpenAIChatRequest, errorPrefix?: string): Promise<OpenAIChatResponse>;
67
+ /**
68
+ * 根据模型能力校验并适配 OpenAI 请求体。
69
+ * 若调用方明确要求了模型不支持的能力,直接抛异常。
70
+ */
71
+ export declare function adaptRequestForModel(body: OpenAIChatRequest): OpenAIChatRequest;
66
72
  /** 模型枚举与注册表 */
67
- export type { Model, ModelConfig } from './models';
68
- export { MODEL_REGISTRY } from './models';
73
+ export type { Model, ModelConfig, ModelCapabilities } from './models';
74
+ export { MODEL_REGISTRY, MODEL_CAPABILITIES, getModelCapabilities } from './models';
69
75
  /** 标准化类型 */
70
76
  export type { Message, LLMRequest, LLMResponse, ProviderConfig, StreamChunk } from './types';
71
77
  /** Provider 接口与实现 */
@@ -13,8 +13,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
13
13
  });
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.BailianProvider = exports.MODEL_REGISTRY = void 0;
16
+ exports.BailianProvider = exports.getModelCapabilities = exports.MODEL_CAPABILITIES = exports.MODEL_REGISTRY = void 0;
17
17
  exports.callChatCompletions = callChatCompletions;
18
+ exports.adaptRequestForModel = adaptRequestForModel;
18
19
  /**
19
20
  * 发送 OpenAI 兼容的 chat completions 请求。
20
21
  * 只做 HTTP 层:构造请求、fetch、错误处理、基础解析。
@@ -56,7 +57,25 @@ function callChatCompletions(baseUrl_1, apiKey_1, body_1) {
56
57
  return data;
57
58
  });
58
59
  }
59
- var models_1 = require("./models");
60
- Object.defineProperty(exports, "MODEL_REGISTRY", { enumerable: true, get: function () { return models_1.MODEL_REGISTRY; } });
60
+ const models_1 = require("./models");
61
+ /**
62
+ * 根据模型能力校验并适配 OpenAI 请求体。
63
+ * 若调用方明确要求了模型不支持的能力,直接抛异常。
64
+ */
65
+ function adaptRequestForModel(body) {
66
+ var _a;
67
+ const caps = (0, models_1.getModelCapabilities)(body.model);
68
+ if (body.reasoning_effort !== undefined && !caps.reasoningEffort) {
69
+ throw new Error(`[adapt] Model "${body.model}" does not support reasoning_effort`);
70
+ }
71
+ if (((_a = body.response_format) === null || _a === void 0 ? void 0 : _a.type) === 'json_object' && !caps.jsonMode) {
72
+ throw new Error(`[adapt] Model "${body.model}" does not support response_format json_object`);
73
+ }
74
+ return body;
75
+ }
76
+ var models_2 = require("./models");
77
+ Object.defineProperty(exports, "MODEL_REGISTRY", { enumerable: true, get: function () { return models_2.MODEL_REGISTRY; } });
78
+ Object.defineProperty(exports, "MODEL_CAPABILITIES", { enumerable: true, get: function () { return models_2.MODEL_CAPABILITIES; } });
79
+ Object.defineProperty(exports, "getModelCapabilities", { enumerable: true, get: function () { return models_2.getModelCapabilities; } });
61
80
  var bailian_1 = require("./bailian");
62
81
  Object.defineProperty(exports, "BailianProvider", { enumerable: true, get: function () { return bailian_1.BailianProvider; } });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 支持的模型枚举。项目层通过此枚举选择模型,Axiom 内部路由到对应 Provider。
3
3
  */
4
- export type Model = 'qwen3.7-max' | 'qwen-plus' | 'qwen-turbo' | 'qwq-plus' | 'deepseek-v4-pro' | 'deepseek-v4-flash' | 'kimi-k2.6' | 'qwen-vl-plus';
4
+ export type Model = 'qwen3.7-max' | 'qwen-plus' | 'qwen-turbo' | 'qwq-plus' | 'deepseek-v4-pro' | 'deepseek-v4-flash' | 'kimi-k2.6' | 'glm-5.1' | 'qwen-vl-plus';
5
5
  /** 模型到 Provider 的映射配置 */
6
6
  export interface ModelConfig {
7
7
  readonly model: string;
@@ -12,3 +12,17 @@ export interface ModelConfig {
12
12
  * 当首选 Provider 失败时,Predictor 按此表顺序尝试下一个。
13
13
  */
14
14
  export declare const MODEL_REGISTRY: Readonly<Record<Model, ReadonlyArray<ModelConfig>>>;
15
+ /** 模型能力配置 */
16
+ export interface ModelCapabilities {
17
+ /** 是否原生支持 response_format: { type: 'json_object' } */
18
+ readonly jsonMode: boolean;
19
+ /** 是否原生支持 reasoning_effort 参数 */
20
+ readonly reasoningEffort: boolean;
21
+ }
22
+ /**
23
+ * 模型能力矩阵。
24
+ * 未列出的模型默认视为不支持 jsonMode 和 reasoningEffort。
25
+ */
26
+ export declare const MODEL_CAPABILITIES: Readonly<Record<string, ModelCapabilities>>;
27
+ /** 获取指定模型的能力配置 */
28
+ export declare function getModelCapabilities(model: string): ModelCapabilities;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MODEL_REGISTRY = void 0;
3
+ exports.MODEL_CAPABILITIES = exports.MODEL_REGISTRY = void 0;
4
+ exports.getModelCapabilities = getModelCapabilities;
4
5
  /**
5
6
  * 模型注册表。每个模型对应一个或多个 Provider 候选,按优先级排序。
6
7
  * 当首选 Provider 失败时,Predictor 按此表顺序尝试下一个。
@@ -13,5 +14,27 @@ exports.MODEL_REGISTRY = {
13
14
  'deepseek-v4-pro': [{ model: 'deepseek-v4-pro', provider: 'bailian' }],
14
15
  'deepseek-v4-flash': [{ model: 'deepseek-v4-flash', provider: 'bailian' }],
15
16
  'kimi-k2.6': [{ model: 'kimi-k2.6', provider: 'bailian' }],
17
+ 'glm-5.1': [{ model: 'glm-5.1', provider: 'bailian' }],
16
18
  'qwen-vl-plus': [{ model: 'qwen-vl-plus', provider: 'bailian' }],
17
19
  };
20
+ /**
21
+ * 模型能力矩阵。
22
+ * 未列出的模型默认视为不支持 jsonMode 和 reasoningEffort。
23
+ */
24
+ exports.MODEL_CAPABILITIES = {
25
+ 'qwen-max': { jsonMode: true, reasoningEffort: false },
26
+ 'qwen3.7-max': { jsonMode: true, reasoningEffort: false },
27
+ 'qwen-plus': { jsonMode: true, reasoningEffort: false },
28
+ 'qwen-turbo': { jsonMode: true, reasoningEffort: false },
29
+ 'qwq-plus': { jsonMode: true, reasoningEffort: false },
30
+ 'deepseek-v4-pro': { jsonMode: true, reasoningEffort: false },
31
+ 'deepseek-v4-flash': { jsonMode: true, reasoningEffort: false },
32
+ 'kimi-k2.6': { jsonMode: true, reasoningEffort: false },
33
+ 'glm-5.1': { jsonMode: false, reasoningEffort: false },
34
+ 'qwen-vl-plus': { jsonMode: true, reasoningEffort: false },
35
+ };
36
+ /** 获取指定模型的能力配置 */
37
+ function getModelCapabilities(model) {
38
+ var _a;
39
+ return (_a = exports.MODEL_CAPABILITIES[model]) !== null && _a !== void 0 ? _a : { jsonMode: false, reasoningEffort: false };
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keo-ai/axiom",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "基于 LLM 的预测与推理库,支持多 Provider 切换",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",