🐘✨ DeepSeek PHP Community ✨🐘
May 21, 2026 · View on GitHub
DeepSeek PHP 客户端
🚀 由社区驱动的 PHP SDK,用于集成 DeepSeek AI API
目录
✨ 特性
- 无缝 API 集成: DeepSeek AI 功能的 PHP 优先接口
- 构建器模式: 直观的链接请求构建方法
- 企业级别: 符合 PSR-18 规范
- 模型灵活性: 支持多种 DeepSeek 模型(Coder、Chat 等)
- 流式传输: 内置对实时响应处理的支持
- 框架友好: 提供 Laravel 和 Symfony 包
📦 安装
通过 Composer 安装:
composer require deepseek-php/deepseek-php-client
要求:
- PHP 8.1+
🚀 快速入门
基本用法
只需两行代码即可开始:
use DeepSeek\DeepSeekClient;
$response = DeepSeekClient::build('your-api-key')
->query('Explain quantum computing in simple terms')
->run();
echo $response;
📌 默认配置:
- Model:
deepseek-chat - Temperature: 0.8
Advanced Configuration
use DeepSeek\DeepSeekClient;
use DeepSeek\Enums\Models;
$client = DeepSeekClient::build(apiKey:'your-api-key', baseUrl:'https://api.deepseek.com/v3', timeout:30, clientType:'guzzle');
$response = $client
->withModel(Models::CODER->value)
->withStream()
->withTemperature(1.2)
->setMaxTokens(8192)
->setResponseFormat('text')
->query('Explain quantum computing in simple terms')
->run();
echo 'API Response:'.$response;
⚠️ DeepSeek JSON 模式使用要求
当使用:
->setResponseFormat('json_object')
你的提示语(prompt)必须包含 "json" 这个词,否则 API 会返回以下错误:
"Prompt must contain the word 'json' in some form to use 'response_format' of type 'json_object'"
🚫 错误示例
->setResponseFormat('json_object')
->query('用简单的语言解释量子计算')
✅ 正确示例
->setResponseFormat('json_object')
->query('请以有效的 JSON 格式回答,并用简单语言解释量子计算。')
✅ 建议:为了获得更好的结果,最好也在提示中提供一个 JSON 示例,并强调 “只返回 JSON”。
Use with Symfony HttpClient
the package already built with symfony Http client, if you need to use package with symfony Http Client , it is easy to achieve that, just pass clientType:'symfony' with build function.
ex with symfony:
// with defaults baseUrl and timeout
$client = DeepSeekClient::build('your-api-key', clientType:'symfony')
// with customization
$client = DeepSeekClient::build(apiKey:'your-api-key', baseUrl:'https://api.deepseek.com/v3', timeout:30, clientType:'symfony');
$client->query('Explain quantum computing in simple terms')
->run();
获取模型列表
use DeepSeek\DeepSeekClient;
$response = DeepSeekClient::build('your-api-key')
->getModelsList()
->run();
echo $response; // {"object":"list","data":[{"id":"deepseek-chat","object":"model","owned_by":"deepseek"},{"id":"deepseek-reasoner","object":"model","owned_by":"deepseek"}]}
函数调用
函数调用允许模型调用外部工具以增强其功能。 你可以在文档中查看有关函数调用的详细信息: FUNCTION-CALLING.md
🛠 框架集成
Laravel Deepseek Package
🐘✨ DeepSeek PHP Community ✨🐘
Click the button bellow or join here to be part of our growing community!
Channel Structure 🏗️
- 🗨️ General - Daily chatter
- 💡 Ideas & Suggestions - Shape the community's future
- 📢 Announcements & News - Official updates & news
- 🚀 Releases & Updates - Version tracking & migration support
- 🐞 Issues & Bug Reports - Collective problem-solving
- 🤝 Pull Requests - Code collaboration & reviews
🚧 迁移指南
从 v1.x 升级?请查看我们全面的 迁移指南 了解重大变更和升级说明。
📝 更新日志
详细的发布说明可在 CHANGELOG.md 查看。
🧪 测试
./vendor/bin/pest
测试覆盖范围涵盖 v2.1。
🔒 安全
报告漏洞: omaralwi2010@gmail.com
📄 许可
基于 MIT License 开源协议。