php接入DeepSeek api对话

PHP 调用 DeepSeek API 完整指南 本文将介绍如何使用 PHP 调用 DeepSeek API,实现流式对话并保存对话记录。PHP 版本使用面向对象的方式实现,代码结构清晰,易于维护。PHP 版本的 DeepSeek API 实现采用面向对象方式,代码结构清晰,易于维护和扩展。通过 cURL 实现流式处理,提供了良好的交互体验。 阅读详情

啊里云服务器、宝塔、fastadmin后台

1、推荐使用Composer安装一个轻量级HTTP客户端(Guzzle),方便发起请求

在宝塔面版,打开(终端),输入

composer require guzzlehttp/guzzle

2、DeepSeek api申请
打开DeepSeek API开放平台官网(platform.deepseek.com),点击注册,使用邮箱或手机号完成账号创建,创建完成后购买相应的token

3、把composer下载好的guzzlehttp文件夹,移动到 app\common\library 下面

4、在 app\common\library 下创建 DeepSeekService PHP文件,文件代码如下

<?php
namespace app\common\library;
use GuzzleHttp\Client;

class DeepSeekService
{
    private $apiKey;
    private $apiUrl = 'https://api.deepseek.com/v1/chat/completions';

    public function __construct($apiKey)
    {
        $this->apiKey = $apiKey;
    }

    public function chat($message)
    {

        $client = new Client();
        $response = $client->post($this->apiUrl, [
            'headers' => [
                'Authorization' => 'Bearer ' . $this->apiKey,
                'Content-Type'  => 'application/json',
            ],
            'json'    => [
                'model'    => 'deepseek-v4-flash', // 根据需要选择模型
                'messages' => [
                    ['role' => 'system', 'content' => '你是一个有帮助的助手。'],
                    ['role' => 'user', 'content' => $message],
                ],
            ],
        ]);

        $body = json_decode($response->getBody(), true);
        return $body['choices'][0]['message']['content'] ?? '';
    }
}

5、在自定义的php中,调用chat对话,获取返回结果

 public function test(){
        $deepseek = new \app\common\library\DeepSeekService('deepSeek申请的api key');
        $answer = $deepseek->chat('小新美食店 推荐菜式 铁板牛肉、白切鸡、咕噜肉 生成一个评价 ');
        p($answer);
        die;
    }

结束

使用PHP+HTML集成DeepSeek API,实现一个简单的聊天对话项目 阅读详情

相关推荐

PHP接入DeepSeek API的两种专业方法:从原生cURL到高效封装

本文介绍了PHP接入DeepSeek API的两种方法:原生cURL方案和Guzzle封装方案。cURL方式简单直接,适合轻量级项目;Guzzle方案则提供更完善的错误处理、并发请求等企业级功能,推荐用于生产环境。两种方法均通过代码示例详细演示了API调用流程,并对比了各自优缺点。文章还包含常见问题解决方案和最佳实践建议,如密钥管理、异步处理等,帮助开发者快速集成DeepSeek的强大AI能力到PHP应用中。

九品菜鸟的博客 1382

三步接入DeepSeek智能对话API:PHP代码实现与响应解析

这篇技术博客提供了两方面的实用指南:首先,详细介绍了如何接入DeepSeek智能对话API,涵盖创建API Key、PHP代码实现请求封装及返回结果解析,示例代码清晰展示了请求参数与错误处理逻辑,并附有响应结构说明,内容简明实用,兼顾代码示例与系统配置,适合开发者快速实现API集成或排查环境问题,提升开发效率。

stark张宇 770

使用mne包来对脑电数据进行预处理(一)

MNE(MNE-Python)是一个用于处理脑电(EEG)、磁图(MEG)和其他神经科学数据的Python库。它提供了丰富的功能,包括数据加载、预处理、分析和可视化,旨在帮助研究人员和神经科学家更轻松地进行脑电数据的处理和分析。在本文中,我们使用mne来对不同的格式的脑电数据集进行数据读取。

m0_71596228的博客 4305

php 实现 deepSeek聊天对话

deepSeek 在 2025年可以说是火热。它可以说是国内版真正义意上的chatgpt。那么,如果我要实现用php 接入 deepSeek 的api呢。其实,方法也很简单。下面的代码我是自己封装过的,大家可以直接拿来使用,记得自己修改下密钥。

weixin_42371812的博客 1061

CMake、Make、MinGw、Clang、Llvm、GCC、MSVC的区别

