Skip to content

Instantly share code, notes, and snippets.

@zredlined
Last active May 1, 2024 04:00
Show Gist options
  • Save zredlined/2c205049775aaa83ea201d2c1b87bd59 to your computer and use it in GitHub Desktop.
Save zredlined/2c205049775aaa83ea201d2c1b87bd59 to your computer and use it in GitHub Desktop.
gretel-tabular-llm-inference-api-example.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/zredlined/2c205049775aaa83ea201d2c1b87bd59/gretel-tabular-llm-inference-api-example.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"source": [
"%%capture\n",
"!pip install -Uqq gretel_client"
],
"metadata": {
"id": "-2YO5lg8Ydpj"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "o3pwdd5FYXvx"
},
"outputs": [],
"source": [
"from gretel_client import Gretel\n",
"\n",
"gretel = Gretel(api_key=\"prompt\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "owgebZrfYXvy"
},
"outputs": [],
"source": [
"navigator = gretel.factories.initialize_inference_api(\"navigator\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "3MYr-f5MYXvy"
},
"outputs": [],
"source": [
"prompt = \"\"\"\\\n",
"Generate a dataset of characters from The Simpsons.\n",
"\n",
"Each character should have the following columns:\n",
"* first_name: The first name of the character.\n",
"* last_name: The last name of the character.\n",
"* favorite_band: The character's all-time favorite band.\n",
"* favorite_tv_show: The character's favorite TV show other than The Simpsons.\n",
"* favorite_food: The character's favorite food.\n",
"* backstory: The character's back story in 3-5 sentences.\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "AYL_0bP2YXvz"
},
"outputs": [],
"source": [
"df = navigator.generate(prompt=prompt, num_records=10)\n",
"\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "I-uwHc0OYXvz"
},
"outputs": [],
"source": [
"edit_prompt = \"Please add a column that describes the character's worst nightmare.\"\n",
"\n",
"df = navigator.edit(prompt=edit_prompt, seed_data=df)\n",
"\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jdNdonhlYXvz"
},
"outputs": [],
"source": [
"for record in navigator.generate(prompt=prompt, num_records=10, stream=True):\n",
" print(record)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "monogretel-dev",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
},
"colab": {
"provenance": [],
"include_colab_link": true
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment