deepseek-toolkit 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +240 -0
  2. package/package.json +3 -1
package/README.md ADDED
@@ -0,0 +1,240 @@
1
+ # deepseek-toolkit
2
+
3
+ DeepSeek API toolkit with built-in Brave Search — batteries-included TypeScript wrapper for chat, tools, and web search.
4
+
5
+ ```bash
6
+ npm install deepseek-toolkit
7
+ ```
8
+
9
+ ## Quick Start
10
+
11
+ ```ts
12
+ import { DeepSeekClient } from "deepseek-toolkit";
13
+
14
+ const client = new DeepSeekClient({
15
+ deepseekApiKey: process.env.DEEPSEEK_API_KEY!,
16
+ braveSearchApiKey: process.env.BRAVE_SEARCH_API_KEY!, // optional
17
+ });
18
+
19
+ const response = await client.chat([
20
+ { role: "user", content: "What's new in AI?" },
21
+ ]);
22
+
23
+ console.log(response.choices[0].message.content);
24
+ ```
25
+
26
+ ## Features
27
+
28
+ - **DeepSeek V4** — `deepseek-v4-pro` and `deepseek-v4-flash` models
29
+ - **Thinking mode** — `enabled` / `disabled` with `reasoning_effort`: `high` or `max`
30
+ - **Built-in Brave Search** — web search and LLM-optimized context, auto-registered as tools
31
+ - **Custom tools** — `addTool()` with typed handlers, auto-execution loop
32
+ - **Streaming** — `chatStream()` with async iterable
33
+ - **Full TypeScript** — types exported for everything
34
+ - **ESM + CJS** — dual build, works everywhere
35
+ - **Minimal setup** — sensible defaults, zero config needed
36
+
37
+ ## Configuration
38
+
39
+ ```ts
40
+ interface DeepSeekConfig {
41
+ deepseekApiKey: string; // required
42
+ braveSearchApiKey?: string; // optional — enables built-in search tools
43
+ model?: "deepseek-v4-pro" | "deepseek-v4-flash"; // default: "deepseek-v4-pro"
44
+ thinking?: { type: "enabled" | "disabled" }; // default: { type: "enabled" }
45
+ reasoningEffort?: "high" | "max"; // default: "high"
46
+ braveSearch?: {
47
+ safesearch?: "off" | "moderate" | "strict"; // default: "off"
48
+ freshness?: "pd" | "pw" | "pm" | "py";
49
+ country?: string; // default: "US"
50
+ searchLang?: string; // default: "en"
51
+ count?: number; // default: 10
52
+ };
53
+ maxTokens?: number;
54
+ temperature?: number;
55
+ topP?: number;
56
+ baseURL?: string; // default: "https://api.deepseek.com"
57
+ maxToolLoopIterations?: number; // default: 10
58
+ }
59
+ ```
60
+
61
+ ## API
62
+
63
+ ### Chat
64
+
65
+ ```ts
66
+ // Single-turn
67
+ const r = await client.chat([
68
+ { role: "system", content: "You are a helpful assistant." },
69
+ { role: "user", content: "Hello!" },
70
+ ]);
71
+ console.log(r.choices[0].message.content);
72
+
73
+ // Streaming
74
+ const stream = await client.chatStream([
75
+ { role: "user", content: "Tell me a story." },
76
+ ]);
77
+ for await (const chunk of stream) {
78
+ process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
79
+ }
80
+ ```
81
+
82
+ ### Thinking Mode
83
+
84
+ ```ts
85
+ // High reasoning effort (default)
86
+ const r = await client.chat([
87
+ { role: "user", content: "9.11 and 9.8, which is greater?" },
88
+ ]);
89
+ console.log(r.choices[0].message.reasoning_content); // chain-of-thought
90
+ console.log(r.choices[0].message.content); // final answer
91
+
92
+ // Max reasoning effort for harder problems
93
+ client.reasoningEffort = "max";
94
+
95
+ // Disable thinking for fast responses
96
+ client.thinking = { type: "disabled" };
97
+
98
+ // Per-request override
99
+ const r = await client.chat(messages, {
100
+ thinking: { type: "disabled" },
101
+ reasoningEffort: "max",
102
+ });
103
+ ```
104
+
105
+ ### Brave Search
106
+
107
+ ```ts
108
+ // Direct web search (bypasses the model)
109
+ const results = await client.search("climate news", {
110
+ freshness: "pw", // past week
111
+ safesearch: "moderate",
112
+ count: 5,
113
+ });
114
+ console.log(results.web?.results);
115
+
116
+ // LLM-optimized search (pre-extracted content for AI consumption)
117
+ const ctx = await client.searchAsContext("TypeScript 5.8 features", {
118
+ maxTokens: 4096,
119
+ maxUrls: 5,
120
+ });
121
+ console.log(ctx.grounding.generic);
122
+
123
+ // Let the model decide when to search (auto tool-calling)
124
+ const r = await client.chat([
125
+ { role: "user", content: "Search the web: What's the latest TypeScript version?" },
126
+ ]);
127
+ // The model calls brave_web_search, the library executes it, returns grounded answer
128
+ console.log(r.choices[0].message.content);
129
+ ```
130
+
131
+ ### Custom Tools
132
+
133
+ ```ts
134
+ import type { ToolDefinition } from "deepseek-toolkit";
135
+
136
+ const weatherTool: ToolDefinition = {
137
+ type: "function",
138
+ function: {
139
+ name: "get_weather",
140
+ description: "Get current weather for a city",
141
+ parameters: {
142
+ type: "object",
143
+ properties: {
144
+ city: { type: "string", description: "City name" },
145
+ },
146
+ required: ["city"],
147
+ },
148
+ },
149
+ };
150
+
151
+ // Register with a handler for auto-execution
152
+ client.addTool(weatherTool, async (args) => {
153
+ const city = args.city;
154
+ // Call your weather API here
155
+ return JSON.stringify({ city, temp: 22, condition: "Sunny" });
156
+ });
157
+
158
+ // Register multiple tools at once
159
+ client.addTools([
160
+ { definition: toolA, handler: handlerA },
161
+ { definition: toolB, handler: handlerB },
162
+ ]);
163
+
164
+ // The model calls your tool, library auto-executes, loops until done
165
+ const r = await client.chat([
166
+ { role: "user", content: "What's the weather in Tokyo?" },
167
+ ]);
168
+ console.log(r.choices[0].message.content);
169
+
170
+ // Remove a tool
171
+ client.removeTool("get_weather");
172
+ ```
173
+
174
+ ### Runtime Config
175
+
176
+ ```ts
177
+ // Switch model
178
+ client.model = "deepseek-v4-flash";
179
+
180
+ // Toggle thinking
181
+ client.thinking = { type: "disabled" };
182
+ client.reasoningEffort = "max";
183
+
184
+ // Update Brave Search defaults
185
+ client.braveSearchDefaults = { safesearch: "strict", country: "DE" };
186
+ ```
187
+
188
+ ### Per-Request Options
189
+
190
+ ```ts
191
+ const r = await client.chat(messages, {
192
+ model: "deepseek-v4-flash",
193
+ thinking: { type: "disabled" },
194
+ maxTokens: 500,
195
+ temperature: 0.7,
196
+ tools: [myTool],
197
+ toolChoice: "auto",
198
+ onToolCall: async (name, args, id) => {
199
+ console.log(`Model called: ${name}(${JSON.stringify(args)})`);
200
+ return "custom result";
201
+ },
202
+ onToolResult: (name, result) => {
203
+ console.log(`Tool result: ${name} → ${result}`);
204
+ },
205
+ });
206
+ ```
207
+
208
+ ## Advanced
209
+
210
+ ### Access the raw OpenAI client
211
+
212
+ ```ts
213
+ const openai = client.openaiClient; // OpenAI instance
214
+ ```
215
+
216
+ ### Direct tool management
217
+
218
+ ```ts
219
+ import { ToolManager } from "deepseek-toolkit";
220
+
221
+ const tm = new ToolManager();
222
+ tm.addTool(myDefinition, myHandler);
223
+ const result = await tm.executeToolCall("my_tool", { arg: "val" }, "call_id");
224
+ ```
225
+
226
+ ### Error types
227
+
228
+ ```ts
229
+ import {
230
+ DeepSeekError,
231
+ BraveSearchError,
232
+ ToolError,
233
+ ToolLoopError,
234
+ ConfigError,
235
+ } from "deepseek-toolkit";
236
+ ```
237
+
238
+ ## License
239
+
240
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepseek-toolkit",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "DeepSeek API toolkit with built-in Brave Search — batteries-included wrapper for chat, tools, and web search",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -54,6 +54,8 @@
54
54
  "node": ">=18"
55
55
  },
56
56
  "dependencies": {
57
+ "deepseek-toolkit": "^0.1.1",
58
+ "dotenv": "^17.4.2",
57
59
  "openai": "^5.0.0"
58
60
  },
59
61
  "devDependencies": {