{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Calling a Large Language Model\n",
    "You can use the `evalute_prompt` method to call the LLM of your choice:\n",
    "- prompt: This is the actual message that the model receives from the user\n",
    "- system_message: These are the instructions that the model will follow"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Athens\n"
     ]
    }
   ],
   "source": [
    "r = client.evaluate_prompt(prompt = \"What is the capital of Greece?\", system_message = \"You should answer all questions with a single word.\", llm_name = \"OPENAI_GPT4O\")\n",
    "\n",
    "# Response:\n",
    "print(r.content)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Responding with JSON\n",
    "You can also use the `json_response_schema` to specify the output of the model in a pre-defined manner"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'learning_objectives': ['Understand the components and functions of car batteries',\n",
       "  'Learn how to maintain and troubleshoot car batteries',\n",
       "  'Gain knowledge about the different types of car doors and their mechanisms',\n",
       "  'Learn how to repair and replace car doors',\n",
       "  'Understand the principles and components of car suspension systems',\n",
       "  'Learn how to diagnose and fix common issues in car suspension systems']}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "r = client.evaluate_prompt(prompt = \"In this course, you will learn about car batteries, car doors, and car suspension system\",\n",
    "                           # system_message = \"OPTIONAL, but good to have\", \n",
    "                           llm_name = 'OPENAI_GPT4O',\n",
    "                           response_type='json',\n",
    "                           json_response_schema = {\"learning_objectives\": {\"type\": \"list\", \"description\": \"A list of learning objectives\", \"is_required\": True}}\n",
    ")\n",
    "learning_objectives = json.loads(r.content)\n",
    "learning_objectives"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Sending image to `client.evaluate_prompt`\n",
    "\n",
    "You can also send images so a model!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fo = open('test.png', 'rb')\n",
    "import base64\n",
    "encoded_data = base64.b64encode(fo.read()).decode('utf-8')\n",
    "\n",
    "response = client.evaluate_prompt(\n",
    "    prompt='What can you see in the image?',\n",
    "    messages=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": [\n",
    "                {\n",
    "                    \"type\": \"image_url\",\n",
    "                    \"image_url\": {\n",
    "                        \"url\": f\"data:image/png;base64,{encoded_data}\",\n",
    "                    },\n",
    "                },\n",
    "            ],\n",
    "        },\n",
    "    ],\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
