{ "cells": [ { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "from langchain.llms import OpenAI\n", "from langchain.callbacks import get_openai_callback" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "llm = OpenAI(model_name=\"text-davinci-002\", temperature=0)" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Tokens Used: 56\n", "\tPrompt Tokens: 44\n", "\tCompletion Tokens: 12\n", "Successful Requests: 2\n", "Total Cost (USD): $0.0011200000000000001\n" ] } ], "source": [ "with get_openai_callback() as suspend:\n", " llm(\"男生3人,女生2人,老师有1人,一共多少人?\")\n", " llm(\"33*2=?\")\n", " print(suspend)" ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.10.10" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }