{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9c8c6a86-c220-4ef9-91f3-97a0ad6eb109",
   "metadata": {},
   "source": [
    "### Import the packages required for LLM Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3111e7c-0ba4-4703-8970-e2149c42409a",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install httpx openai langchain langchain-core langchain-openai langchain-classic"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86bd819f-b844-4a8d-b1c7-ff1f77de21f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#import the necessary packages \n",
    "# package required for calling the LLM model endpoint \n",
    "from openai import OpenAI\n",
    "import httpx"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1b8bba17-7c2b-485f-8187-f38bec34d683",
   "metadata": {},
   "source": [
    "### Prepare the LLM model instance with the locally deployemnt 8B LLM Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "94c43a49-631f-43e8-b9d0-46aa19aa83d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "MODEL_ENDPOINT = \"https://do-no-delete--llama-multimodal-predictor-hugo-hpe-com-7f9ace25.ai-application.hou-pcai.hpecic.net/v1\"\n",
    "AUTH_TOKEN = \"eyJhbGciOiJSUzI1NiIsImtpZCI6IkdVRF93ZGprQW9LMjI1NlZfZUFLQUQ0TVFKaXVveDBpa0xLS0ZhbVdfNFEifQ.eyJhdWQiOlsiYXBpIiwiaXN0aW8tY2EiXSwiZXhwIjoxNzc1MTEyNTYxLCJpYXQiOjE3NzI1MjA1NjEsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwianRpIjoiMWMxZGE5YjAtODM5MS00OGZlLTk1NTEtZTdhOWFkOGM1ZWZmIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJ1aSIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJpc3ZjLWVwLTE3NzI1MjA1NTQ1NDIiLCJ1aWQiOiIzNjQyMWQ1Yy01YTRkLTQzZmMtOGFlMS0zN2IyODkwOWQzMzQifX0sIm5iZiI6MTc3MjUyMDU2MSwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OnVpOmlzdmMtZXAtMTc3MjUyMDU1NDU0MiJ9.XBzC4o18DrH376NnRqP4F07_ZdsDKfjfDmmH5rVrTlrEl7Jg_Ks_uyDMp4aZMLRUlVo8CEzcNVOgz8C80BBB9HXZwNqUEoMU4saBKpYfZuD6zcPse3JvxOv45pPbhmxRULDC-6xSFHLvlnZ46sgnL0gQAXrFS3eFKVZaoDkD3UYAHeRh6gdtvRmHDGpqz5DP6P5SuqreYNEU7kRvwjt7FsnTJlQx6Zo1btUdkK76tE3Z9VglycBFmQJAjw-eyZs1iwN1ywF9LcQxo4MrRoYzRtFYrwHT94zFsVWPkTa_0wjll_urY0qdx7rUA_or4OmLwDgaY6M6DH6C9McjdO_bog\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7bf3e84a-dae1-4f28-b5f6-691dd1793c13",
   "metadata": {},
   "outputs": [],
   "source": [
    "apikey=AUTH_TOKEN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c9980374-221c-479c-9750-586317f72aba",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Initialize client\n",
    "httpx_client = httpx.Client(verify=False)\n",
    "client = OpenAI(\n",
    "        api_key=apikey,\n",
    "        base_url=MODEL_ENDPOINT,\n",
    "        http_client=httpx_client\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef09705e-bd9d-4be1-8155-c2cb6b9ebf2f",
   "metadata": {},
   "source": [
    "### Function to interact with LLM Model - QA "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6c59846-1f5f-462f-bae9-53550db39b9a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Function to interact with LLM model\n",
    "\n",
    "def answer_question_with_llama(question: str):\n",
    "    print(f\"Question: {question}\")\n",
    "    messages = [\n",
    "     {\"role\": \"user\", \"content\": f\"{question}\"}\n",
    "    ]\n",
    "    \n",
    "    chat_response = client.chat.completions.create(\n",
    "         model=\"meta-llama/Llama-3.2-11B-Vision-Instruct\",\n",
    "         messages=messages,\n",
    "         max_tokens=1024,\n",
    "         stream=False\n",
    "    )\n",
    "    # Pass the question directly to the model (no prompt template used)\n",
    "    full_response = chat_response.choices[0].message  # This calls the custom Llama-3.1.8B LLM\n",
    "    \n",
    "    # Display only the  answer\n",
    "    print(f\"Answer from LLM model: {full_response.content}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5af3fba4-9a17-40e9-9e34-c4351e2d0fdf",
   "metadata": {},
   "source": [
    "### Testing the LLM model with QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18c9dcc3-4751-42d5-a0b3-99aa3ed63138",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example Question\n",
    "question = \"What is the capital of France?\"\n",
    "answer_question_with_llama(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4af2c5c5-4718-4188-9076-57d6443c4a29",
   "metadata": {},
   "outputs": [],
   "source": [
    "question = \"Who is the current prime minister of Australia?\"\n",
    "answer_question_with_llama(question)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7dfae54c-5aa0-4752-9441-01449f9851f4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9234bf69-7edb-4db1-8e96-a6370074b7a7",
   "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.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
