
AI Functions - Launch Week #2

Today, we will introduce how to build AI tools for your organization’s workflows using APIs from platforms like OpenAI and Anthropic on Morph, along with the features that make it all possible!
Using AI SDKs with Morph's Python Layer
Morph allows you to directly utilize the Python SDKs of OpenAI and Anthropic through its Python layer. This enables fine-grained control over API requests and response processing, making it possible to create AI tools tailored to your specific workflows.
For instance, you can design system prompts aligned with your business requirements, customize data inputs, and adjust the response formats. Additionally, executing scripts within the Python environment ensures seamless integration with your existing code and libraries.
Here’s an example of how easy it is to run AI SDKs with Morph:
@morph.variables("prompt")
def main(context: MorphGlobalContext):
client = OpenAI(api_key=os.environ.OPENAI_API_KEY)
prompt = context.vars["prompt"]
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
stream=True,
)
for c in response:
yield create_chunk(c.model_dump()["choices"][0]["delta"].get("content", ""))
Integrating Organizational Data into AI Models
Morph’s robust data integration capabilities make it possible to embed your organizational data into AI models. For example, you can query data stored in Snowflake using SQL and feed that data into an AI model to enhance its responses.
@morph.func
@morph.variables("prompt")
def main(context: MorphGlobalContext):
prompt = context.vars["prompt"]
response = text_to_sql(
prompt=prompt,
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o",
table_names=["SALES_DATA", "ORDER_DATA", "CUSTOMER_DATA"],
connection="Snowflake",
schema_name="PUBLIC"
)
yield create_chunk(response.code)
df = execute_sql(response.code, "Snowflake")
yield create_chunk(df.to_markdown())
Dynamic Data Analysis Based on User Input
With these capabilities, you can effortlessly build AI-powered dashboards that perform data analysis based on user input, leveraging your internal data.
For example, you can have your AI generate interactive charts by referencing organizational data. Here’s a code example:
@morph.func
@morph.variables("prompt")
@morph.load_data("customer_logs")
def chat(context: MorphGlobalContext):
prompt = context.vars["prompt"]
customer_logs = context.data["customer_logs"]
response = text_to_plotly(
prompt=prompt,
api_key=os.environ["OPENAI_API_KEY"],
model="gpt-4o",
df=customer_logs,
)
yield create_chunk(response.code, response.content)
export const title = "Chat";
<LLM
postData="chat"
layout="side-by-side"
height={300}
/>
With just a few lines of code, you can achieve a fully functional AI analyst. Unlike traditional BI systems, these tools excel at handling ad-hoc requests and unplanned analyses, providing unparalleled flexibility.
The Impact
Harnessing the latest AI models to streamline and improve business workflows is a priority for many organizations. However, when it comes to real-world implementation, customization often becomes necessary.
While numerous no-code tools claim to simplify AI customization, achieving ultimate flexibility still requires writing code. Morph, being a code-first platform, empowers you to customize your AI workflows with precision.
From feeding organizational data to AI models and combining multiple AI systems to fine-tuning output results, Morph enables you to build truly impactful AI tools for your business.
By building AI tools with Morph, you can instantly share the output with your team and start using it immediately. No need to worry about setting up infrastructure or deployment!
Related Articles


