{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7008ba66-ce29-4d9d-92d3-ce64ff9a5e2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from dotenv import load_dotenv, find_dotenv\n",
    "_ = load_dotenv(find_dotenv())\n",
    "REPLICATE_API_TOKEN = os.environ[\"REPLICATE_API_TOKEN\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e06723b2-71f7-49ea-bf54-cbea937e132e",
   "metadata": {},
   "source": [
    "There are a few ways to access LLaMA2.\n",
    "\n",
    "To run locally, use Ollama.ai. See [here](https://python.langchain.com/docs/integrations/chat/ollama) for details on installation and setup.\n",
    "\n",
    "To use an external API, which is not private, you can use Replicate. You can register and get your REPLICATE_API_TOKEN [here](https://replicate.com/)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d098ef28-cebf-46d6-90c0-4fcf8ab718b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.llms import Replicate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f2ddcd30-a6a2-4ecb-840c-5d737e1296e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Init param `input` is deprecated, please use `model_kwargs` instead.\n"
     ]
    }
   ],
   "source": [
    "replicate_id = \"meta/llama-2-13b-chat:f4e2de70d66816a838a89eeeb621910adffb0dd0baba3976c96980970978018d\"\n",
    "llama2_llm = Replicate(\n",
    "    model=replicate_id,\n",
    "    input={\"temperature\": 0.01, \n",
    "           \"max_length\": 500, \n",
    "           \"top_p\": 1}\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7fe079ea-71ee-43f9-858e-82b29cbad146",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = llama2_llm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "65d81600-104b-47c9-a826-d9da8bcba970",
   "metadata": {},
   "outputs": [],
   "source": [
    "question = \"Who was the second U.S. president of the 21st century?\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "46682ae7-c307-4f65-8e63-da36a7f3cffe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' Good question! The second U.S. president of the 21st century was George W. Bush, who served from 2001 to 2009.'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "llm(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ca1c953-683b-4273-9cc2-ec8cc8ceb3cd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
