MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / DashScopeEmbedder

Class DashScopeEmbedder

api/dashscope_client.py:651–733  ·  view source on GitHub ↗

r""" A user-facing component that orchestrates an embedder model via the DashScope model client and output processors. Args: model_client (ModelClient): The DashScope model client to use for the embedder. model_kwargs (Dict[str, Any], optional): The model kwargs to pass to t

Source from the content-addressed store, hash-verified

649
650
651class DashScopeEmbedder(DataComponent):
652 r"""
653 A user-facing component that orchestrates an embedder model via the DashScope model client and output processors.
654
655 Args:
656 model_client (ModelClient): The DashScope model client to use for the embedder.
657 model_kwargs (Dict[str, Any], optional): The model kwargs to pass to the model client. Defaults to {}.
658 output_processors (Optional[Component], optional): The output processors after model call. Defaults to None.
659 """
660
661 model_type: ModelType = ModelType.EMBEDDER
662 model_client: ModelClient
663 output_processors: Optional[DataComponent]
664
665 def __init__(
666 self,
667 *,
668 model_client: ModelClient,
669 model_kwargs: Dict[str, Any] = {},
670 output_processors: Optional[DataComponent] = None,
671 ) -> None:
672
673 super().__init__(model_kwargs=model_kwargs)
674 if not isinstance(model_kwargs, Dict):
675 raise TypeError(
676 f"{type(self).__name__} requires a dictionary for model_kwargs, not a string"
677 )
678 self.model_kwargs = model_kwargs.copy()
679
680 if not isinstance(model_client, ModelClient):
681 raise TypeError(
682 f"{type(self).__name__} requires a ModelClient instance for model_client."
683 )
684 self.model_client = model_client
685 self.output_processors = output_processors
686
687 def call(
688 self,
689 input: EmbedderInputType,
690 model_kwargs: Optional[Dict] = {},
691 ) -> EmbedderOutputType:
692 log.debug(f"Calling {self.__class__.__name__} with input: {input}")
693 api_kwargs = self.model_client.convert_inputs_to_api_kwargs(
694 input=input,
695 model_kwargs=self._compose_model_kwargs(**model_kwargs),
696 model_type=self.model_type,
697 )
698 try:
699 output = self.model_client.call(
700 api_kwargs=api_kwargs, model_type=self.model_type
701 )
702 except Exception as e:
703 log.error(f"🤡 Error calling the DashScope model: {e}")
704 output = EmbedderOutput(error=str(e))
705 return output
706
707 async def acall(
708 self,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected