[教程]DeepSeek 本地化部署(Linux)

1、Ollama部署

参考 Ollama 官网

在 Linux 使用命令

curl -fsSL https://ollama.com/install.sh | sh

下载并执行 install.sh 脚本,注意保证根分区有足够的空间,如果没有,手动下载 install.sh ,修改目标安装位置。

如果修改了安装位置,需要将 /usr/local/bin/ollama 的符号链接删除,重建指向安装目录下的 bin/ollama 。

2、按需修改服务配置后启动服务

按需要修改服务中模型下载位置和服务端口,然后重载并重启服务。

Environment=”OLLAMA_MODELS=/opt/ollama/models” #可选:设置模型的下载位置
Environment=”OLLAMA_HOST=0.0.0.0:11434″ #可选:设置可访问ollama服务的地址与端口(此处表示任意IP地址都可以从端口11434访问此ollama服务)

3、运行命令下载模型

访问 Ollama 官网的 Deepseek 模型,找到需要的模型,性能越强,可选模型可以越好,可能的情况下,尽量选32b及以上的模型,不要先 14b 以下模型,输出内容的参考程度有限。

在终端中,输入 ollama run 模型名 来下载并进行模型执行,可以加入 –verbose 参数来显示统计数据。

ollama run deepseek-r1:14b –verbose

我测试了几个问题,感觉 14b 可以做为一个甜点值了,配置高的就选更好的模型。

4、联网搜索支持

在浏览器里安装 Page Assist 插件,然后设置好搜索引擎相关参数和文本嵌入相关设置。然后打开联网选项就可以了。

推荐 Delphi 开发者使用模型,直接转换 C 头文件到 Delphi 头文件效果相当不错,只有9GB大小:

ollama run ishumilin/deepseek-r1-coder-tools:14b

可选 1.5b/7b/8b/14b/32b/70b,32b 跑起来大约需要 50G+内存,70b 需要 98G 内存,也才43GB,有足够的内存也能跑起来。

14b 翻译 C++ 头文件到 Pascal 代码结果:

以下是将C语言头文件内容转换为Pascal格式的版本:

```pascal
(*
 * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under both the BSD-style license (found in the
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
 * in the COPYING file in the root directory of this source tree).
 * You may select, at your option, one of the above-listed licenses.
 *)

#ifndef ZSTD_ZLIBWRAPPER_H
#define ZSTD_ZLIBWRAPPER_H

{$if defined(__cplusplus__)}
interface

{$endif}

(* 定义 *)
#define ZLIB_CONST
#define Z_PREFIX
#define ZLIB_INTERNAL (* 禁用 gz*64 函数,但修复了 zlib 1.2.4 的 Z_PREFIX 问题 *)

#include <zlib.h>

{$ifndef z_const}
    #define z_const
{$endif}

(* 返回 zstd 库的版本字符串 *)
function zstdVersion: PChar;

(* 压缩部分 *)
procedure ZWRAP_useZSTDcompression(turn_on: Integer);
function ZWRAP_isUsingZSTDcompression: Integer;
function ZWRAP_setPledgedSrcSize(strm: z_streamp; pledgedSrcSize: UInt64): Integer;
function ZWRAP_deflateReset_keepDict(strm: z_streamp): Integer;

(* 解压部分 *)
type
    ZWRAP_decompress_type = (ZWRAP_FORCE_ZLIB, ZWRAP_AUTO);

procedure ZWRAP_setDecompressionType(type_: ZWRAP_decompress_type);
function ZWRAP_getDecompressionType: ZWRAP_decompress_type;
function ZWRAP_isUsingZSTDdecompression(strm: z_streamp): Integer;
function ZWRAP_inflateReset_keepDict(strm: z_streamp): Integer;

{$if defined(__cplusplus__)}
end
{$endif}

#endif (* ZSTD_ZLIBWRAPPER_H *)
```

此转换版本:
1. 使用了 Pascal 的语法结构,如 `(* 注释 *)` 和 `procedure/function` 声明。
2. 保留了原始文件的版权声明、许可证信息和宏定义。
3. 将 C 的 `typedef enum` 转换为 Pascal 的 `type` 定义。
4. 处理了函数指针和其他结构,使其适应 Pascal 的语法。
5. 移除了 C++ 的 `extern "C"` 和其他特定于语言的特性。

注意:Pascal 与 C 在某些方面存在差异,特别是关于文件包含和模块化。在实际使用中可能需要根据具体需求进行调整。

total duration:       1m40.432799843s
load duration:        11.188659ms
prompt eval count:    1894 token(s)
prompt eval duration: 21.461s
prompt eval rate:     88.25 tokens/s
eval count:           590 token(s)
eval duration:        1m18.936s
eval rate:            7.47 tokens/s

32b 的翻译结果:

好的,我现在要将一个C语言的头文件转换为Pascal格式。首先,我需要仔细阅读并理解这个C头文件的内容和结构。

从内容来看,这个头文件主要是Zstandard库的一个zlib包装器。它包含了压缩和解压缩的相关函数、宏定义以及一些类型定义。因此,在转换时,我需要确保所有这些元素都能在Pascal中正确地表达出来
。

