Calls and computations

LLMs and data
Author

Cody Peterson

Published

October 14, 2023

Introduction

The Generative AI hype cycle has led to a new wave of terminology to understand. In this post, we’ll use basic programming language to explain and explore the concepts of “chains” of LLMs and retrieval-augmented generation (RAG) approaches to working with data.

This post assumes basic familiarity with Marvin and Ibis and the three approaches to applying LLMs to data.

Code
import ibis
import marvin

from dotenv import load_dotenv

load_dotenv()

con = ibis.connect("duckdb://penguins.ddb")
t = ibis.examples.penguins.fetch()
t = con.create_table("penguins", t.to_pyarrow(), overwrite=True)
1
Import the libraries we need.
2
Load the environment variable to setup Marvin to call our OpenAI account.
3
Setup the demo datain an Ibis backend.
import ibis
import marvin

from ibis.expr.schema import Schema
from ibis.expr.types.relations import Table

ibis.options.interactive = True
marvin.settings.llm_model = "openai/gpt-4"

con = ibis.connect("duckdb://penguins.ddb")
t = con.table("penguins")
1
Import Ibis and Marvin.
2
Configure Ibis (interactive) and Marvin (GPT-4).
3
Connect to the data and load a table into a variable.

Calls and computations

When an AI platform’s large language model API is called, it returns text as the result of some computation on input text. See the LLM concept article for details.

Calls

A call is just that – a call to something. In Python, this is typically always something else in Python, that itself may make calls to other programming languages or external services.

@marvin.ai_fn
def _generate_sql_select(
    text: str, table_name: str, table_schema: Schema
) -> str:
    """Generate SQL SELECT from text."""


def sql_from_text(text: str, t: Table) -> Table:
    """Run SQL from text."""
    return t.sql(_generate_sql_select(text, t.get_name(), t.schema()).strip(";"))
1
A non-deterministic, LLM-powered AI function.
2
A deterministic, human-authored function that calls the AI function.

Computations

A computation is just that – a computation of something. In general, a computation is represented by a system that takes an input and returns an output.

Comparison to MLOps and DevOps

Summary

Next steps

You can get involved with Ibis Birdbrain, our open-source data & AI project for building next-generation natural language interfaces to data.

Read the next post in this series.

Back to top