@jsonstudio/rcc 0.89.1189 → 0.89.1348
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 +17 -0
- package/configsamples/config.json +426 -0
- package/configsamples/config.reference.json +58 -0
- package/configsamples/provider/crs/config.v1.json +46 -0
- package/configsamples/provider/glm/config.v1.json +81 -0
- package/configsamples/provider/glm-anthropic/config.v1.json +45 -0
- package/configsamples/provider/iflow/config.v1.json +74 -0
- package/configsamples/provider/kimi/config.v1.json +41 -0
- package/configsamples/provider/lmstudio/config.v1.json +101 -0
- package/configsamples/provider/mimo/config.v1.json +35 -0
- package/configsamples/provider/modelscope/config.v1.json +96 -0
- package/configsamples/provider/qwen/config.v1.json +38 -0
- package/configsamples/provider/tab/config.v1.json +50 -0
- package/configsamples/provider/tabglm/config.v1.json +49 -0
- package/dist/build-info.js +2 -2
- package/dist/cli/commands/code.js +12 -6
- package/dist/cli/commands/code.js.map +1 -1
- package/dist/cli/commands/config.d.ts +2 -1
- package/dist/cli/commands/config.js +74 -103
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/examples.js +6 -6
- package/dist/cli/commands/examples.js.map +1 -1
- package/dist/cli/commands/init.d.ts +28 -0
- package/dist/cli/commands/init.js +91 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/port.js +10 -2
- package/dist/cli/commands/port.js.map +1 -1
- package/dist/cli/commands/restart.js +5 -2
- package/dist/cli/commands/restart.js.map +1 -1
- package/dist/cli/commands/start.js +25 -22
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/status.js +1 -0
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/stop.js +1 -0
- package/dist/cli/commands/stop.js.map +1 -1
- package/dist/cli/config/bundled-docs.d.ts +20 -0
- package/dist/cli/config/bundled-docs.js +91 -0
- package/dist/cli/config/bundled-docs.js.map +1 -0
- package/dist/cli/config/init-config.d.ts +36 -0
- package/dist/cli/config/init-config.js +180 -0
- package/dist/cli/config/init-config.js.map +1 -0
- package/dist/cli/config/init-provider-catalog.d.ts +8 -0
- package/dist/cli/config/init-provider-catalog.js +187 -0
- package/dist/cli/config/init-provider-catalog.js.map +1 -0
- package/dist/cli/register/init-command.d.ts +3 -0
- package/dist/cli/register/init-command.js +5 -0
- package/dist/cli/register/init-command.js.map +1 -0
- package/dist/cli.js +28 -3
- package/dist/cli.js.map +1 -1
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js +1 -1
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js.map +1 -1
- package/dist/config/risk-control-config.d.ts +94 -0
- package/dist/config/risk-control-config.js +196 -0
- package/dist/config/risk-control-config.js.map +1 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +13 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/docs/daemon-admin-ui.html +2113 -190
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/manager/modules/health/index.d.ts +1 -1
- package/dist/manager/modules/quota/antigravity-quota-manager.d.ts +70 -0
- package/dist/manager/modules/quota/antigravity-quota-manager.js +442 -0
- package/dist/manager/modules/quota/antigravity-quota-manager.js.map +1 -0
- package/dist/manager/modules/quota/index.d.ts +3 -127
- package/dist/manager/modules/quota/index.js +2 -1093
- package/dist/manager/modules/quota/index.js.map +1 -1
- package/dist/manager/modules/quota/provider-key-normalization.d.ts +3 -0
- package/dist/manager/modules/quota/provider-key-normalization.js +155 -0
- package/dist/manager/modules/quota/provider-key-normalization.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.cooldown.d.ts +9 -0
- package/dist/manager/modules/quota/provider-quota-daemon.cooldown.js +115 -0
- package/dist/manager/modules/quota/provider-quota-daemon.cooldown.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.d.ts +77 -0
- package/dist/manager/modules/quota/provider-quota-daemon.events.d.ts +12 -0
- package/dist/manager/modules/quota/provider-quota-daemon.events.js +237 -0
- package/dist/manager/modules/quota/provider-quota-daemon.events.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.js +404 -0
- package/dist/manager/modules/quota/provider-quota-daemon.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.d.ts +11 -0
- package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.js +189 -0
- package/dist/manager/modules/quota/provider-quota-daemon.model-backoff.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.snapshot.d.ts +8 -0
- package/dist/manager/modules/quota/provider-quota-daemon.snapshot.js +96 -0
- package/dist/manager/modules/quota/provider-quota-daemon.snapshot.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.view.d.ts +19 -0
- package/dist/manager/modules/quota/provider-quota-daemon.view.js +37 -0
- package/dist/manager/modules/quota/provider-quota-daemon.view.js.map +1 -0
- package/dist/manager/modules/routing/index.d.ts +1 -0
- package/dist/manager/modules/routing/index.js +11 -25
- package/dist/manager/modules/routing/index.js.map +1 -1
- package/dist/manager/quota/provider-quota-center.d.ts +2 -0
- package/dist/manager/quota/provider-quota-center.js +80 -82
- package/dist/manager/quota/provider-quota-center.js.map +1 -1
- package/dist/modules/llmswitch/bridge.d.ts +16 -18
- package/dist/modules/llmswitch/bridge.js +314 -71
- package/dist/modules/llmswitch/bridge.js.map +1 -1
- package/dist/modules/llmswitch/core-loader.d.ts +4 -2
- package/dist/modules/llmswitch/core-loader.js +32 -20
- package/dist/modules/llmswitch/core-loader.js.map +1 -1
- package/dist/modules/pipeline/utils/colored-logger.js +3 -2
- package/dist/modules/pipeline/utils/colored-logger.js.map +1 -1
- package/dist/modules/pipeline/utils/debug-logger.js +1 -1
- package/dist/modules/pipeline/utils/debug-logger.js.map +1 -1
- package/dist/providers/auth/iflow-cookie-auth.js +0 -2
- package/dist/providers/auth/iflow-cookie-auth.js.map +1 -1
- package/dist/providers/auth/oauth-lifecycle.js +2 -23
- package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
- package/dist/providers/core/config/camoufox-launcher.js +35 -4
- package/dist/providers/core/config/camoufox-launcher.js.map +1 -1
- package/dist/providers/core/runtime/antigravity-quota-client.js +6 -3
- package/dist/providers/core/runtime/antigravity-quota-client.js.map +1 -1
- package/dist/providers/core/runtime/base-provider.d.ts +2 -2
- package/dist/providers/core/runtime/base-provider.js +74 -69
- package/dist/providers/core/runtime/base-provider.js.map +1 -1
- package/dist/providers/core/runtime/gemini-cli-http-provider.js +6 -4
- package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
- package/dist/providers/core/runtime/http-request-executor.js +2 -2
- package/dist/providers/core/runtime/http-request-executor.js.map +1 -1
- package/dist/providers/core/runtime/http-transport-provider.d.ts +14 -0
- package/dist/providers/core/runtime/http-transport-provider.js +111 -5
- package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
- package/dist/providers/core/runtime/provider-error-classifier.js +10 -0
- package/dist/providers/core/runtime/provider-error-classifier.js.map +1 -1
- package/dist/providers/core/runtime/provider-factory.js +7 -5
- package/dist/providers/core/runtime/provider-factory.js.map +1 -1
- package/dist/providers/core/runtime/provider-runtime-metadata.d.ts +6 -0
- package/dist/providers/core/runtime/provider-runtime-metadata.js.map +1 -1
- package/dist/providers/core/runtime/responses-provider.d.ts +1 -7
- package/dist/providers/core/runtime/responses-provider.js +12 -93
- package/dist/providers/core/runtime/responses-provider.js.map +1 -1
- package/dist/providers/core/strategies/oauth-auth-code-flow.js +12 -8
- package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
- package/dist/providers/core/utils/http-client.js +16 -3
- package/dist/providers/core/utils/http-client.js.map +1 -1
- package/dist/providers/core/utils/provider-error-logger.d.ts +1 -1
- package/dist/providers/core/utils/provider-error-reporter.d.ts +3 -1
- package/dist/providers/core/utils/provider-error-reporter.js +3 -0
- package/dist/providers/core/utils/provider-error-reporter.js.map +1 -1
- package/dist/providers/core/utils/snapshot-writer.js +1 -4
- package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
- package/dist/providers/mock/mock-provider-runtime.js +57 -27
- package/dist/providers/mock/mock-provider-runtime.js.map +1 -1
- package/dist/scripts/camoufox/launch-auth.mjs +193 -58
- package/dist/server/handlers/handler-utils.js +3 -2
- package/dist/server/handlers/handler-utils.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/auth-handler.d.ts +2 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-handler.js +103 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-handler.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-session.d.ts +5 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-session.js +77 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-session.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-store.d.ts +18 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-store.js +89 -0
- package/dist/server/runtime/http-server/daemon-admin/auth-store.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js +1 -2
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/providers-handler.js +226 -24
- package/dist/server/runtime/http-server/daemon-admin/providers-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/quota-handler.js +47 -8
- package/dist/server/runtime/http-server/daemon-admin/quota-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/restart-handler.js +1 -1
- package/dist/server/runtime/http-server/daemon-admin/restart-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/stats-handler.js +1 -1
- package/dist/server/runtime/http-server/daemon-admin/stats-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/status-handler.js +68 -4
- package/dist/server/runtime/http-server/daemon-admin/status-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin-routes.d.ts +3 -4
- package/dist/server/runtime/http-server/daemon-admin-routes.js +9 -14
- package/dist/server/runtime/http-server/daemon-admin-routes.js.map +1 -1
- package/dist/server/runtime/http-server/executor-metadata.js +1 -1
- package/dist/server/runtime/http-server/executor-metadata.js.map +1 -1
- package/dist/server/runtime/http-server/executor-response.js +0 -16
- package/dist/server/runtime/http-server/executor-response.js.map +1 -1
- package/dist/server/runtime/http-server/hub-shadow-compare.d.ts +18 -0
- package/dist/server/runtime/http-server/hub-shadow-compare.js +256 -0
- package/dist/server/runtime/http-server/hub-shadow-compare.js.map +1 -0
- package/dist/server/runtime/http-server/index.d.ts +7 -2
- package/dist/server/runtime/http-server/index.js +287 -49
- package/dist/server/runtime/http-server/index.js.map +1 -1
- package/dist/server/runtime/http-server/middleware.js +19 -1
- package/dist/server/runtime/http-server/middleware.js.map +1 -1
- package/dist/server/runtime/http-server/request-executor.js +10 -19
- package/dist/server/runtime/http-server/request-executor.js.map +1 -1
- package/dist/server/runtime/http-server/routes.js +8 -2
- package/dist/server/runtime/http-server/routes.js.map +1 -1
- package/dist/server/runtime/http-server/session-dir.d.ts +2 -0
- package/dist/server/runtime/http-server/session-dir.js +59 -0
- package/dist/server/runtime/http-server/session-dir.js.map +1 -0
- package/dist/server/runtime/http-server/types.d.ts +0 -4
- package/dist/server/utils/utf8-chunk-buffer.js +6 -3
- package/dist/server/utils/utf8-chunk-buffer.js.map +1 -1
- package/dist/server/utils/warmup-storm-tracker.js +1 -1
- package/dist/server/utils/warmup-storm-tracker.js.map +1 -1
- package/dist/server-factory.d.ts +6 -28
- package/dist/server-factory.js +8 -93
- package/dist/server-factory.js.map +1 -1
- package/dist/token-daemon/index.js +2 -2
- package/dist/token-daemon/index.js.map +1 -1
- package/dist/token-daemon/provider-registry.js +0 -1
- package/dist/token-daemon/provider-registry.js.map +1 -1
- package/dist/token-daemon/server-utils.js +8 -9
- package/dist/token-daemon/server-utils.js.map +1 -1
- package/dist/token-daemon/token-utils.js +1 -1
- package/dist/token-daemon/token-utils.js.map +1 -1
- package/dist/tools/semantic-replay.js +2 -2
- package/dist/tools/semantic-replay.js.map +1 -1
- package/dist/tools/stats-request-events.d.ts +1 -1
- package/dist/tools/stats-usage.js +6 -3
- package/dist/tools/stats-usage.js.map +1 -1
- package/dist/utils/errorsamples.d.ts +5 -0
- package/dist/utils/errorsamples.js +27 -0
- package/dist/utils/errorsamples.js.map +1 -0
- package/dist/utils/llms-engine-shadow.d.ts +19 -0
- package/dist/utils/llms-engine-shadow.js +209 -0
- package/dist/utils/llms-engine-shadow.js.map +1 -0
- package/dist/utils/runtime-versions.d.ts +1 -0
- package/dist/utils/runtime-versions.js +39 -0
- package/dist/utils/runtime-versions.js.map +1 -0
- package/docs/ARCHITECTURE.md +402 -0
- package/docs/CODEX_AND_CLAUDE_CODE.md +69 -0
- package/docs/CONFIG_ARCHITECTURE.md +517 -0
- package/docs/ERROR_HANDLING_AUDIT.md +0 -0
- package/docs/GCLI2API_PARITY_GAPS.md +98 -0
- package/docs/INSTALLATION_AND_QUICKSTART.md +74 -0
- package/docs/INSTRUCTION_MARKUP.md +89 -0
- package/docs/MODULE_ENHANCEMENT_SYSTEM.md +666 -0
- package/docs/PORTS.md +36 -0
- package/docs/PROVIDERS_BUILTIN.md +111 -0
- package/docs/PROVIDER_TYPES.md +55 -0
- package/docs/SERVERTOOL_CLOCK_DESIGN.md +233 -0
- package/docs/USAGE_HANDLING_ANALYSIS.md +335 -0
- package/docs/USER_CONFIG_PARSER_CHANGES.md +175 -0
- package/docs/V3_INBOUND_OUTBOUND_DESIGN.md +86 -0
- package/docs/VIRTUAL_ROUTER_PRIORITY_AND_HEALTH.md +125 -0
- package/docs/anthropic-request-golden-samples.md +50 -0
- package/docs/ccr-alignment-enhancetool.md +105 -0
- package/docs/chat-glm-500-analysis.md +79 -0
- package/docs/chat-request-golden-samples.md +42 -0
- package/docs/chat-semantic-expansion-plan.md +82 -0
- package/docs/cli-command-inventory.md +76 -0
- package/docs/codex-samples-replay.md +50 -0
- package/docs/daemon-admin-api-design.md +350 -0
- package/docs/daemon-admin-module-structure.md +169 -0
- package/docs/daemon-admin-ui.html +3394 -0
- package/docs/debug-system-design.md +734 -0
- package/docs/debugging/gemini-sse-root-cause.md +52 -0
- package/docs/debugging/sse_encoding_failure_analysis.md +53 -0
- package/docs/dry-run/README.md +721 -0
- package/docs/error-handling-v2.md +92 -0
- package/docs/exec-command-guard-policy.example.v1.json +42 -0
- package/docs/fixes/gemini-protocol-mapping.md +57 -0
- package/docs/fixes/oauth-portal-timing-fix.md +202 -0
- package/docs/fixes/web-search-hop3-fix.md +265 -0
- package/docs/glm-api-reference.md +390 -0
- package/docs/glm-chat-completions.md +1779 -0
- package/docs/glm-history-inline-images.md +44 -0
- package/docs/golden-ci-library.md +66 -0
- package/docs/lmstudio-dry-run-summary.md +203 -0
- package/docs/lmstudio-tool-calling.md +214 -0
- package/docs/mapping-tables/anthropic-to-openai.json +290 -0
- package/docs/mapping-tables/iflow-to-openai.json +215 -0
- package/docs/mapping-tables/openai-passthrough.json +190 -0
- package/docs/mapping-tables/openai-to-iflow.json +227 -0
- package/docs/monitoring/Design.md +61 -0
- package/docs/multi-token-auth-guide.md +66 -0
- package/docs/oauth-authentication-guide.md +168 -0
- package/docs/oauth-iflow-implementation.md +153 -0
- package/docs/pipeline-routing-report.md +209 -0
- package/docs/plans/manager-daemon/PLAN.md +86 -0
- package/docs/plans/provider-config-v2-plan.md +176 -0
- package/docs/plans/provider-runtime-manager-plan.md +209 -0
- package/docs/plans/transparent-429-failover.md +89 -0
- package/docs/plans/unified-hub-framework-v1.md +245 -0
- package/docs/provider-config-v2-ui-design.md +181 -0
- package/docs/provider-quota-design.md +129 -0
- package/docs/providers/gemini-provider.md +62 -0
- package/docs/providers/lmstudio-v2-migration-report.md +102 -0
- package/docs/providers/provider-composite-design.md +142 -0
- package/docs/providers/provider-composite-testing.md +98 -0
- package/docs/providers/provider-type-only-migration.md +111 -0
- package/docs/rccx-wasm-migration.md +74 -0
- package/docs/refactoring/architecture-comparison-diagram.md +140 -0
- package/docs/refactoring/compatibility-v2-architecture-design.md +738 -0
- package/docs/refactoring/workflow-compatibility-refactoring-design.md +361 -0
- package/docs/reports/routing-classification-report.json +24 -0
- package/docs/reports/routing-classification-report.md +18 -0
- package/docs/reports/thinking-keywords-report.json +19 -0
- package/docs/responses/README.md +156 -0
- package/docs/responses-generic-provider.md +86 -0
- package/docs/responses-passthrough-provider-design.md +202 -0
- package/docs/routing-awrr-health-weighted-round-robin.md +179 -0
- package/docs/routing-instructions.md +393 -0
- package/docs/stop-message-auto.md +225 -0
- package/docs/streaming-flow.html +30 -0
- package/docs/streaming-flow.md +182 -0
- package/docs/token-daemon-preview.html +490 -0
- package/docs/token-refresh-daemon-plan.md +269 -0
- package/docs/transformation-tables/Gemini-FinishReason/345/256/214/346/225/264/350/275/254/346/215/242/350/241/250.json +233 -0
- package/docs/transformation-tables/README.md +225 -0
- package/docs/transformation-tables/claude-code-router-anthropic-to-gemini.json +283 -0
- package/docs/transformation-tables/claude-code-router-anthropic-to-openai.json +208 -0
- package/docs/transformation-tables/claude-code-router-openai-to-anthropic.json +261 -0
- package/docs/transformation-tables/claude-code-router-openai-to-gemini.json +208 -0
- package/docs/transformation-tables/claude-code-router-openai-to-lmstudio.json +182 -0
- package/docs/transformation-tables/claude-code-router-openai-to-ollama.json +250 -0
- package/docs/transformation-tables/claude-code-router-openai-to-textgenwebui.json +295 -0
- package/docs/transformation-tables/claude-code-router-provider-conversions.json +193 -0
- package/docs/transformation-tables//345/256/214/346/225/264/347/232/204/345/267/245/345/205/267/346/211/247/350/241/214/346/265/201/347/250/213/350/275/254/346/215/242/350/241/250.json +299 -0
- package/docs/transformation-tables//345/257/271/350/257/235/345/216/206/345/217/262/347/273/264/346/212/244/345/210/206/346/236/220.md +134 -0
- package/docs/transformation-tables//345/267/245/345/205/267/350/260/203/347/224/250/346/250/241/345/274/217/345/210/206/346/236/220.md +158 -0
- package/docs/transformation-tables//347/212/266/346/200/201/347/256/241/347/220/206/351/234/200/346/261/202/345/210/206/346/236/220.md +175 -0
- package/docs/transformation-tables//351/235/231/346/200/201/350/241/250vs/345/212/250/346/200/201/345/210/206/346/236/220.md +189 -0
- package/docs/transformation-tables//351/235/231/346/200/201/350/241/250/345/207/206/347/241/256/346/200/247/350/257/204/344/274/260.md +179 -0
- package/docs/transformation-tables//351/235/236/346/265/201/345/274/217/345/234/272/346/231/257/345/210/206/346/236/220.md +189 -0
- package/docs/v2-architecture/IMPLEMENTATION-ROADMAP.md +367 -0
- package/docs/v2-architecture/OPTIMIZED-DESIGN.md +827 -0
- package/docs/v2-architecture/PRERUN-CONNECTION-DESIGN.md +716 -0
- package/docs/v2-architecture/README.md +551 -0
- package/docs/verification/modelscope-verify.md +59 -0
- package/docs/web-search-service-design.md +322 -0
- package/package.json +12 -7
- package/scripts/camoufox/launch-auth.mjs +193 -58
- package/scripts/monitor-diff.mjs +126 -0
- package/scripts/pack-mode.mjs +19 -1
- package/scripts/pack-rcc.mjs +63 -0
- package/scripts/unified-hub-shadow-compare.mjs +33 -13
- package/scripts/verify-e2e-toolcall.mjs +115 -26
- package/dist/modules/llmswitch/pipeline-registry.d.ts +0 -57
- package/dist/modules/llmswitch/pipeline-registry.js +0 -229
- package/dist/modules/llmswitch/pipeline-registry.js.map +0 -1
- package/dist/server/RouteCodexServer.d.ts +0 -13
- package/dist/server/RouteCodexServer.js +0 -25
- package/dist/server/RouteCodexServer.js.map +0 -1
- package/dist/v2/conversion/hub/snapshot-recorder.d.ts +0 -12
- package/dist/v2/conversion/hub/snapshot-recorder.js +0 -22
- package/dist/v2/conversion/hub/snapshot-recorder.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# GLM 4.7 历史消息中的 inline 图片兼容说明
|
|
2
|
+
|
|
3
|
+
## 背景
|
|
4
|
+
|
|
5
|
+
在 `glm-4.7` 上游接口下,历史消息(history)中携带 `data:image/...` 形式的 inline base64 图片内容,在上下文较长时会触发 HTTP 400 / 错误码 `1210`(“API 调用参数有误,请检查文档。”),即使当前轮请求本身是合法的。
|
|
6
|
+
|
|
7
|
+
本地调试(基于 snapshot 回放和 payload 二分)确认:
|
|
8
|
+
|
|
9
|
+
- 只保留首条 `system` + 当前轮最后一条 `user` 时可以正常返回 200;
|
|
10
|
+
- 从最早历史开始累积,当累积到某条 **带有 `type=image|image_url|input_image` 且 URL 以 `data:image` 开头** 的 `user` 历史消息时,首次出现 400 / `1210`。
|
|
11
|
+
|
|
12
|
+
## RouteCodex 侧兼容策略
|
|
13
|
+
|
|
14
|
+
为避免这类错误,RouteCodex 在 `chat:glm` 兼容配置中增加了专门的裁剪动作:
|
|
15
|
+
|
|
16
|
+
- Action:`glm_history_image_trim`
|
|
17
|
+
- 实现位置:`sharedmodule/llmswitch-core/src/conversion/compat/actions/glm-history-image-trim.ts`
|
|
18
|
+
|
|
19
|
+
兼容策略规则:
|
|
20
|
+
|
|
21
|
+
- 仅在以下条件同时满足时生效:
|
|
22
|
+
- 请求 `protocol` 为 `openai-chat`;
|
|
23
|
+
- `compatibilityProfile` 为 `chat:glm`;
|
|
24
|
+
- `model` 以 `glm-4.7` 开头。
|
|
25
|
+
- 遍历 `messages`:
|
|
26
|
+
- 找到最后一条 `role: "user"` 的消息,视为当前轮请求;
|
|
27
|
+
- 对这条之前的所有 `user` 历史消息:
|
|
28
|
+
- 如果 `content` 中存在 `type ∈ { "image", "image_url", "input_image" }` 且 URL/数据以 `data:image` 开头的片段:
|
|
29
|
+
- 从该条 `content` 中丢弃这些 inline image 片段;
|
|
30
|
+
- 如果丢弃后该条消息不再包含任何内容(即之前是“纯图片历史”):
|
|
31
|
+
- 直接移除整条历史消息。
|
|
32
|
+
- 当前轮最后一条 `user` 消息(通常是用户最新问题)不会被该规则修改。
|
|
33
|
+
|
|
34
|
+
## 对调用方的影响
|
|
35
|
+
|
|
36
|
+
- 对于通过 RouteCodex 调用 `glm-4.7` 的业务方:
|
|
37
|
+
- 历史对话中包含 inline base64 图片时,RouteCodex 会在发送到上游之前自动裁剪掉这些历史图片内容;
|
|
38
|
+
- 当前轮用户输入中携带的图片内容不会被该规则移除。
|
|
39
|
+
- 这样可以:
|
|
40
|
+
- 避免由于历史中的 `data:image/...` 导致的 400 / `1210` 错误;
|
|
41
|
+
- 保持当前轮请求的图片能力正常可用。
|
|
42
|
+
|
|
43
|
+
如果需要完整重现原始 payload(包括被裁剪掉的 inline 图片),可以使用 snapshot 调试工具直接回放 provider 前的快照,而不是依赖线上请求路径。
|
|
44
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
## CI Golden 样本库
|
|
2
|
+
|
|
3
|
+
`samples/ci-goldens/` 内置了一套最小化的请求样本,覆盖目前已经打通的三条聊天入口:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
samples/ci-goldens/
|
|
7
|
+
openai-chat/
|
|
8
|
+
glm/
|
|
9
|
+
meta.json
|
|
10
|
+
request.sample.json
|
|
11
|
+
openai-responses/
|
|
12
|
+
fai/
|
|
13
|
+
meta.json
|
|
14
|
+
request.sample.json
|
|
15
|
+
anthropic-messages/
|
|
16
|
+
glm-anthropic/
|
|
17
|
+
meta.json
|
|
18
|
+
request.sample.json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
每个目录直接包含阶段快照里抽取的 `request.sample.json`(等价于
|
|
22
|
+
`*_req_outbound_stage2_format_build.json.body`),以及 `meta.json`,注明来源
|
|
23
|
+
stage、providerId 与捕获时间。CI 或本地始终可以依赖这些样本来跑最基本的
|
|
24
|
+
roundtrip/工具校验,而不需要访问真实 provider。
|
|
25
|
+
|
|
26
|
+
### `npm run test:golden`
|
|
27
|
+
|
|
28
|
+
命令会按照下面的顺序执行:
|
|
29
|
+
|
|
30
|
+
1. `node scripts/tools/capture-provider-goldens.mjs --custom-only --update-golden`
|
|
31
|
+
- 优先读取 `~/.routecodex/golden_samples/new/<entry>/<provider>/`;
|
|
32
|
+
- 若用户目录缺失,则自动回退到 `samples/ci-goldens/...`;
|
|
33
|
+
- 最后才会使用 `samples/chat-blackbox/**/request-basic.json` 做最小回放。
|
|
34
|
+
- 结果写入 `~/.routecodex/golden_samples/provider_golden_samples/**`,供 Provider
|
|
35
|
+
单测与 mock 回放使用。
|
|
36
|
+
2. `node scripts/mock-provider/run-regressions.mjs`
|
|
37
|
+
- 使用仓库内 `samples/mock-provider/_registry` 的样本,通过 mock provider
|
|
38
|
+
执行一轮端到端回放;
|
|
39
|
+
- 默认启用 `ROUTECODEX_MOCK_ENTRY_FILTER=all`,确保 chat/responses/anthropic
|
|
40
|
+
都被验证。
|
|
41
|
+
|
|
42
|
+
如果检测到 `~/.routecodex/codex-samples`,脚本会提示可以运行
|
|
43
|
+
`node scripts/mock-provider/capture-from-configs.mjs` 将真实请求转成 mock 回放样本。
|
|
44
|
+
该命令会根据本地 `~/.routecodex/provider/**/config*.json` 与
|
|
45
|
+
`~/.routecodex/golden_samples/new/**` 生成新的 `samples/mock-provider/...`
|
|
46
|
+
目录,并刷新 `_registry/index.json`。随后再次执行 `npm run test:golden` 即可把
|
|
47
|
+
“真实” provider 行为也纳入回归。
|
|
48
|
+
|
|
49
|
+
### 如何补充新的 provider 样本
|
|
50
|
+
|
|
51
|
+
1. 在本地 `routecodex` 服务上真实跑通一次请求,确认
|
|
52
|
+
`~/.routecodex/golden_samples/new/<entry>/<provider>/request.sample.json` 已生成。
|
|
53
|
+
2. 运行 `npm run sync:ci-goldens`(或直接执行
|
|
54
|
+
`node scripts/tools/sync-ci-goldens.mjs --entry <entry> --provider <id>`)把刚产生的
|
|
55
|
+
样本复制到 `samples/ci-goldens/<entry>/<provider>/`,脚本会自动生成/刷新 `meta.json`
|
|
56
|
+
并用 `source: "ci-goldens"` 标识。
|
|
57
|
+
3. 运行 `npm run test:golden`,确认新的样本能够被
|
|
58
|
+
`capture-provider-goldens.mjs` 消费并写入
|
|
59
|
+
`~/.routecodex/golden_samples/provider_golden_samples/<provider>/<entry>/`。
|
|
60
|
+
4. 如需把同一份请求加入 mock provider 回放,可执行
|
|
61
|
+
`node scripts/mock-provider/capture-from-configs.mjs --filter <providerId>`,
|
|
62
|
+
该命令会复用刚才的 `request.sample` 生成 `samples/mock-provider/...` 记录。
|
|
63
|
+
|
|
64
|
+
> 注意:CI goldens 只存储对齐 chat 入口输入字段的最终 JSON,不包含任何密钥或本地路径。
|
|
65
|
+
> 如需测试特定机密字段,请在本地运行 `capture-provider-goldens` 并利用私有
|
|
66
|
+
> `~/.routecodex/golden_samples/new/**`,不要把敏感样本提交到仓库。
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# LM Studio Dry-Run Implementation Summary
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document summarizes the comprehensive LM Studio dry-run implementation that focuses on capturing and analyzing response transformations in the RouteCodex pipeline system.
|
|
6
|
+
|
|
7
|
+
## 🚀 Key Features Implemented
|
|
8
|
+
|
|
9
|
+
### 1. Response-Focused Dry-Run Analysis
|
|
10
|
+
- **Response Transformation Tracking**: Detailed analysis of how responses are transformed through each pipeline stage
|
|
11
|
+
- **Performance Metrics**: Execution time, memory usage, and efficiency calculations
|
|
12
|
+
- **Error Detection**: Comprehensive error tracking and reporting during response processing
|
|
13
|
+
|
|
14
|
+
### 2. Comprehensive Analysis Scripts
|
|
15
|
+
|
|
16
|
+
#### `tests/lmstudio-response-analysis-dry-run.mjs`
|
|
17
|
+
- **Purpose**: Focused analysis on response transformations
|
|
18
|
+
- **Features**:
|
|
19
|
+
- Real response generation and capture
|
|
20
|
+
- Detailed transformation step analysis
|
|
21
|
+
- Performance metrics and efficiency calculations
|
|
22
|
+
- Structure analysis of input/output data
|
|
23
|
+
- Tool call extraction and analysis
|
|
24
|
+
|
|
25
|
+
#### `tests/lmstudio-comprehensive-dry-run.mjs`
|
|
26
|
+
- **Purpose**: Complete pipeline dry-run with enhanced response analysis
|
|
27
|
+
- **Features**:
|
|
28
|
+
- Multi-stage execution (request + response)
|
|
29
|
+
- Enhanced response wrappers with detailed logging
|
|
30
|
+
- Comprehensive analysis reports
|
|
31
|
+
- Performance comparison across stages
|
|
32
|
+
|
|
33
|
+
### 3. Configuration Support
|
|
34
|
+
|
|
35
|
+
#### `config/lmstudio-dry-run-config.json`
|
|
36
|
+
- **Purpose**: Centralized configuration for LM Studio dry-run operations
|
|
37
|
+
- **Features**:
|
|
38
|
+
- Request pipeline configuration with detailed node settings
|
|
39
|
+
- Response pipeline configuration with transformation analysis
|
|
40
|
+
- Performance thresholds and analysis levels
|
|
41
|
+
- Driver feedback configuration
|
|
42
|
+
|
|
43
|
+
## 📊 Analysis Capabilities
|
|
44
|
+
|
|
45
|
+
### Response Analysis Features
|
|
46
|
+
1. **Structure Analysis**: Automatic analysis of response object structure
|
|
47
|
+
2. **Tool Call Extraction**: Detection and analysis of tool calls in responses
|
|
48
|
+
3. **Size Tracking**: Input/output size changes during transformation
|
|
49
|
+
4. **Performance Metrics**: Execution time, throughput, and efficiency calculations
|
|
50
|
+
5. **Error Tracking**: Comprehensive error detection and reporting
|
|
51
|
+
|
|
52
|
+
### Transformation Chain Analysis
|
|
53
|
+
1. **Step-by-Step Tracking**: Each transformation step is logged and analyzed
|
|
54
|
+
2. **Data Flow Visualization**: Clear visualization of how data moves through the pipeline
|
|
55
|
+
3. **Efficiency Metrics**: Transformation efficiency calculations at each stage
|
|
56
|
+
4. **Comparative Analysis**: Before/after comparison of response data
|
|
57
|
+
|
|
58
|
+
## 🛠️ Usage Examples
|
|
59
|
+
|
|
60
|
+
### Basic Response Analysis
|
|
61
|
+
```bash
|
|
62
|
+
# Run response analysis with existing response file
|
|
63
|
+
node tests/lmstudio-response-analysis-dry-run.mjs
|
|
64
|
+
|
|
65
|
+
# Output files:
|
|
66
|
+
# - tests/output/lmstudio-response-analysis-result.json
|
|
67
|
+
# - tests/output/lmstudio-response-analysis-report.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### CLI Tool Usage
|
|
71
|
+
```bash
|
|
72
|
+
# Run response analysis via CLI
|
|
73
|
+
node scripts/dry-run-cli.mjs run-response \
|
|
74
|
+
--response tests/output/lmstudio-real-response.json \
|
|
75
|
+
--pipeline-id lmstudio-response-test
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Configuration-Based Analysis
|
|
79
|
+
```bash
|
|
80
|
+
# Use dedicated LM Studio dry-run configuration
|
|
81
|
+
# Configuration: config/lmstudio-dry-run-config.json
|
|
82
|
+
# Features: Request + response pipeline configuration
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 📈 Output Reports
|
|
86
|
+
|
|
87
|
+
### 1. Response Analysis Report
|
|
88
|
+
- **Location**: `tests/output/lmstudio-response-analysis-report.json`
|
|
89
|
+
- **Contents**:
|
|
90
|
+
- Execution summary with timestamps
|
|
91
|
+
- Original response analysis
|
|
92
|
+
- Compatibility transformation analysis
|
|
93
|
+
- LLM Switch transformation analysis
|
|
94
|
+
- Performance insights and metrics
|
|
95
|
+
|
|
96
|
+
### 2. Detailed Result Report
|
|
97
|
+
- **Location**: `tests/output/lmstudio-response-analysis-result.json`
|
|
98
|
+
- **Contents**:
|
|
99
|
+
- Complete execution pipeline details
|
|
100
|
+
- Node-by-node analysis results
|
|
101
|
+
- Performance metrics and timing
|
|
102
|
+
- Breakpoint status and recommendations
|
|
103
|
+
|
|
104
|
+
## 🔧 Technical Implementation
|
|
105
|
+
|
|
106
|
+
### Response Wrapper System
|
|
107
|
+
```javascript
|
|
108
|
+
// Enhanced response wrapper with analysis capabilities
|
|
109
|
+
function createResponseWrapper(id, type, underlyingModule) {
|
|
110
|
+
return {
|
|
111
|
+
// Detailed analysis tracking
|
|
112
|
+
executionStats: { startTime: 0, endTime: 0, steps: [] },
|
|
113
|
+
|
|
114
|
+
// Structure analysis
|
|
115
|
+
analyzeStructure(obj) {
|
|
116
|
+
// Automatic structure detection and analysis
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
// Performance calculation
|
|
120
|
+
calculateEfficiency(input, output) {
|
|
121
|
+
// Transformation efficiency metrics
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Analysis Data Structure
|
|
128
|
+
```javascript
|
|
129
|
+
const analysisData = {
|
|
130
|
+
transformationSteps: [],
|
|
131
|
+
inputAnalysis: { size, structure, toolCalls, choices },
|
|
132
|
+
outputAnalysis: { size, structure, toolCalls, choices },
|
|
133
|
+
performanceMetrics: { totalExecutionTime, throughput, transformationEfficiency },
|
|
134
|
+
errors: []
|
|
135
|
+
};
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 🎯 Key Insights Generated
|
|
139
|
+
|
|
140
|
+
### Performance Metrics
|
|
141
|
+
- **Total Transformation Time**: Combined execution time across all stages
|
|
142
|
+
- **Efficiency Ratios**: Input/output size efficiency calculations
|
|
143
|
+
- **Throughput**: Data processing speed metrics
|
|
144
|
+
- **Error Count**: Transformation and processing errors
|
|
145
|
+
|
|
146
|
+
### Data Flow Analysis
|
|
147
|
+
- **Size Changes**: Byte-level changes between input/output
|
|
148
|
+
- **Structure Transformations**: Object structure changes during processing
|
|
149
|
+
- **Tool Call Preservation**: How tool calls are handled through transformations
|
|
150
|
+
- **Content Integrity**: Data consistency analysis
|
|
151
|
+
|
|
152
|
+
## 📋 Test Results
|
|
153
|
+
|
|
154
|
+
### Successful Execution
|
|
155
|
+
- ✅ Response analysis dry-run completed successfully
|
|
156
|
+
- ✅ Sample response data processed and analyzed
|
|
157
|
+
- ✅ Comprehensive reports generated
|
|
158
|
+
- ✅ CLI tool functionality verified
|
|
159
|
+
- ✅ Configuration system integration tested
|
|
160
|
+
|
|
161
|
+
### Generated Artifacts
|
|
162
|
+
1. **Real Response Sample**: `tests/output/lmstudio-real-response.json`
|
|
163
|
+
2. **Analysis Result**: `tests/output/lmstudio-response-analysis-result.json`
|
|
164
|
+
3. **Analysis Report**: `tests/output/lmstudio-response-analysis-report.json`
|
|
165
|
+
4. **Configuration**: `config/lmstudio-dry-run-config.json`
|
|
166
|
+
|
|
167
|
+
## 🔮 Future Enhancements
|
|
168
|
+
|
|
169
|
+
### Planned Features
|
|
170
|
+
1. **HTML Report Generation**: Visual timeline and node tree visualization
|
|
171
|
+
2. **Real-time Analysis**: Live monitoring of response transformations
|
|
172
|
+
3. **Historical Comparison**: Compare transformation performance over time
|
|
173
|
+
4. **Advanced Metrics**: Memory usage, CPU utilization, and network impact
|
|
174
|
+
|
|
175
|
+
### Integration Opportunities
|
|
176
|
+
1. **Web Interface**: Web-based dry-run analysis dashboard
|
|
177
|
+
2. **API Endpoints**: RESTful API for programmatic analysis
|
|
178
|
+
3. **Plugin System**: Custom analysis modules and extensions
|
|
179
|
+
4. **Export Formats**: Multiple export formats (CSV, XML, HTML)
|
|
180
|
+
|
|
181
|
+
## 🏆 Conclusion
|
|
182
|
+
|
|
183
|
+
The LM Studio dry-run implementation provides a comprehensive solution for analyzing response transformations in the RouteCodex pipeline system. Key achievements:
|
|
184
|
+
|
|
185
|
+
1. **Complete Response Analysis**: End-to-end analysis of response processing
|
|
186
|
+
2. **Performance Insights**: Detailed performance metrics and efficiency calculations
|
|
187
|
+
3. **Error Detection**: Comprehensive error tracking and reporting
|
|
188
|
+
4. **Extensible Architecture**: Modular design for future enhancements
|
|
189
|
+
5. **User-Friendly Tools**: CLI and script-based interfaces for easy usage
|
|
190
|
+
|
|
191
|
+
This implementation demonstrates the power and flexibility of the RouteCodex dry-run system, providing deep insights into how AI model responses are processed and transformed through the pipeline architecture.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
**Files Created/Modified:**
|
|
196
|
+
- `tests/lmstudio-response-analysis-dry-run.mjs` - Response-focused analysis script
|
|
197
|
+
- `tests/lmstudio-comprehensive-dry-run.mjs` - Complete pipeline analysis script
|
|
198
|
+
- `config/lmstudio-dry-run-config.json` - Centralized configuration
|
|
199
|
+
- `tests/output/sample-real-response.json` - Sample response data
|
|
200
|
+
- `docs/lmstudio-dry-run-summary.md` - This documentation
|
|
201
|
+
|
|
202
|
+
**Status**: ✅ Complete and tested
|
|
203
|
+
**Version**: v2.1 - Response Analysis Enhancement
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# LM Studio Tool Calling API Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
LM Studio provides comprehensive tool calling functionality that enables Large Language Models (LLMs) to interact with external functions and APIs. All models in LM Studio support at least some degree of tool use, with two levels of support: **Native** and **Default**.
|
|
6
|
+
|
|
7
|
+
## Tool Support Levels
|
|
8
|
+
|
|
9
|
+
### Native Tool Use Support
|
|
10
|
+
Models with native tool use support:
|
|
11
|
+
- Have a hammer badge in the LM Studio app
|
|
12
|
+
- Generally perform better in tool use scenarios
|
|
13
|
+
- Include chat templates that specifically support tool use
|
|
14
|
+
- Are trained for tool use functionality
|
|
15
|
+
|
|
16
|
+
**Currently supported models with native tool use:**
|
|
17
|
+
- **Qwen series**
|
|
18
|
+
- `lmstudio-community/Qwen2.5-7B-Instruct-GGUF` (4.68 GB)
|
|
19
|
+
- `mlx-community/Qwen2.5-7B-Instruct-4bit` (4.30 GB)
|
|
20
|
+
- **Llama series**
|
|
21
|
+
- Llama-3.1, Llama-3.2 models
|
|
22
|
+
|
|
23
|
+
### Default Tool Use Support
|
|
24
|
+
**All models that don't have native tool use support will have default tool use support.**
|
|
25
|
+
|
|
26
|
+
LM Studio uses a standardized tool calling format that works with any model. The system provides a consistent interface regardless of the underlying model's capabilities.
|
|
27
|
+
|
|
28
|
+
## Tool Calling Format
|
|
29
|
+
|
|
30
|
+
### System Prompt Template
|
|
31
|
+
|
|
32
|
+
When tools are provided, LM Studio automatically formats the system prompt using this template:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
# Tools
|
|
36
|
+
|
|
37
|
+
You may call one or more functions to assist with the user query.
|
|
38
|
+
|
|
39
|
+
You are provided with function signatures within <tools></tools> XML tags:
|
|
40
|
+
<tools>
|
|
41
|
+
{
|
|
42
|
+
"type": "function",
|
|
43
|
+
"function": {
|
|
44
|
+
"name": "get_delivery_date",
|
|
45
|
+
"description": "Get the delivery date for a customer's order",
|
|
46
|
+
"parameters": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"properties": {
|
|
49
|
+
"order_id": {"type": "string"}
|
|
50
|
+
},
|
|
51
|
+
"required": ["order_id"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</tools>
|
|
56
|
+
|
|
57
|
+
For each function call, return a json object with function name and arguments within
|
|
58
|
+
|
|
59
|
+
{"name": "<function-name>", "arguments": <args-json-object>}```
|
|
60
|
+
|
|
61
|
+
**Important:** The model can only *request* calls to these tools because LLMs *cannot* directly call functions, APIs, or any other tools. They can only output text, which can then be parsed to programmatically call the functions.
|
|
62
|
+
|
|
63
|
+
### Response Options
|
|
64
|
+
|
|
65
|
+
When prompted, the LLM can either:
|
|
66
|
+
|
|
67
|
+
#### (a) Call one or more tools
|
|
68
|
+
```xml
|
|
69
|
+
User: Get me the delivery date for order 123
|
|
70
|
+
Model:```
|
|
71
|
+
|
|
72
|
+
#### (b) Respond normally
|
|
73
|
+
```xml
|
|
74
|
+
User: Hi
|
|
75
|
+
Model: Hello! How can I assist you today?
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API Usage
|
|
79
|
+
|
|
80
|
+
### Request Format
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
curl http://localhost:1234/v1/chat/completions \
|
|
84
|
+
-H "Content-Type: application/json" \
|
|
85
|
+
-d '{
|
|
86
|
+
"model": "lmstudio-community/qwen2.5-7b-instruct",
|
|
87
|
+
"messages": [{"role": "user", "content": "What dell products do you have under $50 in electronics?"}],
|
|
88
|
+
"tools": [
|
|
89
|
+
{
|
|
90
|
+
"type": "function",
|
|
91
|
+
"function": {
|
|
92
|
+
"name": "search_products",
|
|
93
|
+
"description": "Search the product catalog by various criteria. Use this whenever a customer asks about product availability, pricing, or specifications.",
|
|
94
|
+
"parameters": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": {
|
|
97
|
+
"query": {
|
|
98
|
+
"type": "string",
|
|
99
|
+
"description": "Search terms or product name"
|
|
100
|
+
},
|
|
101
|
+
"category": {
|
|
102
|
+
"type": "string",
|
|
103
|
+
"description": "Product category to filter by",
|
|
104
|
+
"enum": ["electronics", "clothing", "home", "outdoor"]
|
|
105
|
+
},
|
|
106
|
+
"max_price": {
|
|
107
|
+
"type": "number",
|
|
108
|
+
"description": "Maximum price in dollars"
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
"required": ["query"],
|
|
112
|
+
"additionalProperties": false
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Response Format
|
|
121
|
+
|
|
122
|
+
When the model decides to use tools, the response will include:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"id": "chatcmpl-gb1t1uqzefudice8ntxd9i",
|
|
127
|
+
"object": "chat.completion",
|
|
128
|
+
"created": 1730913210,
|
|
129
|
+
"model": "lmstudio-community/qwen2.5-7b-instruct",
|
|
130
|
+
"choices": [
|
|
131
|
+
{
|
|
132
|
+
"index": 0,
|
|
133
|
+
"logprobs": null,
|
|
134
|
+
"finish_reason": "tool_calls",
|
|
135
|
+
"message": {
|
|
136
|
+
"role": "assistant",
|
|
137
|
+
"tool_calls": [
|
|
138
|
+
{
|
|
139
|
+
"id": "365174485",
|
|
140
|
+
"type": "function",
|
|
141
|
+
"function": {
|
|
142
|
+
"name": "search_products",
|
|
143
|
+
"arguments": "{\"query\": \"dell\", \"category\": \"electronics\", \"max_price\": 50}"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## LM Studio Processing
|
|
154
|
+
|
|
155
|
+
### Parsing Logic
|
|
156
|
+
|
|
157
|
+
LM Studio parses the text output from the model into an OpenAI-compliant `chat.completion` response object:
|
|
158
|
+
|
|
159
|
+
1. **With tools array**: LM Studio attempts to parse tool calls into the `response.choices[0].message.tool_calls` field
|
|
160
|
+
2. **No valid tool calls**: Returns response to the standard `response.choices[0].message.content` field
|
|
161
|
+
3. **Invalid format**: Tool calls with incorrect formatting won't be parsed into the `tool_calls` field
|
|
162
|
+
|
|
163
|
+
### Error Handling
|
|
164
|
+
|
|
165
|
+
**Note:** Smaller models and models that were not trained for tool use may output improperly formatted tool calls, resulting in LM Studio being unable to parse them into the `tool_calls` field.
|
|
166
|
+
|
|
167
|
+
**Example of improperly formatted tool call:**
|
|
168
|
+
```xml
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
This fails because:
|
|
172
|
+
- Brackets are incorrect (should be `{}` not `[]`)
|
|
173
|
+
- Does not follow the required `name, arguments` format
|
|
174
|
+
- `function: "date"` is not a valid argument structure
|
|
175
|
+
|
|
176
|
+
## Alternative Tool Call Format
|
|
177
|
+
|
|
178
|
+
For models that don't follow the standard XML format, LM Studio also supports an alternative format:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
[TOOL_REQUEST]{"name": "get_delivery_date", "arguments": {"order_id": "123"}}[END_TOOL_REQUEST]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
If a model follows this format exactly, LM Studio will parse those tool calls into the `chat.completions` object, just like for natively supported models.
|
|
185
|
+
|
|
186
|
+
## Implementation Notes
|
|
187
|
+
|
|
188
|
+
### Key Features
|
|
189
|
+
|
|
190
|
+
1. **Universal Support**: All models have at least default tool use support
|
|
191
|
+
2. **OpenAI Compatibility**: Responses follow OpenAI's chat.completion format
|
|
192
|
+
3. **Flexible Parsing**: Supports multiple tool call formats
|
|
193
|
+
4. **Error Resilience**: Gracefully handles malformed tool calls
|
|
194
|
+
|
|
195
|
+
### Best Practices
|
|
196
|
+
|
|
197
|
+
1. **Model Selection**: Use models with native tool support for better results
|
|
198
|
+
2. **Parameter Validation**: Ensure all required parameters are included in function definitions
|
|
199
|
+
3. **Error Handling**: Always check if `tool_calls` array is populated in responses
|
|
200
|
+
4. **Testing**: Test tool calling with your specific model as capabilities vary
|
|
201
|
+
|
|
202
|
+
### Troubleshooting
|
|
203
|
+
|
|
204
|
+
If you're not receiving `tool_calls` as expected:
|
|
205
|
+
1. Verify the model supports tool calling (native or default)
|
|
206
|
+
2. Check the tool call format in the model's response
|
|
207
|
+
3. Ensure all required parameters are properly defined
|
|
208
|
+
4. Test with a model that has native tool support for comparison
|
|
209
|
+
|
|
210
|
+
## File Information
|
|
211
|
+
|
|
212
|
+
- **Source**: LM Studio Tool Use Documentation
|
|
213
|
+
- **URL**: https://lmstudio.ai/docs/app/api/tools
|
|
214
|
+
- **Extracted**: September 22, 2025
|