|
| 1 | +<div align="center"> |
| 2 | + <img src="./media/header_ai.png" > |
| 3 | +</div> |
| 4 | + |
| 5 | +<br /> |
| 6 | + |
| 7 | +<div align="center"> |
| 8 | +<a href="https://npmjs.com/package/@tanstack/ai-deepseek" target="\_parent"> |
| 9 | + <img alt="" src="https://img.shields.io/npm/dm/@tanstack/ai-deepseek.svg" /> |
| 10 | +</a> |
| 11 | +<a href="https://github.com/TanStack/ai" target="\_parent"> |
| 12 | + <img alt="" src="https://img.shields.io/github/stars/TanStack/ai.svg?style=social&label=Star" alt="GitHub stars" /> |
| 13 | +</a> |
| 14 | +<a href="https://bundlephobia.com/result?p=@tanstack/ai-deepseek@latest" target="\_parent"> |
| 15 | + <img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/ai-deepseek@latest" /> |
| 16 | +</a> |
| 17 | +</div> |
| 18 | + |
| 19 | +<div align="center"> |
| 20 | +<a href="#badge"> |
| 21 | + <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg"> |
| 22 | +</a> |
| 23 | + <a href="#badge"> |
| 24 | + <img src="https://img.shields.io/github/v/release/tanstack/ai" alt="Release"/> |
| 25 | + </a> |
| 26 | +<a href="https://twitter.com/tan_stack"> |
| 27 | + <img src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social" alt="Follow @TanStack"/> |
| 28 | +</a> |
| 29 | +</div> |
| 30 | + |
| 31 | +<div align="center"> |
| 32 | + |
| 33 | +### [Become a Sponsor!](https://github.com/sponsors/tannerlinsley/) |
| 34 | +</div> |
| 35 | + |
| 36 | +# TanStack AI - DeepSeek Adapter |
| 37 | + |
| 38 | +DeepSeek adapter for TanStack AI - provides access to DeepSeek's powerful language models including DeepSeek-V3, DeepSeek Reasoner, and DeepSeek Coder. |
| 39 | + |
| 40 | +- **Tree-shakeable adapters** - Import only what you need for smaller bundles |
| 41 | +- **Type-safe model options** - Fully typed DeepSeek model configurations |
| 42 | +- **Tool calling support** - Function calling with automatic tool execution |
| 43 | +- **Streaming responses** - Real-time response streaming |
| 44 | +- **Structured output** - Type-safe responses with Zod schemas |
| 45 | + |
| 46 | +### <a href="https://tanstack.com/ai/docs/adapters/deepseek">Read the docs →</b></a> |
| 47 | + |
| 48 | +## Tree-Shakeable Adapters |
| 49 | + |
| 50 | +Import only the functionality you need for smaller bundle sizes: |
| 51 | + |
| 52 | +```typescript |
| 53 | +// Only chat functionality - no summarization code bundled |
| 54 | +import { deepseekText } from '@tanstack/ai-deepseek/adapters' |
| 55 | +import { chat } from '@tanstack/ai' |
| 56 | + |
| 57 | +// Set your DeepSeek API key |
| 58 | +process.env.DEEPSEEK_API_KEY = 'sk-...' |
| 59 | + |
| 60 | +// Create adapter |
| 61 | +const adapter = deepseekText('deepseek-chat') |
| 62 | + |
| 63 | +// Start chatting |
| 64 | +const stream = chat({ |
| 65 | + adapter, |
| 66 | + messages: [{ role: 'user', content: 'Hello, DeepSeek!' }] |
| 67 | +}) |
| 68 | + |
| 69 | +for await (const chunk of stream) { |
| 70 | + if (chunk.type === 'content') { |
| 71 | + console.log(chunk.delta) |
| 72 | + } |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +Available adapters: `deepseekText`, `deepseekSummarize` |
| 77 | + |
| 78 | +## Installation |
| 79 | + |
| 80 | +```bash |
| 81 | +npm install @tanstack/ai-deepseek @tanstack/ai zod |
| 82 | +``` |
| 83 | + |
| 84 | +## Supported Models |
| 85 | + |
| 86 | +### Chat/Text Models |
| 87 | + |
| 88 | +- `deepseek-chat` - Latest DeepSeek-V3 model with strong reasoning capabilities |
| 89 | +- `deepseek-reasoner` - Specialized reasoning model with enhanced logical thinking |
| 90 | +- `deepseek-coder` - Code-specialized model based on DeepSeek-Coder-V2 |
| 91 | + |
| 92 | +## Features |
| 93 | + |
| 94 | +### Tool Calling |
| 95 | + |
| 96 | +DeepSeek supports function calling with automatic tool execution: |
| 97 | + |
| 98 | +```typescript |
| 99 | +import { toolDefinition } from '@tanstack/ai' |
| 100 | +import { z } from 'zod' |
| 101 | + |
| 102 | +const weatherTool = toolDefinition({ |
| 103 | + name: 'getWeather', |
| 104 | + inputSchema: z.object({ |
| 105 | + location: z.string().describe('City name'), |
| 106 | + }), |
| 107 | + outputSchema: z.object({ |
| 108 | + temperature: z.number(), |
| 109 | + condition: z.string(), |
| 110 | + }), |
| 111 | +}) |
| 112 | + |
| 113 | +const serverTool = weatherTool.server(async ({ location }) => { |
| 114 | + // Your weather API call here |
| 115 | + return { temperature: 72, condition: 'sunny' } |
| 116 | +}) |
| 117 | + |
| 118 | +const stream = chat({ |
| 119 | + adapter: deepseekText('deepseek-chat'), |
| 120 | + messages: [{ role: 'user', content: 'What\'s the weather in San Francisco?' }], |
| 121 | + tools: [serverTool], |
| 122 | +}) |
| 123 | +``` |
| 124 | + |
| 125 | +### Structured Output |
| 126 | + |
| 127 | +Generate type-safe structured responses using Zod schemas: |
| 128 | + |
| 129 | +```typescript |
| 130 | +import { generate } from '@tanstack/ai' |
| 131 | +import { z } from 'zod' |
| 132 | + |
| 133 | +const schema = z.object({ |
| 134 | + summary: z.string(), |
| 135 | + keyPoints: z.array(z.string()), |
| 136 | + sentiment: z.enum(['positive', 'negative', 'neutral']), |
| 137 | +}) |
| 138 | + |
| 139 | +const result = await generate({ |
| 140 | + adapter: deepseekText('deepseek-chat'), |
| 141 | + messages: [{ |
| 142 | + role: 'user', |
| 143 | + content: 'Analyze this product review: "Great product, love it!"' |
| 144 | + }], |
| 145 | + schema, |
| 146 | +}) |
| 147 | + |
| 148 | +// result.data is fully typed according to your schema |
| 149 | +console.log(result.data.summary) |
| 150 | +console.log(result.data.keyPoints) |
| 151 | +console.log(result.data.sentiment) |
| 152 | +``` |
| 153 | + |
| 154 | +### Streaming Support |
| 155 | + |
| 156 | +All adapters support streaming for real-time responses: |
| 157 | + |
| 158 | +```typescript |
| 159 | +const stream = chat({ |
| 160 | + adapter: deepseekText('deepseek-chat'), |
| 161 | + messages: [{ role: 'user', content: 'Write a story about AI' }], |
| 162 | +}) |
| 163 | + |
| 164 | +for await (const chunk of stream) { |
| 165 | + switch (chunk.type) { |
| 166 | + case 'content': |
| 167 | + process.stdout.write(chunk.delta) |
| 168 | + break |
| 169 | + case 'tool_call': |
| 170 | + console.log('Tool called:', chunk.toolCall.function.name) |
| 171 | + break |
| 172 | + case 'done': |
| 173 | + console.log('\nUsage:', chunk.usage) |
| 174 | + break |
| 175 | + } |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +## Configuration |
| 180 | + |
| 181 | +### Environment Variables |
| 182 | + |
| 183 | +Set your DeepSeek API key: |
| 184 | + |
| 185 | +```bash |
| 186 | +export DEEPSEEK_API_KEY="sk-your-api-key-here" |
| 187 | +``` |
| 188 | + |
| 189 | +### Custom Configuration |
| 190 | + |
| 191 | +```typescript |
| 192 | +import { createDeepSeekText } from '@tanstack/ai-deepseek' |
| 193 | + |
| 194 | +const adapter = createDeepSeekText('deepseek-chat', 'sk-...', { |
| 195 | + baseURL: 'https://api.deepseek.com', // Custom API endpoint |
| 196 | +}) |
| 197 | +``` |
| 198 | + |
| 199 | +### Model Options |
| 200 | + |
| 201 | +Configure model-specific parameters: |
| 202 | + |
| 203 | +```typescript |
| 204 | +const stream = chat({ |
| 205 | + adapter: deepseekText('deepseek-chat'), |
| 206 | + messages: [{ role: 'user', content: 'Hello!' }], |
| 207 | + temperature: 0.8, // Creativity (0-2) |
| 208 | + maxTokens: 2000, // Response length |
| 209 | + topP: 0.9, // Nucleus sampling |
| 210 | + frequencyPenalty: 0.1, // Reduce repetition |
| 211 | + presencePenalty: 0.1, // Encourage novelty |
| 212 | + stop: ['END'], // Stop sequences |
| 213 | +}) |
| 214 | +``` |
| 215 | + |
| 216 | +## Type Safety |
| 217 | + |
| 218 | +This adapter provides full TypeScript support with: |
| 219 | + |
| 220 | +- **Per-model type inference** - Options are typed based on the selected model |
| 221 | +- **Tool type safety** - Automatic inference of tool input/output types |
| 222 | +- **Schema validation** - Runtime validation with Zod schemas |
| 223 | + |
| 224 | +```typescript |
| 225 | +// Model-specific type inference |
| 226 | +const adapter = deepseekText('deepseek-reasoner') // Types inferred for reasoning model |
| 227 | + |
| 228 | +// Tool type safety |
| 229 | +const tool = toolDefinition({ |
| 230 | + name: 'calculate', |
| 231 | + inputSchema: z.object({ expression: z.string() }), |
| 232 | + outputSchema: z.object({ result: z.number() }), |
| 233 | +}) |
| 234 | + |
| 235 | +// Fully typed tool implementation |
| 236 | +const serverTool = tool.server(async ({ expression }) => { |
| 237 | + // expression is typed as string |
| 238 | + return { result: eval(expression) } // result must be { result: number } |
| 239 | +}) |
| 240 | +``` |
| 241 | + |
| 242 | +## DeepSeek Model Capabilities |
| 243 | + |
| 244 | +| Model | Strengths | Best For | |
| 245 | +|-------|-----------|----------| |
| 246 | +| `deepseek-chat` | General conversation, reasoning | Chat applications, general Q&A | |
| 247 | +| `deepseek-reasoner` | Enhanced logical thinking | Complex problem solving, analysis | |
| 248 | +| `deepseek-coder` | Code understanding and generation | Programming assistance, code review | |
| 249 | + |
| 250 | +## Limitations |
| 251 | + |
| 252 | +- **Image Generation**: DeepSeek does not currently support image generation |
| 253 | +- **Multimodal Input**: Limited support for non-text inputs compared to other providers |
| 254 | +- **Rate Limits**: Refer to DeepSeek's API documentation for current rate limits |
| 255 | + |
| 256 | +## Get Involved |
| 257 | + |
| 258 | +- We welcome issues and pull requests! |
| 259 | +- Participate in [GitHub discussions](https://github.com/TanStack/ai/discussions) |
| 260 | +- Chat with the community on [Discord](https://discord.com/invite/WrRKjPJ) |
| 261 | +- See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions |
| 262 | + |
| 263 | +## Partners |
| 264 | + |
| 265 | +<table align="center"> |
| 266 | + <tr> |
| 267 | + <td> |
| 268 | + <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" > |
| 269 | + <picture> |
| 270 | + <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/coderabbit-dark-CMcuvjEy.svg" height="40" /> |
| 271 | + <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" /> |
| 272 | + <img src="https://tanstack.com/assets/coderabbit-light-DVMJ2jHi.svg" height="40" alt="CodeRabbit" /> |
| 273 | + </picture> |
| 274 | + </a> |
| 275 | + </td> |
| 276 | + <td> |
| 277 | + <a href="https://www.cloudflare.com?utm_source=tanstack"> |
| 278 | + <picture> |
| 279 | + <source media="(prefers-color-scheme: dark)" srcset="https://tanstack.com/assets/cloudflare-white-DQDB7UaL.svg" height="60" /> |
| 280 | + <source media="(prefers-color-scheme: light)" srcset="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" /> |
| 281 | + <img src="https://tanstack.com/assets/cloudflare-black-CPufaW0B.svg" height="60" alt="Cloudflare" /> |
| 282 | + </picture> |
| 283 | + </a> |
| 284 | + </td> |
| 285 | + </tr> |
| 286 | +</table> |
| 287 | + |
| 288 | +<div align="center"> |
| 289 | +<img src="./media/partner_logo.svg" alt="AI & you?" height="65"> |
| 290 | +<p> |
| 291 | +We're looking for TanStack AI Partners to join our mission! Partner with us to push the boundaries of TanStack AI and build amazing things together. |
| 292 | +</p> |
| 293 | +< a href= "mailto:[email protected]?subject=TanStack AI Partnership">< b>LET'S CHAT</ b></ a> |
| 294 | +</div> |
| 295 | + |
| 296 | +## Explore the TanStack Ecosystem |
| 297 | + |
| 298 | +- <a href="https://github.com/tanstack/config"><b>TanStack Config</b></a> – Tooling for JS/TS packages |
| 299 | +- <a href="https://github.com/tanstack/db"><b>TanStack DB</b></a> – Reactive sync client store |
| 300 | +- <a href="https://github.com/tanstack/devtools"><b>TanStack Devtools</b></a> – Unified devtools panel |
| 301 | +- <a href="https://github.com/tanstack/form"><b>TanStack Form</b></a> – Type‑safe form state |
| 302 | +- <a href="https://github.com/tanstack/pacer"><b>TanStack Pacer</b></a> – Debouncing, throttling, batching |
| 303 | +- <a href="https://github.com/tanstack/query"><b>TanStack Query</b></a> – Async state & caching |
| 304 | +- <a href="https://github.com/tanstack/ranger"><b>TanStack Ranger</b></a> – Range & slider primitives |
| 305 | +- <a href="https://github.com/tanstack/router"><b>TanStack Router</b></a> – Type‑safe routing, caching & URL state |
| 306 | +- <a href="https://github.com/tanstack/router"><b>TanStack Start</b></a> – Full‑stack SSR & streaming |
| 307 | +- <a href="https://github.com/tanstack/store"><b>TanStack Store</b></a> – Reactive data store |
| 308 | +- <a href="https://github.com/tanstack/table"><b>TanStack Table</b></a> – Headless datagrids |
| 309 | +- <a href="https://github.com/tanstack/virtual"><b>TanStack Virtual</b></a> – Virtualized rendering |
| 310 | + |
| 311 | +… and more at <a href="https://tanstack.com"><b>TanStack.com »</b></a> |
| 312 | + |
| 313 | +<!-- USE THE FORCE LUKE --> |
0 commit comments