1"""

2 DeepSeek Provider — 基于 OpenAIProvider 子类化，仅换 base_url。

3 DeepSeek API 完全兼容 OpenAI Chat Completions 格式。

4 v1.3.36: 首个实现，支持 Function Calling。

5"""

6

7 from __future__ import annotations

8

9 from typing import Any

10

11 from agentos.llm.base import CompletionResult

12 from agentos.llm.openai_provider import OpenAIProvider

13

14__all__ = ["DeepSeekProvider"]

15

16# USD per 1M tokens (DeepSeek pricing as of 2025-06)

17_DEEPSEEK_PRICING: dict[str, tuple[float, float]] = {

18 "deepseek-chat": (0.27, 1.10),

19 "deepseek-reasoner": (0.55, 2.19),

20}

21

22

23 class DeepSeekProvider(OpenAIProvider):

24 """DeepSeek Provider — OpenAI 兼容，零额外代码。

25

26 用法:

27 provider = DeepSeekProvider(api_key="sk-...")

28 result = provider.chat([Message(role=MessageRole.USER, content="Hello")])

29 """

30

31 _pricing_injected: bool = False

32

33 def __init__(

34 self,

35 model: str = "deepseek-chat",

36 api_key: str = "",

37 base_url: str = "https://api.deepseek.com/v1",

38 timeout: float = 120.0,

39 ):

40 super().__init__(model=model, api_key=api_key, base_url=base_url, timeout=timeout)

41 if not self._pricing_injected:

42 from agentos.llm.openai_provider import _PRICING

43 _PRICING.update(_DEEPSEEK_PRICING)

44 DeepSeekProvider._pricing_injected = True

45

46 @property

47 def provider_name(self) -> str:

48 return "deepseek"