|
20 | 20 | from functools import cached_property |
21 | 21 | from typing import TYPE_CHECKING, Any, Sequence |
22 | 22 |
|
23 | | -from airflow.exceptions import AirflowException |
24 | 23 | from airflow.models import BaseOperator |
25 | 24 | from airflow.providers.openai.hooks.openai import OpenAIHook |
26 | 25 |
|
@@ -60,18 +59,18 @@ def __init__( |
60 | 59 | self.input_text = input_text |
61 | 60 | self.model = model |
62 | 61 | self.embedding_kwargs = embedding_kwargs or {} |
| 62 | + if not self.input_text or not isinstance(self.input_text, (str, list)): |
| 63 | + raise ValueError( |
| 64 | + "The 'input_text' must be a non-empty string, list of strings, list of integers, or list of lists of integers." |
| 65 | + ) |
63 | 66 |
|
64 | 67 | @cached_property |
65 | 68 | def hook(self) -> OpenAIHook: |
66 | 69 | """Return an instance of the OpenAIHook.""" |
67 | 70 | return OpenAIHook(conn_id=self.conn_id) |
68 | 71 |
|
69 | 72 | def execute(self, context: Context) -> list[float]: |
70 | | - if not self.input_text or not isinstance(self.input_text, (str, list)): |
71 | | - raise AirflowException( |
72 | | - "The 'input_text' must be a non-empty string, list of strings, list of integers, or list of lists of integers." |
73 | | - ) |
74 | 73 | self.log.info("Generating embeddings for the input text of length: %d", len(self.input_text)) |
75 | 74 | embeddings = self.hook.create_embeddings(self.input_text, model=self.model, **self.embedding_kwargs) |
76 | | - self.log.info("Generated embeddings: %s", embeddings) |
| 75 | + self.log.info("Generated embeddings for %d items", len(embeddings)) |
77 | 76 | return embeddings |
0 commit comments