llm.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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="Qwen3-32B-H800"
  21. model_parameters["chat_template_kwargs"] = {"enable_thinking": False}
  22. return super()._invoke(model, credentials, prompt_messages, model_parameters, tools, stop, stream)
  23. @staticmethod
  24. def _add_custom_parameters(credentials) -> None:
  25. credentials["endpoint_url"] = str("http://10.132.200.185:30012/gateway/ti/qwen3-32b-h800/v1/")
  26. credentials["mode"] = LLMMode.CHAT.value
  27. credentials["function_calling_type"] = "tool_call"
  28. credentials["stream_function_calling"] = "support"
  29. credentials["extra_headers"] = {
  30. "Content-type": "application/json",
  31. "szc-api-key": "f4eb2eb55b4f4a17a5"
  32. }