除开 GCC (GNU 编译器集合) 以外,MinGW 还包含有一些其他的 GNU 程序开发工具;的缩写,MinGw是windows版本的gcc集合。并不仅是一个 C/C++ 编译器,而是一套。是微软开发的VC运行时库,3、Make和CMake是。

m0_37698164的博客 1万+

一个开源的AI数据分析工具,与数据对话,一键生成SQL、图表、表格、报告和智能商业分析。

Wren AI是一个开源的AI智能代理,让用户能够跟数据对话,实现从文本到SQL的转换,还能生成图表、电子表格、报告以及商业智能分析。它支持多种语言,能深入挖掘数据价值,提供智能数据探索功能,通过语义索引和精心设计的界面,让用户无需写代码即可获取洞察。Wren AI采用独特的架构,包含Wren UI、Wren AI Service和Wren Engine三大核心服务,可部署在本地或云端,助力团队高效、安全地解锁数据潜力。

AI_Charlotte的博客 4498

如何通过PHP接入DeepSeek的API

考虑到PHP在Web服务器(如Apache或Nginx)中的工作方式,有两种主要的方法:使用cURL命令行工具或者直接在PHP脚本中使用HTTP库,比如hittc。用户可能更习惯于命令行,所以我先介绍cURL的方法。接下来,如果用户希望更高级的功能,比如批量处理或自动回复,可以建议他们使用hittc库,这样代码会更模块化和易于维护。同时,提醒他们在生产环境中使用正确的配置,如HTTPS、SSL验证等,确保安全性。最后,要提供完整的示例代码,并解释每一步的作用,帮助用户理解如何将这些代码集成到他们的网站中。

tiger_web0的博客 4123

告别Keil手动分区!用CubeMX+VS Code一键生成带Bootloader的STM32 OTA工程

本文详细介绍了如何利用STM32CubeMX和VS Code实现STM32 OTA工程的自动化构建,告别传统Keil手动分区的繁琐流程。通过图形化配置Flash分区、自动生成链接脚本以及实现Bootloader跳转逻辑,开发者可以高效完成远程升级功能开发,显著提升嵌入式开发效率。

weixin_33720956的博客 389

Cocos Creator使用http请求DeepSeek API 对话接口

借助DeepSeek API接口,在Cocos Creator中请求对话

鹤九日的博客 2391

SAP FICO 资产会计AA后台配置 (上)

输入折旧表“CZ11”如有外币计价的资产,则需指定外币计价的资产折旧范围,以及规则。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。因为在设置资产类型时,需指定一个对应的 资产编号范围、资产账户确定类型(便于分配自动会计科目)、屏幕格式规则(便于设置资产字段必填与否)。新增资产类型:Z101 固定资产-房屋及建筑物新增资产类型:Z301 固定资产-房屋及建筑物。

ghgxm520的博客 1762

Plaxis软件简介及 Plaxis Python API环境搭建、自动化建模、Python全自动实现、高级案例分析

本次课程主要针对岩土工程中的各种问题(塑性、渗流、固结、动力、稳定安全、热力TM),用四天时间,教大家如何一步一步地搭建自己的Plaxis模型,包括Plaxis Python API的连接与配置、外部Python编译器的使用、Python命令流自动建模过程、Python远程脚本读取输出结果等,其中的Python建模模块尽可能做到让学员零基础开始,通过提供标准命令流库,使用搭积木、摆乐高的形式模块化进行,加强学员的易上手、可操作性。(2)钻孔的建立、土层的建立、土层属性、水力条件及初始条件、导入土层。

CCfz566的博客 1463

JienDa聊PHP:PHP 调用 DeepSeek API 完整指南:从入门到实战应用

本文介绍了使用PHP调用DeepSeek API的完整指南,涵盖从基础配置到实战应用的全流程。主要内容包括:DeepSeek API的功能特性与版本介绍、PHP环境准备与SDK安装、基础API调用类的实现(支持Guzzle和原生cURL两种方式)、错误处理机制以及性能优化策略。文章还提供了配置管理类示例代码,帮助开发者快速集成DeepSeek的强大AI能力到PHP应用中,适用于文本生成、代码补全等多种场景。

Jien Da官方博客 1287

干法刻蚀工艺进阶:如何通过调节DC自偏压优化刻蚀速率和各向异性

本文深入探讨了干法刻蚀工艺中DC自偏压的精细调控艺术。DC自偏压是影响刻蚀速率和各向异性的关键因素,文章通过实战案例,详细分析了如何通过调节射频功率、频率、腔室压力及气体成分等参数,间接而有效地控制DC自偏压,从而优化高深宽比硅沟槽等复杂结构的刻蚀效果,实现工艺性能的精准提升。

