{ "cells": [ { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "97" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import utils\n", "\n", "utils.load_env()\n", "\n", "from langchain.llms import OpenAI\n", "\n", "# Create an instance of the OpenAI class\n", "openai = OpenAI(model_name=\"text-davinci-003\")\n", "\n", "# Get the maximum context size for the model\n", "max_context_size = openai.modelname_to_contextsize(openai.model_name)\n", "\n", "# Set the max_tokens attribute to a value within the model's maximum context length\n", "openai.max_tokens = max_context_size - 1 # or any value less than max_context_size\n", "\n", "# Alternatively, you can use the max_tokens_for_prompt method\n", "prompt = \"Tell me a joke.\"*800\n", "openai.max_tokens = openai.max_tokens_for_prompt(prompt)\n", "openai.max_tokens" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.11.9" } }, "nbformat": 4, "nbformat_minor": 2 }