Skip to content

Commit e5ac732

Browse files
committed
docs: DeepSeek
1 parent 338ef7b commit e5ac732

File tree

7 files changed

+198
-8
lines changed

7 files changed

+198
-8
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<script setup lang="ts">
2+
import {computed} from "vue";
3+
const props = withDefaults(defineProps<{
4+
id: string,
5+
autoplay?: boolean,
6+
controls?: boolean
7+
}>(), {
8+
autoplay: false,
9+
controls: true
10+
});
11+
12+
const url = computed(() => {
13+
const res = new URL(`https://www.youtube.com/embed/${props.id}`);
14+
res.searchParams.set("origin", location.origin);
15+
res.searchParams.set("autoplay", props.autoplay ? "1" : "0");
16+
res.searchParams.set("controls", props.controls ? "1" : "0");
17+
res.searchParams.set("playsinline", "1");
18+
res.searchParams.set("rel", "0");
19+
20+
return res.href;
21+
});
22+
</script>
23+
24+
<template>
25+
<div class="youtubePlayer" v-if="url">
26+
<iframe
27+
class="player"
28+
:src="url"
29+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
30+
allowfullscreen
31+
/>
32+
</div>
33+
</template>
34+
35+
<style scoped>
36+
.youtubePlayer {
37+
margin-top: 1em;
38+
overflow: hidden;
39+
border-radius: 12px;
40+
background-color: color-mix(in srgb, var(--vp-c-text-1) 6%, transparent);
41+
42+
> .player {
43+
width: 100%;
44+
aspect-ratio: 16 / 9;
45+
min-height: 240px;
46+
max-height: 600px;
47+
border: none;
48+
}
49+
}
50+
</style>

.vitepress/theme/LayoutContainer.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ if (typeof document !== "undefined")
1616
document?.documentElement.classList.toggle("theme-transition", themeTransitionEnabled);
1717
1818
function updateIsBlogPage() {
19-
document?.documentElement.classList.toggle(
20-
"blog-page",
21-
route.path !== "/blog/" && route.path.startsWith("/blog/")
22-
);
19+
const blogIndex = route.path === "/blog/";
20+
document?.documentElement.classList.toggle("blog-page", !blogIndex && route.path.startsWith("/blog/"));
21+
document?.documentElement.classList.toggle("blog-index", blogIndex);
2322
}
2423
2524
watch(() => route.path, updateIsBlogPage);

.vitepress/theme/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import LatestVersionHomeBadge from "../components/LatestVersionHomeBadge/LatestV
99
import CommentsSection from "../components/CommentsSection/CommentsSection.vue";
1010
import {NolebaseGitChangelogPlugin} from "@nolebase/vitepress-plugin-git-changelog/client";
1111
import LayoutContainer from "./LayoutContainer.vue";
12+
import YouTubePlayer from "../components/YouTubePlayer/YouTubePlayer.vue";
1213

