llm.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 dify_plugin import OAICompatLargeLanguageModel
  6. class DeepseekLargeLanguageModel(OAICompatLargeLanguageModel):
  7. def _invoke(
  8. self,
  9. model: str,
  10. credentials: dict,
  11. prompt_messages: list[PromptMessage],
  12. model_parameters: dict,
  13. tools: Optional[list[PromptMessageTool]] = None,
  14. stop: Optional[list[str]] = None,
  15. stream: bool = True,
  16. user: Optional[str] = None,
  17. ) -> Union[LLMResult, Generator]:
  18. self._add_custom_parameters(credentials)
  19. model="Qwen3-32B-H800"
  20. return super()._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream)
  21. # def validate_credentials(self, model: str, credentials: dict) -> None:
  22. # self._add_custom_parameters(credentials)
  23. # super().validate_credentials(model, credentials)
  24. @staticmethod
  25. def _add_custom_parameters(credentials) -> None:
  26. # credentials["endpoint_url"] = str("http://10.132.200.185:30012/gateway/ti/v1/")
  27. credentials["endpoint_url"] = str("http://10.132.200.185:30012/gateway/ti/qwen3-32b-h800/v1/chat/completions")
  28. credentials["mode"] = LLMMode.CHAT.value
  29. credentials["function_calling_type"] = "tool_call"
  30. credentials["stream_function_calling"] = "support"
  31. credentials["extra_headers"] = {
  32. "Content-type": "application/json",
  33. "szc-api-key": "f4eb2eb55b4f4a17a5"
  34. }