首先,处理版权信息。C中的注释使用“/*”开始,“*/”结束。在Pascal中,单行注释用“{”,而多行注释则可以继续使用“{”和“}”。因此,我需要将版权部分的注释转换为Pascal的格式。

接下来是头文件的包含保护。C语言使用#ifndef, #define和#endif来防止重复包含。在Pascal中,通常使用条件编译指令{$IFNDEF}, {$DEFINE}和{$ENDIF}。所以这部分结构可以保持类似,只需要调整符
号即可。

然后是针对C++的外部块。C中的extern "C"告诉编译器这些函数应该按照C的方式处理。在Pascal中,我们使用 cdecl 调用约定,并且可能需要包裹函数声明在外层模块中。因此,这部分我需要添加一个 
begin..end 块来包含所有函数声明。

接下来是宏定义和头文件的包含。例如,ZLIB_CONST, Z_ PREFIX 等宏在Pascal中如何处理?Pascal通常不使用宏,而是直接定义常量或类型。因此,这些宏可能需要转换为const或者类似的方式。此外,
<zlib.h>在Pascal中可能已经有一个对应的单元(unit),所以可能需要调整include语句。

函数声明部分需要注意参数和返回类型的转换。例如,C中的void * zstdVersion(void)在Pascal中可以写成 function zstdVersion: PChar; cdecl; 因为Pascal使用PChar来表示指向字符的指针,并且
cdecl用于指定调用约定以匹配C语言的行为。

枚举类型和函数参数也需要调整。例如,ZWRAP_decompress_type是一个枚举类型,在Pascal中可以直接定义为type ZWRAP_decompress_type = (ZWRAP_FORCE_ZLIB, ZWRAP_AUTO); 这样更清晰。

函数的参数传递方式需要考虑是否使用引用或指针。比如z_streamp在C中是指向z_stream结构体的指针,因此在Pascal中应该使用var参数或者作为PzStream类型的指针来传递。

此外,所有的函数都需要添加 cdecl 调用约定,以确保Pascal能够正确调用这些外部C函数。同时,在模块结束时需要重新声明 cdecl,以避免影响后续代码的默认调用方式。

最后,需要注意的是,Pascal中的类型命名和大小写规则可能与C不同,因此在转换过程中要保持一致性,并根据需要调整标识符的大小写。

总结一下,转换过程包括以下几个步骤:

1. 处理注释:将C的多行注释转换为Pascal的多行注释。
2. 转换头文件保护:使用Pascal的条件编译指令代替C的#ifndef等。
3. 包装C函数声明:使用begin..end块和cdecl调用约定。
4. 替换宏定义:将C中的宏转换为Pascal中的常量或类型。
5. 转换数据类型:如z_streamp转为PzStream,const char *转为PChar等。
6. 适配函数声明:确保参数和返回类型的正确性,并添加必要的调用约定。
7. 处理枚举类型:在Pascal中定义相应的枚举类型。

在整个过程中,我需要仔细检查每个转换步骤,确保没有遗漏或错误。如果遇到不确定的部分,可能需要查阅相关文档或参考资料,以确保转换的准确性和兼容性。
</think>

以下是将提供的C语言头文件内容转换为Pascal格式的结果:

```pascal
{*
 * Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under both the BSD-style license (found in the
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
 * in the COPYING file in the root directory of this source tree).
 * You may select, at your option, one of the above-mentioned licenses.
 *}

{$IFNDEF ZSTD_ZLIBWRAPPER_H}
{$DEFINE ZSTD_ZLIBWRAPPER_H}

unit ZstdZlibWrapper;

interface

uses
  zlib; { Adjust this to the correct Pascal zlib unit if necessary }

type
  z_streamp = PzStream;
  ZWRAP_decompress_type = (ZWRAP_FORCE_ZLIB, ZWRAP_AUTO);

const
  ZLIB_CONST = '';
  Z_ PREFIX = '';

procedure UseZSTDCompression(turn_on: Integer); cdecl; external;
function IsUsingZSTDCompression: Integer; cdecl; external;
function SetPledgedSrcSize(strm: z_streamp; pledgedSrcSize: UInt64): Integer; cdecl; external;
function DeflateReset_keepDict(strm: z_streamp): Integer; cdecl; external;

procedure SetDecompressionType(type_: ZWRAP_decompress_type); cdecl; external;
function GetDecompressionType: ZWRAP_decompress_type; cdecl; external;
function IsUsingZSTDdecompression(strm: z_streamp): Integer; cdecl; external;
function InflateReset_keepDict(strm: z_streamp): Integer; cdecl; external;

function zstdVersion: PChar; cdecl; external;

implementation

begin
  { C functions are declared here with appropriate Pascal equivalents }
end.

{$ENDIF} { ZSTD_ZLIBWRAPPER_H }
```

### 注意事项:
1. **单元(Unit)名称**:确保单元名称与文件名一致。
2. **外部函数声明**:使用 `external` 关键字声明外部C函数,并指定正确的调用约定(如 `cdecl`)。
3. **类型映射**:将C中的结构体指针映射为相应的Pascal指针类型,例如 `z_streamp` 转换为 `PzStream`。
4. **枚举类型**:在Pascal中定义枚举类型以替代C中的枚举。
5. **字符串处理**:使用 `PChar` 来表示指向字符的指针,并根据需要进行转换。

请根据实际开发环境和Pascal编译器的具体要求调整上述代码。

total duration:       7m27.911770823s
load duration:        12.723748ms
prompt eval count:    1089 token(s)
prompt eval duration: 56.433s
prompt eval rate:     19.30 tokens/s
eval count:           1419 token(s)
eval duration:        6m31.464s
eval rate:            3.62 tokens/s
滚动至顶部