@keo-ai/axiom 0.1.6 → 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 +1 -3
- package/dist/function_call_loop/loop.js +1 -11
- package/dist/function_call_loop/provider.js +4 -5
- package/dist/function_call_loop/types.d.ts +0 -5
- package/dist/llm_provider/bailian.js +4 -4
- package/dist/llm_provider/index.d.ts +8 -2
- package/dist/llm_provider/index.js +22 -3
- package/dist/llm_provider/models.d.ts +14 -0
- package/dist/llm_provider/models.js +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -529,7 +529,6 @@ const result = await promise;
|
|
|
529
529
|
| `temperature` | `number` | — | 采样温度,范围 0~2 |
|
|
530
530
|
| `topP` | `number` | — | 核采样概率阈值,范围 0~1 |
|
|
531
531
|
| `reasoningEffort` | `'low' \| 'medium' \| 'high'` | — | 推理深度。仅部分模型支持(如 o1、o3) |
|
|
532
|
-
| `responseFormat` | `'text' \| 'json'` | — | 响应格式。`json` 时模型输出会被内部 `JSON.parse`,解析结果存到 `parsedContent` |
|
|
533
532
|
|
|
534
533
|
### 返回结果
|
|
535
534
|
|
|
@@ -537,9 +536,8 @@ const result = await promise;
|
|
|
537
536
|
interface LoopResult {
|
|
538
537
|
messages: Message[]; // 完整的对话历史
|
|
539
538
|
harness: HarnessRecord[]; // 执行历史
|
|
540
|
-
finalContent: string | null; //
|
|
539
|
+
finalContent: string | null; // 最终回复内容
|
|
541
540
|
turns: number; // 实际执行轮数
|
|
542
|
-
parsedContent?: unknown; // 仅当 responseFormat === 'json' 时存在,JSON.parse 后的结果
|
|
543
541
|
}
|
|
544
542
|
```
|
|
545
543
|
|
|
@@ -81,7 +81,6 @@ function runLoop(config) {
|
|
|
81
81
|
maxTokens: config.maxTokens,
|
|
82
82
|
topP: config.topP,
|
|
83
83
|
reasoningEffort: config.reasoningEffort,
|
|
84
|
-
responseFormat: config.responseFormat,
|
|
85
84
|
});
|
|
86
85
|
// 第六步:检查 LLM 回复
|
|
87
86
|
if (!llmResponse.tool_calls || llmResponse.tool_calls.length === 0) {
|
|
@@ -89,21 +88,12 @@ function runLoop(config) {
|
|
|
89
88
|
role: 'assistant',
|
|
90
89
|
content: (_f = llmResponse.content) !== null && _f !== void 0 ? _f : '',
|
|
91
90
|
});
|
|
92
|
-
|
|
91
|
+
return {
|
|
93
92
|
messages,
|
|
94
93
|
harness: harness.getAll(),
|
|
95
94
|
finalContent: llmResponse.content,
|
|
96
95
|
turns: turn,
|
|
97
96
|
};
|
|
98
|
-
if (config.responseFormat === 'json' && llmResponse.content) {
|
|
99
|
-
try {
|
|
100
|
-
Object.assign(result, { parsedContent: JSON.parse(llmResponse.content) });
|
|
101
|
-
}
|
|
102
|
-
catch (_h) {
|
|
103
|
-
// JSON 解析失败时保持 parsedContent 未定义,finalContent 仍为原始字符串
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
97
|
}
|
|
108
98
|
// 有 tool_calls,将 assistant message 加入 Messages
|
|
109
99
|
messages.push({
|
|
@@ -47,17 +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
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}, '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');
|
|
61
60
|
const choice = data.choices[0];
|
|
62
61
|
return {
|
|
63
62
|
content: choice.message.content,
|
|
@@ -144,7 +144,6 @@ export interface LLMCallOptions {
|
|
|
144
144
|
readonly maxTokens?: number;
|
|
145
145
|
readonly topP?: number;
|
|
146
146
|
readonly reasoningEffort?: 'low' | 'medium' | 'high';
|
|
147
|
-
readonly responseFormat?: 'text' | 'json';
|
|
148
147
|
}
|
|
149
148
|
/**
|
|
150
149
|
* LLM 调用接口。由外部注入,Loop 内部不绑定具体 Provider。
|
|
@@ -185,8 +184,6 @@ export interface LoopConfig {
|
|
|
185
184
|
readonly topP?: number;
|
|
186
185
|
/** 推理深度。仅部分模型支持 */
|
|
187
186
|
readonly reasoningEffort?: 'low' | 'medium' | 'high';
|
|
188
|
-
/** 响应格式。默认 text */
|
|
189
|
-
readonly responseFormat?: 'text' | 'json';
|
|
190
187
|
}
|
|
191
188
|
/**
|
|
192
189
|
* 待审批信息。
|
|
@@ -206,6 +203,4 @@ export interface LoopResult {
|
|
|
206
203
|
readonly finalContent: string | null;
|
|
207
204
|
readonly turns: number;
|
|
208
205
|
readonly pendingApproval?: PendingApprovalInfo;
|
|
209
|
-
/** 当 responseFormat === 'json' 时,finalContent 经 JSON.parse 后的结果 */
|
|
210
|
-
readonly parsedContent?: unknown;
|
|
211
206
|
}
|
|
@@ -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,
|
|
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(
|
|
83
|
+
body: JSON.stringify(body),
|
|
84
84
|
}));
|
|
85
85
|
}
|
|
86
86
|
catch (cause) {
|
|
@@ -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
|
-
|
|
60
|
-
|
|
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; } });
|
|
@@ -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 按此表顺序尝试下一个。
|
|
@@ -16,3 +17,24 @@ exports.MODEL_REGISTRY = {
|
|
|
16
17
|
'glm-5.1': [{ model: 'glm-5.1', provider: 'bailian' }],
|
|
17
18
|
'qwen-vl-plus': [{ model: 'qwen-vl-plus', provider: 'bailian' }],
|
|
18
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
|
+
}
|