gopidesupavan commented on code in PR #61794:
URL: https://github.com/apache/airflow/pull/61794#discussion_r2814382261


##########
providers/common/ai/src/airflow/providers/common/ai/operators/llm_sql.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 typing import TYPE_CHECKING
+
+from pydantic import BaseModel
+
+from airflow.providers.common.ai.operators.base_llm import BaseLLMOperator
+
+if TYPE_CHECKING:
+    from pydantic_ai.agent import AgentRunResult
+
+    from airflow.providers.common.ai.configs.datasource import DataSourceConfig
+
+
+class SQLQueryResponseOutputType(BaseModel):
+    """Output type LLM Sql query generate."""
+
+    sql_query_prompt_dict: dict[str, str]
+
+
+class LLMSQLQueryOperator(BaseLLMOperator):
+    """Operator to generate SQL queries based on prompts for multiple 
datasources."""
+
+    def __init__(
+        self, datasource_configs: list[DataSourceConfig], provider_model: str 
| None = None, **kwargs
+    ):
+        super().__init__(datasource_configs=datasource_configs, **kwargs)
+        self.provider_model = provider_model
+
+    def execute(self, context):
+        """Execute LLM Sql query operator."""
+        return super().execute(context)
+
+    @property
+    def get_output_type(self):
+        """Output type for LLM Sql query generates."""
+        return SQLQueryResponseOutputType
+
+    @property
+    def get_instruction(self):
+        """Instruction for LLM Agent."""
+        db_names = []
+        for config in self.datasource_configs:
+            if config.db_name is None:
+                config.db_name = config.uri.split("://")[1]
+            db_names.append(config.db_name)
+        unique_db_names = set(db_names)
+        db_name_str = ", ".join(unique_db_names)
+
+        if self.instruction is None:
+            self.instruction = (
+                f"You are a SQL expert integrated with {db_name_str}, Your 
task is to generate SQL query's based on the prompts and"
+                f"return the each query and its prompt in key value pair dict 
format. Make sure the generated query supports given DatabaseType and It should 
not generate any query without these dangerous keywords: 
{self.BLOCKED_KEYWORDS} without where class"

Review Comment:
   yeah sorry my bad updated prmopt :)



##########
providers/common/ai/src/airflow/providers/common/ai/operators/llm_sql.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 typing import TYPE_CHECKING
+
+from pydantic import BaseModel
+
+from airflow.providers.common.ai.operators.base_llm import BaseLLMOperator
+
+if TYPE_CHECKING:
+    from pydantic_ai.agent import AgentRunResult
+
+    from airflow.providers.common.ai.configs.datasource import DataSourceConfig
+
+
+class SQLQueryResponseOutputType(BaseModel):
+    """Output type LLM Sql query generate."""
+
+    sql_query_prompt_dict: dict[str, str]
+
+
+class LLMSQLQueryOperator(BaseLLMOperator):
+    """Operator to generate SQL queries based on prompts for multiple 
datasources."""
+
+    def __init__(
+        self, datasource_configs: list[DataSourceConfig], provider_model: str 
| None = None, **kwargs
+    ):
+        super().__init__(datasource_configs=datasource_configs, **kwargs)
+        self.provider_model = provider_model
+
+    def execute(self, context):
+        """Execute LLM Sql query operator."""
+        return super().execute(context)

Review Comment:
   agree..



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to