Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openclaw.plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "model_router",
"version": "1.2.14",
"version": "1.2.15",
"name": "AIPing Model Router",
"description": "Routes 'aiping:claw' model requests between your local Ollama model and AIPing cloud (Kimi-K2.5) using fast rule-based scoring.",
"extensions": ["dist/index.js"],
Expand Down Expand Up @@ -37,7 +37,7 @@
"localDisableThinking": {
"type": "boolean",
"title": "Disable thinking on local model",
"description": "When true, adds think: false to local Ollama /v1/chat/completions when the client did not set think (Ollama ignores disableThinking; this turns off reasoning for Qwen3-class models).",
"description": "When true, adds think: false to local Ollama /api/chat when the client did not set think (native API; /v1/chat/completions ignores think on Ollama 0.18.x).",
"default": true
},
"cloudModel": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aiping.cn/model_router",
"version": "1.2.14",
"version": "1.2.15",
"description": "OpenClaw plugin: smart routing between local Ollama models and AIPing cloud (Kimi-K2.5). ~90% requests stay local.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
104 changes: 33 additions & 71 deletions src/__tests__/local-adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,37 @@ describe('LocalAdapter.listModels()', () => {
});

describe('LocalAdapter localDisableThinking', () => {
it('adds think: false to local chat body when enabled and client omits thinking options', async () => {
const ollamaChatDone = {
model: 'qwen2.5:4b',
message: { role: 'assistant', content: 'hi' },
done: true,
done_reason: 'stop',
};

it('POSTs Ollama native /api/chat (not OpenAI /v1/chat/completions)', async () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () =>
Promise.resolve({
id: '1',
object: 'chat.completion',
created: 0,
model: 'qwen2.5:4b',
choices: [
{
index: 0,
message: { role: 'assistant', content: 'hi' },
finish_reason: 'stop',
},
],
}),
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

const adapter = new LocalAdapter({ ...config, localDisableThinking: false });
await adapter.chat({
model: 'aiping:claw',
messages: [{ role: 'user', content: 'hello' }],
});

const [url] = fetchMock.mock.calls[0]!;
expect(String(url)).toContain('/api/chat');
expect(String(url)).not.toContain('/v1/chat/completions');
});

it('adds think: false to local /api/chat body when enabled and client omits thinking options', async () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

Expand All @@ -101,26 +114,14 @@ describe('LocalAdapter localDisableThinking', () => {
const parsed = JSON.parse((init as RequestInit).body as string);
expect(parsed.think).toBe(false);
expect(parsed).not.toHaveProperty('disableThinking');
expect(parsed.stream).toBe(false);
});

it('does not override client-provided think', async () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () =>
Promise.resolve({
id: '1',
object: 'chat.completion',
created: 0,
model: 'qwen2.5:4b',
choices: [
{
index: 0,
message: { role: 'assistant', content: 'hi' },
finish_reason: 'stop',
},
],
}),
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

Expand All @@ -140,20 +141,7 @@ describe('LocalAdapter localDisableThinking', () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () =>
Promise.resolve({
id: '1',
object: 'chat.completion',
created: 0,
model: 'qwen2.5:4b',
choices: [
{
index: 0,
message: { role: 'assistant', content: 'hi' },
finish_reason: 'stop',
},
],
}),
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

Expand All @@ -173,20 +161,7 @@ describe('LocalAdapter localDisableThinking', () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () =>
Promise.resolve({
id: '1',
object: 'chat.completion',
created: 0,
model: 'qwen2.5:4b',
choices: [
{
index: 0,
message: { role: 'assistant', content: 'hi' },
finish_reason: 'stop',
},
],
}),
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

Expand All @@ -206,20 +181,7 @@ describe('LocalAdapter localDisableThinking', () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: () =>
Promise.resolve({
id: '1',
object: 'chat.completion',
created: 0,
model: 'qwen2.5:4b',
choices: [
{
index: 0,
message: { role: 'assistant', content: 'hi' },
finish_reason: 'stop',
},
],
}),
json: () => Promise.resolve(ollamaChatDone),
});
vi.stubGlobal('fetch', fetchMock);

Expand Down
Loading
Loading