/var/opt/nydus/ops/mysql/ai/genai/__pycache__
NameSizeModeActions
embedding.cpython-312.pyc76660644editdlrm
generation.cpython-312.pyc58120644editdlrm
vector_store.cpython-312.pyc194820644editdlrm
__init__.cpython-312.pyc6030644editdlrm
Edit: /var/opt/nydus/ops/mysql/ai/genai/__pycache__/generation.cpython-312.pyc (5812B)
N j1dZddlZddlmZmZmZ ddlmZddl m Z ddl m Z mZmZddlmZGdd eZy#e$r ddl mZY/wxYw) z{GenAI LLM integration utilities for MySQL Connector/Python. Provides MyLLM wrapper that issues ML_GENERATE calls via SQL. N)AnyListOptional)LLM) PrivateAttr)atomic_transaction execute_sqlformat_value_sql)MySQLConnectionAbstractc eZdZUdZeZeed<GddZdeffd Z dde de e e d e d e fd Zed efd Zed e fd ZxZS)MyLLMa Custom Large Language Model (LLM) interface for MySQL HeatWave. This class wraps the generation functionality provided by HeatWave LLMs, exposing an interface compatible with common LLM APIs for text generation. It provides full support for generative queries and limited support for agentic queries. Attributes: _db_connection (MySQLConnectionAbstract): Underlying MySQL connector database connection. _db_connectionceZdZdZdZy) MyLLM.ConfigaL Pydantic config for the model. By default, LangChain (through Pydantic BaseModel) does not allow setting or storing undeclared attributes such as _db_connection. Setting extra = "allow" makes it possible to store extra attributes on the class instance, which is required for MyLLM. allowN)__name__ __module__ __qualname____doc__extraJ/opt/nydus/tmp/pip-target-a90h98xg/lib/python/mysql/ai/genai/generation.pyConfigr@s rr db_connectionc0t|||_y)aS Initialize the MyLLM instance with an active MySQL database connection. Args: db_connection: A MySQL connection object used to run LLM queries. Notes: The db_connection is stored as a private attribute via object.__setattr__, which is compatible with Pydantic models. N)super__init__r)selfr __class__s rrzMyLLM.__init__Ls +rpromptstopkwargsreturnc (|j}|||d<t|\}}t|j5}d|d}t |||g|t j |jdd} ddd| S#1swY SxYw)ac Generate a text completion from the LLM for a given input prompt. References: https://dev.mysql.com/doc/heatwave/en/mys-hwgenai-ml-generate.html A full list of supported options (specified by kwargs) can be found under "options" Args: prompt: The input prompt string for the language model. stop: Optional list of stop strings to support agentic and chain-of-thought reasoning workflows. **kwargs: Additional keyword arguments providing generation options to the LLM (these are serialized to JSON and passed to the HeatWave syscall). Returns: The generated model output as a string. (The actual completion does NOT include the input prompt.) Raises: DatabaseError: If provided options are invalid or unsupported. If a database connection issue occurs. If an operational error occurs during execution. Implementation Notes: - Serializes kwargs into a SQL-compatible JSON string. - Calls the LLM stored procedure using a database cursor context. - Uses `sys.ML_GENERATE` on the server to produce the model output. - Expects the server response to be a JSON object with a 'text' key. Nstop_sequenceszSELECT sys.ML_GENERATE("%s", z);)paramsrtext)copyr rrr jsonloadsfetchone) rr!r"r#optionsoptions_placeholderoptions_paramscursorgenerate_query llm_responses r_callz MyLLM._call[sH++-  (,G$ %.>w.G+^  3 3 4!>?R>SSUXN 7P7P Q::foo&7&:;FCL 55s ABBc ddiS)z Return a dictionary of params that uniquely identify this LLM instance. Returns: dict: Dictionary of identifier parameters (should include model_name for tracing/caching). model_namemysql_heatwave_llmrrs r_identifying_paramszMyLLM._identifying_paramss .  rcy)z Get the type name of this LLM implementation. Returns: A string identifying the LLM provider (used for logging or metrics). r6rr7s r _llm_typezMyLLM._llm_types$r)N)rrrrrrr __annotations__rrstrrrrr3propertydictr8r: __classcell__)r s@rr r 0s /:mN+;   ,&= ,$%)00tCy!0 0 0d  T    $3$$rr )rr*typingrrr#langchain_core.language_models.llmsr ImportErrorlangchain.llms.basepydanticrmysql.ai.utilsrr r mysql.connector.abstractsr r rrrrGsM:  &&(7!LL=r$Cr$('(s: AA