llm.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from collections.abc import Generator
  2. from typing import Optional, Union
  3. from dify_plugin.entities.model.llm import LLMMode, LLMResult
  4. from dify_plugin.entities.model.message import PromptMessage, PromptMessageTool
  5. from yarl import URL
  6. from dify_plugin import OAICompatLargeLanguageModel
  7. class DeepseekLargeLanguageModel(OAICompatLargeLanguageModel):
  8. def _invoke(
  9. self,
  10. model: str,
  11. credentials: dict,
  12. prompt_messages: list[PromptMessage],
  13. model_parameters: dict,
  14. tools: Optional[list[PromptMessageTool]] = None,
  15. stop: Optional[list[str]] = None,
  16. stream: bool = True,
  17. user: Optional[str] = None,
  18. ) -> Union[LLMResult, Generator]:
  19. self._add_custom_parameters(credentials)
  20. model="model"
  21. return super()._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream)
  22. # def validate_credentials(self, model: str, credentials: dict) -> None:
  23. # self._add_custom_parameters(credentials)
  24. # super().validate_credentials(model, credentials)
  25. @staticmethod
  26. def _add_custom_parameters(credentials) -> None:
  27. # credentials["endpoint_url"] = str("http://10.132.200.185:30012/gateway/ti/v1/")
  28. credentials["endpoint_url"] = str("http://10.132.200.185:30012/gateway/ti/ds-v3/v1/")
  29. credentials["mode"] = LLMMode.CHAT.value
  30. credentials["function_calling_type"] = "tool_call"
  31. credentials["stream_function_calling"] = "support"
  32. credentials["extra_headers"] = {
  33. "Content-type": "application/json",
  34. "X-TC-Project": "744701358",
  35. # "X-TC-Project": "1",
  36. # "X-TC-Service": "deepseek-r1-h800-master-sglang",
  37. "X-TC-Service": "deepseek-v3-0324-w8a8-master",
  38. "X-TC-Action": "/v1/chat/completions",
  39. "X-TC-Version": "2020-10-01",
  40. "szc-api-key": "f4eb2eb55b4f4a17a5"
  41. }