ict.shenzhi/Assets/deepseek
he 99e9cf325a 6/25 2025-06-25 08:37:25 +08:00
..
Documentation~ 1 6/25 2025-06-25 08:37:25 +08:00
Editor 6/25 2025-06-25 08:37:25 +08:00
Runtime 6/25 2025-06-25 08:37:25 +08:00
Samples~ 1 6/25 2025-06-25 08:37:25 +08:00
CHANGELOG.md 6/25 2025-06-25 08:37:25 +08:00
CHANGELOG.md.meta 6/25 2025-06-25 08:37:25 +08:00
Documentation~ 1.meta 6/25 2025-06-25 08:37:25 +08:00
Editor.meta 6/25 2025-06-25 08:37:25 +08:00
LICENSE 6/25 2025-06-25 08:37:25 +08:00
LICENSE.meta 6/25 2025-06-25 08:37:25 +08:00
README.md 6/25 2025-06-25 08:37:25 +08:00
README.md.meta 6/25 2025-06-25 08:37:25 +08:00
Runtime.meta 6/25 2025-06-25 08:37:25 +08:00
Samples~ 1.meta 6/25 2025-06-25 08:37:25 +08:00
package.json 6/25 2025-06-25 08:37:25 +08:00
package.json.meta 6/25 2025-06-25 08:37:25 +08:00

README.md

Unity 2020.3+ UPM Compatible License: MIT Sponsor Last Commit Code Size
Maintenance GitHub stars GitHub forks GitHub issues Windows WebGL Android

🐳 DeepSeek API for Unity

💬 A clean, modular Unity integration for DeepSeek's powerful LLMs — chat, reasoning, and task automation made easy.

⚠️ Note: This is an unofficial integration not affiliated with or endorsed by DeepSeek.


Features

  • Clean, reusable SDK for DeepSeek API
  • 🔄 Supports true SSE-based streaming and non-streaming chat completions
  • 🧠 Compatible with multiple models (DeepSeek Chat, Reasoner)
  • 🎨 Modular & customizable UI chat component
  • 🔐 Secure API key storage (runtime-safe)
  • ⚙️ Built with Unity Package Manager (UPM)
  • 🧪 Includes sample scene & prefabs

🧩 Supported Platforms & Unity Versions

Platform Unity 2020.3 Unity 2021 Unity 2022 Unity 6 Notes
Windows Fully supported (tested with IL2CPP & Mono)
Android Requires internet permission in manifest
WebGL ⚠️ Partial ⚠️ Partial Streaming unsupported; add CORS headers on server
Linux Likely works, but not yet tested
macOS Not tested, expected to work
iOS Not tested, expected to work (HTTPS required)
Consoles Not supported (Unity license + network limitations)

= Not tested yet — expected to work but needs verification

⚠️ = Partial support (some limitations)


🧰 Requirements

  • Unity 2020.3 LTS or newer
  • TextMeshPro (via Package Manager)
  • DeepSeek API Key from platform.deepseek.com

📦 Installation

Option 1: Via Git URL (Unity Package Manager)

  1. Open your Unity project

  2. Go to Window > Package Manager

  3. Click +Add package from Git URL

  4. Paste:

    https://github.com/yagizeraslan/DeepSeek-Unity.git
    
    
  5. Done


🚀 Getting Started

🔧 Setup

  1. After installation, download Sample scene from Package Manager
  2. Paste your API key into the DeepSeekSettings.asset.
  3. Hit Play — and chat with DeepSeek AI in seconds 💬

🧪 Sample Scene

To test everything:

  1. In Package Manager, under DeepSeek API for Unity, click Samples

  2. Click Import on DeepSeek Chat Example

  3. Open:

    Assets/Samples/DeepSeek API for Unity/1.0.1/DeepSeek Chat Example/Scenes/DeepSeek-Chat.unity
    
    
  4. Press Play — you're live.

  • You can change model type and streaming mode during play — the SDK picks up changes automatically for each new message.
  • You can also press Enter instead of clicking Send button — handy for fast testing.

🔐 API Key Handling

  • During dev: Store key via EditorPrefs using the DeepSeek Editor Window
  • In production builds: Use the DeepSeekSettings ScriptableObject (recommended)

DO NOT hardcode your key in scripts or prefabs — Unity will reject the package.


🧱 Architecture Overview

Layer Folder Role
API Logic Runtime/API/ HTTP & model logic
Data Models Runtime/Data/ DTOs for requests/responses
UI Component Runtime/UI/ MonoBehaviour & Controller
Config Logic Runtime/Common/ Secure key storage
Editor Tools Editor/ Editor-only settings UI
Example Scene Samples~/ Demo prefab, scene, assets

🧩 Example Integration

🕐 Non-Streaming (Full Response)

[SerializeField] private DeepSeekSettings config;

private async void Start()
{
    var api = new DeepSeekApi(config);
    var request = new ChatCompletionRequest
    {
        model = DeepSeekModel.DeepSeek_V3.ToModelString(),
        messages = new ChatMessage[]
        {
            new ChatMessage { role = "system", content = "You're a helpful assistant." },
            new ChatMessage { role = "user", content = "Tell me something cool." }
        }
    };

    var response = await api.CreateChatCompletion(request);
    Debug.Log("[FULL RESPONSE] " + response.choices[0].message.content);
}

🔄 Streaming (Real-Time Updates)

[SerializeField] private DeepSeekSettings config;

private void Start()
{
    RunStreamingExample();
}

private void RunStreamingExample()
{
    var request = new ChatCompletionRequest
    {
        model = DeepSeekModel.DeepSeek_V3.ToModelString(),
        messages = new ChatMessage[]
        {
            new ChatMessage { role = "user", content = "Stream a fun fact about the ocean." }
        },
        stream = true
    };

    var streamingApi = new DeepSeekStreamingApi();
    streamingApi.CreateChatCompletionStream(
        request,
        config.apiKey,
        partial =>
        {
            Debug.Log("[STREAMING] " + partial); // Called for each streamed segment
        }
    );
}


🛠 Advanced Usage

🔄 Streaming Support

DeepSeek-Unity supports real-time streaming using DeepSeek's official stream: true Server-Sent Events (SSE) endpoint.

Uses Unity's DownloadHandlerScript for chunked response handling
UI updates per-token (no simulated typewriter effect)
No coroutines, no external libraries — works natively in Unity

To enable:

  • Check Use Streaming in the chat prefab or component
  • Partial responses will automatically stream into the UI

📌 You can toggle streaming on/off at runtime.

💬 Multiple Models

DeepSeekModel.DeepSeek_V3
DeepSeekModel.DeepSeek_R1


🐞 Troubleshooting

Can't add component?

→ Make sure you dragged DeepSeekSettings.asset into the DeepSeekChat.cs's Config field.

Streaming not working?

→ Make sure you're on a platform that supports DownloadHandlerScript (Standalone or Editor).
→ WebGL and iOS may have platform limitations for live SSE streams.

Seeing JSON parse warnings in streaming mode?

→ These are normal during SSE — they occur when the parser receives partial chunks. They're automatically skipped and won't affect the final output.


💖 Support This Project

If you find DeepSeek-Unity useful, please consider supporting its development!

Your support helps me continue maintaining and improving this project. Thank you! 🚀


📄 License

Unofficial integration. DeepSeek™ is a trademark of Hangzhou DeepSeek Artificial Intelligence Co., Ltd.

This project is licensed under the MIT License.


🤝 Contact & Support

Author: Yağız ERASLAN

📬 yagizeraslan@gmail.com

💬 GitHub Issues welcome!