{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "67715ad0-1616-45c7-9135-ecf1ccf1d915",
   "metadata": {},
   "source": [
    "### Data Agent Prompting Template\n",
    "\n",
    "Normally, you have three ways to iterate on the behavior instructions of the model:\n",
    "1. Retrain model (This is a slow process since you need to wait for the model to update)\n",
    "2. Use the model's \"Playground\" on the deployment page.\n",
    "3. Use the API\n",
    "\n",
    "The script shows you how you can use the API to actually call a ChatLLM deployment and change the behavior settings as you see fit. Using the API has some advantages over the \"Playground\" depending on the user's expertise level."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c411f4d7-14db-40b1-a9a7-0c9c0b69c1e7",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2024-06-20T18:16:20.496172Z",
     "iopub.status.busy": "2024-06-20T18:16:20.495787Z",
     "iopub.status.idle": "2024-06-20T18:16:21.450856Z",
     "shell.execute_reply": "2024-06-20T18:16:21.450190Z",
     "shell.execute_reply.started": "2024-06-20T18:16:20.496140Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "from abacusai import PredictionClient, ApiClient\n",
    "client = PredictionClient()\n",
    "\n",
    "deployment_token = \"\"\n",
    "deployment_id = \"\"\n",
    "\n",
    "behavior = \"\"\" FILL IN YOUR BEHAVIOR INSTRUCTIONS\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "data_prompt = \"\"\"\n",
    "FILL IN YOUR DATA PROMPT INSTRUCTIONS\n",
    "\"\"\"\n",
    "\n",
    "response_instructions = \"\"\"\n",
    "FILL IN YOUR RESPONSE INSTRUCTIONS\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e1d03576",
   "metadata": {},
   "outputs": [],
   "source": [
    "chat_config = {'data_prompt_context': data_prompt, 'behavior_instructions':behavior, 'response_instructions':response_instructions}\n",
    "#chat_config={\"data_prompt_table_context\": {\"concrete_strength\": \"This tables has information about cement\"} -- How to add table level information"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e872cb7-6e04-42c5-b657-ff20aa6da716",
   "metadata": {
    "editable": true,
    "execution": {
     "iopub.execute_input": "2024-06-20T18:16:36.762992Z",
     "iopub.status.busy": "2024-06-20T18:16:36.762506Z",
     "iopub.status.idle": "2024-06-20T18:16:36.766605Z",
     "shell.execute_reply": "2024-06-20T18:16:36.765822Z",
     "shell.execute_reply.started": "2024-06-20T18:16:36.762960Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "question = 'What is the .....'\n",
    "\n",
    "r = client.get_chat_response(deployment_token=deployment_token,\n",
    "                         deployment_id=deployment_id,\n",
    "                         messages=[{\"is_user\":True,\"text\":question}],\n",
    "                         chat_config=chat_config,\n",
    "                         #llm_name = \"\" # In case you want to change LLM that is used to provid the answer\n",
    "                         )\n",
    "\n",
    "print(r['messages'][1]['text'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1e47e7c",
   "metadata": {},
   "source": [
    "#### How to get current model config -- if required"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99dc02ea-968e-414f-b41f-f91c9e607218",
   "metadata": {},
   "outputs": [],
   "source": [
    "client = ApiClient()\n",
    "project_id = \"YOUR_PROJECT_ID\"\n",
    "models = client.list_models(project_id)\n",
    "\n",
    "for model in models:\n",
    "    print(f\"Model Name: {model.name}\")\n",
    "    print(f\"Model ID: {model.id}\")\n",
    "    print(\"Latest Model Version:\")\n",
    "    latest_version = client.describe_model_version(model.latest_model_version.model_version)\n",
    "    print(f\"  Version: {latest_version.model_version}\")\n",
    "    print(f\"  Status: {latest_version.status}\")\n",
    "    print(\"  Training Config:\")\n",
    "    print(latest_version.model_config.to_dict())\n",
    "    print(\"\\n\" + \"=\"*50 + \"\\n\")"
   ]
  }
 ],
 "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
