utkarsharma2 commented on code in PR #34921: URL: https://github.com/apache/airflow/pull/34921#discussion_r1371890752
########## airflow/providers/cohere/operators/embedding.py: ########## @@ -0,0 +1,82 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from __future__ import annotations + +from functools import cached_property +from typing import TYPE_CHECKING, Any, Callable, Collection, Mapping + +from airflow.exceptions import AirflowException +from airflow.models import BaseOperator +from airflow.providers.cohere.hooks.cohere import CohereHook + +if TYPE_CHECKING: + from airflow.utils.context import Context + + +class CohereEmbeddingOperator(BaseOperator): + """ + Creates the embedding base by interacting with Cohere's hosted services. + + :param conn_id: Optional. The name of the Airflow connection to get connection + information for Cohere. Defaults to "cohere_default". + :param input_text: list of text items that need to be embedded. Only one of input_text or input_callable + should be provided. + :param input_callable: The callable that provides the input texts to generate embeddings for. + Only one of input_text or input_callable should be provided. + :param input_callable_args: The list of arguments to be passed to ``input_callable`` + :param input_callable_kwargs: The kwargs to be passed to ``input_callable`` + """ + + def __init__( + self, + input_text: list[str] | None = None, + input_callable: Callable[[Any], list[str]] | None = None, + input_callable_args: Collection[Any] | None = None, + input_callable_kwargs: Mapping[str, Any] | None = None, + conn_id: str = CohereHook.default_conn_name, + **kwargs: Any, + ): + super().__init__(**kwargs) + self.conn_id = conn_id + self.input_text = input_text + self.input_callable = input_callable + self.input_callable_args = input_callable_args or () + self.input_callable_kwargs = input_callable_kwargs or {} + self.text_to_embed = self._get_text_to_embed() Review Comment: @mpgreg I have updated the [example](https://github.com/apache/airflow/pull/34921/files#diff-3b2baa9db6a75c8be9dffd568b249ceaeb33e2028bfd3a327ba58ce4048f000b) which can work in a similar manner, but with a separate task. Please let me know if this works or if we still need a designated decorator for the same. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org