The morph_lib.ai package has been deprecated since v0.1.5 to reduce the size of the morph-data package.

It is planned to be provided in the form of an external adapter in the future.

Generates SQL from a given prompt.

# 📦 Package: morph_lib.ai.openai.code_generation
# 🛠️ Function: text_to_sql

def text_to_sql(
    prompt: str,
    api_key: str,
    table_names: List[str],
    model: Optional[str] = "gpt-4o",
    connection: Optional[str] = None,
    schema_name: Optional[str] = None,
) -> TextConversionResponse:

Parameters

These are the parameters for OpenAI. Set the authentication parameters for other models as appropriate from the function definitions above.

prompt
string
required

Prompt

api_key
string
required

API key for using the LLM model

table_names
list
required

List of table names used for generation

model
string

LLM model to use

connection
string

Connection used for generation

schema_name
string

Schema name used for generation

Example

from morph_lib.ai.openai import text_to_sql
import os

@morph.func
def func_name(context):
    sql = text_to_sql(
		prompt,
		os.environ["OPENAI_API_KEY"],
		["user"],
		"gpt-4o",
	)
	return execute_sql(sql)