1314
import "./style.css";
1415
import "@nolebase/vitepress-plugin-git-changelog/client/style.css";
@@ -18,9 +19,9 @@ import type {EnhanceAppContext} from "vitepress";
1819
export default {
1920
extends: Theme,
2021
Layout: () => {
21-
const text = "v3.0 is here!";
22-
const link = "/blog/v3";
23-
const hideDate = new Date("2025-01-01T00:00:00Z");
22+
const text = "DeepSeek R1 is here!";
23+
const link = "/blog/v3.6-deepseek-r1";
24+
const hideDate = new Date("2025-06-01T00:00:00Z");
2425

2526
return h(LayoutContainer, null, h(Theme.Layout, null, {
2627
"home-hero-info-before": () => h(LatestVersionHomeBadge, {
@@ -35,6 +36,7 @@ export default {
3536
}));
3637
},
3738
enhanceApp({app, router, siteData}: EnhanceAppContext) {
39+
app.component("YouTubePlayer", YouTubePlayer);
3840
app.use(TwoslashFloatingVue);
3941
app.use(NolebaseGitChangelogPlugin, {
4042
displayAuthorsInsideCommitLine: true,

.vitepress/theme/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,15 @@ html.blog-page .vp-doc>div>hr:first-of-type {
562562
display: none;
563563
}
564564

565+
@media (min-width: 960px) {
566+
html.blog-index .VPDoc:not(.has-sidebar)>.container>.content,
567+
html.blog-page .VPDoc:not(.has-sidebar)>.container>.content {
568+
max-width: 896px;
569+
padding-left: 0px;
570+
padding-right: 0px;
571+
}
572+
}
573+
565574
/*#VPContent {*/
566575
/* background-image: radial-gradient(1200px 380px at 50% 0%, color-mix(in srgb, var(--vp-c-brand-1) 32%, transparent), transparent 64%);*/
567576
/*}*/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
</div>
1717

18-
[`v3.0` is here!](https://node-llama-cpp.withcat.ai/blog/v3)
18+
[DeepSeek R1 is here!](https://node-llama-cpp.withcat.ai/blog/v3.6-deepseek-r1)
1919

2020
## Features
2121
* Run LLMs locally on your machine

docs/blog/v3.6-deepseek-r1.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: DeepSeek R1 with function calling
3+
date: 2025-02-20T22:00:00Z
4+
lastUpdated: false
5+
author:
6+
name: Gilad S.
7+
github: giladgd
8+
category: Release
9+
description: node-llama-cpp v3.6 is here, with full support for DeepSeek R1, including function calling!
10+
image:
11+
url: https://github.com/user-attachments/assets/9ed954f8-102d-4cdd-96d8-9b6710b8a1f5
12+
alt: "node-llama-cpp + DeepSeek R1"
13+
width: 3072
14+
height: 1536
15+
---
16+
[`node-llama-cpp`](https://node-llama-cpp.withcat.ai) v3.6 is here, with full support for [DeepSeek R1](https://github.com/deepseek-ai/DeepSeek-R1), including function calling!
17+
18+
---
19+
20+
## Function Calling
21+
`node-llama-cpp` includes [many tricks](../guide/function-calling) used to make function calling work with most models.
22+
This release includes special adaptations for DeepSeek R1 to improve function calling performance and stability.
23+
24+
Here's a basic example of function calling with DeepSeek R1:
25+
```typescript
26+
import {fileURLToPath} from "url";
27+
import path from "path";
28+
import {
29+
getLlama, LlamaChatSession, defineChatSessionFunction, resolveModelFile
30+
} from "node-llama-cpp";
31+
32+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
33+
const modelsDir = path.join(__dirname, "..", "models");
34+
35+
const modelUri = "hf:mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M";
36+
37+
38+
const llama = await getLlama();
39+
const model = await llama.loadModel({
40+
modelPath: await resolveModelFile(modelUri, modelsDir)
41+
});
42+
const context = await model.createContext();
43+
const session = new LlamaChatSession({
44+
contextSequence: context.getSequence()
45+
});
46+
47+
const fruitPrices: Record<string, string> = {
48+
"apple": "$6",
49+
"banana": "$4"
50+
};
51+
const functions = {
52+
getFruitPrice: defineChatSessionFunction({
53+
description: "Get the price of a fruit",
54+
params: {
55+
type: "object",
56+
properties: {
57+
name: {
58+
type: "string"
59+
}
60+
}
61+
},
62+
async handler(params) {
63+
const name = params.name.toLowerCase();
64+
if (Object.keys(fruitPrices).includes(name))
65+
return {
66+
name: name,
67+
price: fruitPrices[name]
68+
};
69+
70+
return `Unrecognized fruit "${params.name}"`;
71+
}
72+
})
73+
};
74+
75+
76+
const q1 = "Is an apple more expensive than a banana?";
77+
console.log("User: " + q1);
78+
79+
const a1 = await session.prompt(q1, {functions});
80+
console.log("AI: " + a1.trim());
81+
```
82+
83+
84+
## Recommended Models
85+
Here are some recommended model URIs you can use to try out DeepSeek R1 with function calling.
86+
87+
| Model | Size | URI |
88+
|---------------------------------------------------------------------------------------------------------|--------|-------------------------------------------------------------|
89+
| [DeepSeek R1 Distill Qwen 7B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF) | 4.68GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-7B-GGUF:Q4_K_M` |
90+
| [DeepSeek R1 Distill Qwen 14B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-14B-GGUF) | 8.99GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-14B-GGUF:Q4_K_M` |
91+
| [DeepSeek R1 Distill Qwen 32B](https://huggingface.co/mradermacher/DeepSeek-R1-Distill-Qwen-32B-GGUF) | 23.3GB | `hf:mradermacher/DeepSeek-R1-Distill-Qwen-32B-GGUF:Q4_K_M` |
92+
93+
::: info TIP
94+
Estimate the compatibility of a model with your machine before downloading it using the [`inspect estimate`](../cli/inspect/estimate.md) command:
95+
```shell
96+
npx -y node-llama-cpp inspect estimate <model URI>
97+
```
98+
:::
99+
100+
### Try It Using the CLI
101+
To try out function calling with a given model using the CLI, you can use the [`chat` command](../cli/chat.md) with the `--ef` flag
102+
to provide the model with date and time functions:
103+
104+
```shell
105+
npx -y node-llama-cpp chat --ef --prompt "What is the time?" <model URI>
106+
```
107+
108+
109+
## Chain of Thought Segmentation
110+
The thoughts generated by a reasoning model are now [separated into `thought` segments](../guide/chat-session.md#stream-response-segments) in the response,
111+
so you can choose whether to use them or not.
112+
113+
By default, the [`.prompt(...)`](../api/classes/LlamaChatSession#prompt) method returns only the main response, without any `thought` segments.
114+
Use the [`.promptWithMeta(...)`](../api/classes/LlamaChatSession#promptwithmeta) method to get the full response.
115+
116+
You can use the new [`onResponseChunk`](../api/type-aliases/LLamaChatPromptOptions.md#onresponsechunk) option to [stream `thought` segments as they are being generated](../guide/chat-session.md#stream-response-segments).
117+
118+
119+
## Electron App Template
120+
The [Electron app template](../guide/electron.md) has been updated to properly segment the thoughts in the response.
121+
122+
Try it out by downloading the latest build [from GitHub](https://github.com/withcatai/node-llama-cpp/releases/latest),
123+
or by [scaffolding a new project](../guide/index.md#scaffold-new-project) based on the Electron template:
124+
125+
```shell
126+
npm create node-llama-cpp@latest
127+
```
128+
129+
<YouTubePlayer id="IqfMs0lfIvQ" />

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"local",
111111
"catai",
112112
"mistral",
113+
"deepseek",
113114
"typescript",
114115
"lora",
115116
"batching",

0 commit comments

Comments
 (0)