pi-deepseek-tuner
v1.0.3
Published
Pi coding agent extension to optimize DeepSeek models (official & third-party) by stripping thinking history, repairing tool pairings, and enforcing prompt caching.
Maintainers
Readme
Pi DeepSeek Tuner
DeepSeek model tuner extension for Pi. Intercepts and optimizes API payload interactions with DeepSeek models (both official and third-party compatible endpoints) by intercepting requests at the provider gateway level, saving costs and ensuring high availability.
Key Mechanics
Reasoning History Stripping (Cost-Saving)
- The Problem: Resending previous chain-of-thought (
reasoning_contentor<think>tags) back to DeepSeek models in multi-turn conversations acts as billable input tokens, drastically blowing up API costs. - The Solution: Intercepts
before_provider_requestpayload and deletes the reasoning cache fromassistanthistory, saving up to 80% on API fees.
- The Problem: Resending previous chain-of-thought (
Strict Tool-Call Pairing (Sanitization)
- The Problem: Dangling or unanswered
tool_callsgenerated by the model due to connection issues or session interrupts cause DeepSeek API to throw a400 Bad Requestvalidation error. - The Solution: Validates the conversation history, backfills placeholder results for unanswered calls, and discards orphan tool responses to strictly respect the API schema.
- The Problem: Dangling or unanswered
Auto Thinking Mode Toggle
- Automatically injects
{ thinking: { type: "enabled" } }for DeepSeek R1 models to ensure reasoning chunks are streamed successfully even through non-official proxy endpoints.
- Automatically injects
Project Structure
pi-deepseek-tuner/
├── index.ts # Core hook logic (TypeScript)
├── package.json # Extension manifest with peerDependencies for Pi
├── tsconfig.json # TypeScript configurations targeting NodeES
└── biome.jsonInstallation
pi install npm:pi-deepseek-tunerTesting
Run the native TypeScript unit test suite (Node.js native test runner):
npm run testDevelopment
We align with the code quality and security standards of the primary pi-main workspace:
- Linter & Formatter: Biome is configured to auto-format and check codebase. We use
tabindentation with a width of3characters. - Commands:
- Check format and Lint:
npm run check - Run tests:
npm test
- Check format and Lint:
License
MIT
