{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Banana\n", "\n", "\n", "[Banana](https://www.banana.dev/about-us) is focused on building the machine learning infrastructure.\n", "\n", "This example goes over how to use LangChain to interact with Banana models" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "# Install the package https://docs.banana.dev/banana-docs/core-concepts/sdks/python\n", "!pip install banana-dev" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get new tokens: https://app.banana.dev/\n", "# We need three parameters to make a Banana.dev API call:\n", "# * a team api key\n", "# * the model's unique key\n", "# * the model's url slug\n", "\n", "import os\n", "from getpass import getpass\n", "\n", "# You can get this from the main dashboard\n", "# at https://app.banana.dev\n", "os.environ[\"BANANA_API_KEY\"] = \"YOUR_API_KEY\"\n", "# OR\n", "# BANANA_API_KEY = getpass()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from langchain.llms import Banana\n", "from langchain.prompts import PromptTemplate\nfrom langchain.chains import LLMChain" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "template = \"\"\"Question: {question}\n", "\n", "Answer: Let's think step by step.\"\"\"\n", "\n", "prompt = PromptTemplate(template=template, input_variables=[\"question\"])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Both of these are found in your model's \n", "# detail page in https://app.banana.dev\n", "llm = Banana(model_key=\"YOUR_MODEL_KEY\", model_url_slug=\"YOUR_MODEL_URL_SLUG\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "llm_chain = LLMChain(prompt=prompt, llm=llm)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "question = \"What NFL team won the Super Bowl in the year Justin Beiber was born?\"\n", "\n", "llm_chain.run(question)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.6" }, "vscode": { "interpreter": { "hash": "a0a0263b650d907a3bfe41c0f8d6a63a071b884df3cfdc1579f00cdc1aed6b03" } } }, "nbformat": 4, "nbformat_minor": 4 }