weixin_28308325的博客 333

DeepSeek API

DeepSeek API

duke_ding2的博客 3096

数据分享|2023年OSM道路数据(全国,分省,分市)

首先这个工作非常有必要的,因为我们正常使用的道路的分类都是基于包括城市快速路、城市主干路、城市次干路这个体系的,大家对于这个分类体系应该更熟悉,但是OSM地图的道路分类又不是完全按这个来的,所以非常有必要重新分类;搞清楚道路类型是我们使用道路数据做很多工作的基础,比如我们在使用道路数据的时候,经常需要预估道路的行车速度,而这个速度一般就是根据道路类型来的,比如高架路的车速肯定就比城市支路快很多!下载分为两种情况,第一种是下载小区域的数据,比如下载一个街区的数据,第二种为下载整个中国范围的。

JData_Engineer的博客 4306

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

通过PHP接入DeepSeek API的两种方法

想知道如何通过PHP接入DeepSeek的API。看起来他对之前的Python步骤比较熟悉,但这次想用PHP实现。首先,我需要回顾一下DeepSeek API的文档,确认它支持哪些方法和参数。假设用户已经配置了环境变量,比如API密钥,接下来要教他在PHP中调用RESTful API。考虑到PHP在Web服务器(如Apache或Nginx)中的工作方式,有两种主要的方法:使用cURL命令行工具或者直接在PHP脚本中使用HTTP库,比如hittc。用户可能更习惯于命令行,所以我先介绍cURL的方法。

tomatop的博客 340

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

deepseek-php-client开源程序是强力维护的 PHP API 客户端,允许您与 deepseek API 交互

deepseek-php-client开源程序是强力维护的 PHP API 客户端,允许您与 deepseek API 交互。

struggle2025的博客 1075

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

deepseek聊天达到最大对话上限怎么办

本文探讨了解决DeepSeek对话长度限制的三种方案:1)官网网页版虽免费但存在对话记忆丢失问题,可手动总结关键信息续聊;2)本地部署无限制但成本高、模型版本滞后;3)API调用方案费用低、可自定义参数,通过本地或服务器搭建实现持续对话。作者详细分析了各方案优缺点,并提供了PHP调用示例,建议用户根据预算、技术能力和隐私需求选择合适方案,同时开放技术支持和合作渠道。

小板的博客 1万+

PHP语言接入DeepSeek R1满血版智能体大模型DEMO,PHP如何接入DeekSeek R1满血版智能体大模型,教程,详细版,对接接口,附带演示示例DEMO和完整源代码。(源代码有详细注解)

PHP语言接入DeepSeek R1满血版智能体大模型DEMO,PHP如何接入DeekSeek R1满血版智能体大模型,教程,详细版,对接接口,附带演示示例DEMO和完整源代码。(源代码有详细注解)

我的ID:sumer-work(全网同名)昵称:程序员SUMER(全网同名) 1571

使用PHP 调用Deepseek API

本文将介绍如何通过 PHP 调用 Deepseek API,并通过简易代码展示如何与 Deepseek 的 AI 模型进行交互,帮助开发者更好地在自己的项目中应用这一强大的工具。我们将提供一个基本的 PHP 示例,帮助你快速了解如何通过 Deepseek API 进行调用。

TinaYuNuo的博客 1831

PHP调用DeepSeek API的完整指南

PHP 版本的 DeepSeek API 实现采用面向对象方式,代码结构清晰,易于维护和扩展。通过 cURL 实现流式处理,提供了良好的交互体验。

2509_93923260的博客 343

PHP语言如何使用DeepSeek,PHP调用DeepSeek指南

PHP 版本的 DeepSeek API 实现采用面向对象方式,代码结构清晰,易于维护和扩展。通过 cURL 实现流式处理,提供了良好的交互体验。部分内容和图片引用deepseekg官方网站

u013486597的博客 2848

PHP博客系统ModStart如何接入DeepSeek教程(附带源代码下载地址、安装说明)

ModStart接入DeepSeek的两种方法:API调用和本地部署。同时,注意结果中的时间,最新的信息是2025年4月,现在用户的时间是2025年4月,可能需要确认是否有更新,但结果中没有提供更新的内容,所以按现有信息回答。

我的ID:sumer-work(全网同名)昵称:程序员SUMER(全网同名) 769
上一篇: 微信小程序使用wx.chooseImage上传图片时进行压缩,并添加时间水印
bilichen006
博客等级 码龄12年 93粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值