{ "cells": [ { "cell_type": "markdown", "id": "dbfff3b2-fbfd-4ba5-929c-c45d028801f3", "metadata": {}, "source": [ "# Llama LLM API Client Notebook" ] }, { "cell_type": "markdown", "id": "6fcc5513-4c08-42e5-9b96-20b37482d1ea", "metadata": {}, "source": [ "## This Notebook will send a request to the Llama LLM model's API and retrieve the response." ] }, { "cell_type": "markdown", "id": "5f98a3c4-81a6-44be-987a-cd4f5adcef77", "metadata": {}, "source": [ "### First we will import os, gradio and the LlamaAPIClient" ] }, { "cell_type": "code", "execution_count": 1, "id": "4c2a01b9-23d3-4f0e-9c1f-92b2b2b37231", "metadata": {}, "outputs": [], "source": [ "import os\n", "import gradio as gr\n", "from llama_api_client import LlamaAPIClient" ] }, { "cell_type": "markdown", "id": "e3e17aea-0422-4ad4-8ada-94e56e5b0fcf", "metadata": {}, "source": [ "# Use the following [link](https://l.facebook.com/l.php?u=https%3A%2F%2Fllama.developer.meta.com%2F&h=AT1np-Q96F0Qym-qTXCKJuPUqZePWH7EWzib2mRB0XSqjajogDg91FWpn-_MRnaVS7CGCR1o4Z3wff5uQNe55poibnARsHoU_Yf-uKANWztHmiSgl56GTo5ERQR1o8GmHatZ2Eb_hdCGIO4iD3-c0QZN5Sdq) to retrieve your Llama API key. Next, configure your environment by setting the \"LLAMA_API_KEY\" variable to the obtained key using one of the following steps." ] }, { "cell_type": "code", "execution_count": 25, "id": "8ff2c746-44ba-4594-9293-6fdae986fa1b", "metadata": {}, "outputs": [], "source": [ "# either run the following command in your cli terminal\n", "# export LLAMA_API_KEY='Llama API key'\n", "# Or\n", "# Directly set your LLAMA_API_KEY environment variable here\n", "# os.environ['LLAMA_API_KEY'] = 'Llama API key' " ] }, { "cell_type": "markdown", "id": "e7855614-9a8b-421d-b4ec-32b278c24f90", "metadata": {}, "source": [ "### Run the \"infer\" function to create an interactive UI where you can enter your input prompt for the LLM in the designated \"user_input\" field and view the generated response in the adjacent \"output\" field." ] }, { "cell_type": "code", "execution_count": 53, "id": "fd340fa0-a116-4f13-999b-60f5f99f2dc3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7890\n", "* To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "