mmnijas/deepseek 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mmnijas/deepseek

Composer 安装命令:

composer require mmnijas/deepseek

包简介

A Laravel package for seamless integration with DeepSeek AI services, enabling efficient and scalable AI-powered functionalities such as natural language processing, data analysis, and automation through a simple and intuitive API wrapper.

README 文档

README

Latest Version License Total Downloads Monthly Downloads Daily Downloads

A seamless integration package for DeepSeek API in Laravel applications. Easily interact with DeepSeek's AI capabilities through an expressive Laravel-friendly interface.

Features

  • 🚀 Simple facade-based API
  • ⚡️ Guzzle HTTP client integration
  • 🔧 Configurable through environment variables
  • 📦 Out-of-the-box service provider
  • 💬 Support for chat completions
  • 🛠 Extensible architecture

Requirements

  • PHP 8.0 or higher
  • Laravel 9.x or 10.x
  • GuzzleHTTP 7.x

Installation

  1. Install via Composer:
composer require mmnijas/deepseek
  1. Add your DeepSeek API key to .env:
DEEPSEEK_API_KEY=your-api-key-here
  1. (Optional) Publish config file:
php artisan vendor:publish --tag=deepseek-config

Configuration

After publishing the config file (config/deepseek.php), you can customize:

return [
    'api_key' => env('DEEPSEEK_API_KEY'),    // Your API key
    'base_uri' => 'https://api.deepseek.com/v1', // API endpoint
    'model' => 'deepseek-chat',              // Default model
    'timeout' => 30,                         // Request timeout in seconds
];

Basic Usage

1. Using the Facade

use Mmnijas\DeepSeek\Facades\DeepSeek;

$response = DeepSeek::chat([
    ['role' => 'user', 'content' => 'Hello, DeepSeek!']
]);

// Get the assistant's reply
echo $response['choices'][0]['message']['content'];

2. In a Controller

use Mmnijas\DeepSeek\Facades\DeepSeek;
use Illuminate\Http\Request;

class ChatController extends Controller
{
    public function handle(Request $request)
    {
        $messages = [
            ['role' => 'user', 'content' => $request->input('message')]
        ];

        $response = DeepSeek::chat($messages);

        return response()->json([
            'reply' => $response['choices'][0]['message']['content']
        ]);
    }
}

3. Blade View Example

<form action="/chat" method="POST">
    @csrf
    <input type="text" name="message" required>
    <button type="submit">Ask DeepSeek</button>
</form>

@isset($response)
<div class="response">
    {{ $response['choices'][0]['message']['content'] }}
</div>
@endisset

4. Artisan Command

Create a command:

php artisan make:command AskDeepSeek

Implement:

use Mmnijas\DeepSeek\Facades\DeepSeek;

class AskDeepSeek extends Command
{
    protected $signature = 'ask:deepseek {question}';

    public function handle()
    {
        $response = DeepSeek::chat([
            ['role' => 'user', 'content' => $this->argument('question')]
        ]);

        $this->info($response['choices'][0]['message']['content']);
    }
}

Usage:

php artisan ask:deepseek "What is Laravel?"

Advanced Usage

Custom Parameters

$response = DeepSeek::chat(
    messages: [
        ['role' => 'user', 'content' => 'Explain quantum computing in simple terms']
    ],
    params: [
        'temperature' => 0.7,
        'max_tokens' => 500,
        'top_p' => 1.0,
    ]
);

Multiple Messages

$messages = [
    ['role' => 'system', 'content' => 'You are a helpful assistant'],
    ['role' => 'user', 'content' => 'Who won the world series in 2020?'],
    ['role' => 'assistant', 'content' => 'The Los Angeles Dodgers won the World Series in 2020.'],
    ['role' => 'user', 'content' => 'Where was it played?']
];

$response = DeepSeek::chat($messages);

Error Handling

try {
    $response = DeepSeek::chat([...]);
} catch (\Exception $e) {
    // Handle API errors
    logger()->error('DeepSeek API Error: ' . $e->getMessage());
    return response()->json(['error' => 'Service unavailable'], 503);
}

Rate Limiting

The DeepSeek API has rate limits. Implement Laravel's rate limiter in AppServiceProvider:

use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;

RateLimiter::for('deepseek', function ($job) {
    return Limit::perMinute(60); // Adjust based on your API plan
});

Testing

Add to your test case:

public function test_deepseek_integration()
{
    Http::fake([
        'api.deepseek.com/v1/chat/completions' => Http::response([
            'choices' => [
                ['message' => ['content' => 'Mocked response']]
            ]
        ], 200)
    ]);

    $response = DeepSeek::chat([
        ['role' => 'user', 'content' => 'Test message']
    ]);

    $this->assertEquals('Mocked response', $response['choices'][0]['message']['content']);
}

Security

Always:

  • 🔑 Keep your API key secret
  • 🛡 Validate user input
  • ⏱ Implement rate limiting
  • 📝 Follow DeepSeek's API guidelines

Common Issues

Missing API Key

Error: "DeepSeek API key not configured"
Solution: Verify .env contains DEEPSEEK_API_KEY

Network Errors

Error: "Could not connect to DeepSeek API"
Solution:

  1. Check internet connection
  2. Verify API endpoint in config
  3. Review firewall settings

Invalid Response Format

Error: "Undefined index choices"
Solution:

// Check for successful response first
if (isset($response['choices'])) {
    // Process response
}

Changelog

See CHANGELOG.md for recent changes.

License

The MIT License (MIT). See LICENSE.md for details.

Contributing

Pull requests are welcome! Please follow PSR coding standards and include tests.

📧 Support: hello@mmnijas.in 🌐 Documentation: https://mmnijas.in/blog/a-comprehensive-guide-to-the-deepseek-laravel-package

mmnijas/deepseek 适用场景与选型建议

mmnijas/deepseek 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「client」 「sdk」 「nlp」 「ai」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mmnijas/deepseek 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mmnijas/deepseek 我们能提供哪些服务?
定制开发 / 二次开发

基于 mmnijas/deepseek 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 35
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-02