{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3bfa7639",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7f0247e2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"load_dotenv(override = True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "971f57ca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GROQ_API_KEY is set\n"
]
}
],
"source": [
"import os\n",
"groq_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"if groq_api_key:\n",
" print(\"GROQ_API_KEY is set\")\n",
"else:\n",
" print(\"GROQ_API_KEY is not set\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5bf3ecf7",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (1639672286.py, line 1)",
"output_type": "error",
"traceback": [
" \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mfrom groq Import Groq\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m invalid syntax\n"
]
}
],
"source": [
"from groq Import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18dd1ce6",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c5787a4b",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[6]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3fcd0ab7",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[7]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n\u001b[32m 3\u001b[39m client = Groq()\n\u001b[32m 4\u001b[39m completion = client.chat.completions.create(\n\u001b[32m 5\u001b[39m model=\u001b[33m\"\u001b[39m\u001b[33mopenai/gpt-oss-120b\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 6\u001b[39m messages=[\n\u001b[32m (...)\u001b[39m\u001b[32m 17\u001b[39m stop=\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 18\u001b[39m )\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n",
"\n",
"client = Groq()\n",
"completion = client.chat.completions.create(\n",
" model=\"openai/gpt-oss-120b\",\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"\"\n",
" }\n",
" ],\n",
" temperature=1,\n",
" max_completion_tokens=8192,\n",
" top_p=1,\n",
" reasoning_effort=\"medium\",\n",
" stream=True,\n",
" stop=None\n",
")\n",
"\n",
"for chunk in completion:\n",
" print(chunk.choices[0].delta.content or \"\", end=\"\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29acbb6d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e57a2404",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"'c:\\Users\\govindh' is not recognized as an internal or external command,\n",
"operable program or batch file.\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install groq"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "35374ec1",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9a722979",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe: No module named pip\n"
]
}
],
"source": [
"%pip install groq\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04f22594",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'groq'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgroq\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Groq\n",
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'groq'"
]
}
],
"source": [
"from groq import Groq\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "eea60e94",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "4a341d20",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\Users\\govindh vaila\\projects\\agents\\.venv\\Scripts\\python.exe\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "c543e1f1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"works\n"
]
}
],
"source": [
"from groq import Groq\n",
"print(\"works\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "4c33500f",
"metadata": {},
"outputs": [],
"source": [
"groq=Groq()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5f9ef82e",
"metadata": {},
"outputs": [
{
"ename": "BadRequestError",
"evalue": "Error code: 400 - {'error': {'message': 'The model `whisper-large-v3` does not support chat completions', 'type': 'invalid_request_error'}}",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mBadRequestError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m messages=[{\u001b[33m'\u001b[39m\u001b[33mrole\u001b[39m\u001b[33m'\u001b[39m:\u001b[33m'\u001b[39m\u001b[33muser\u001b[39m\u001b[33m'\u001b[39m,\u001b[33m'\u001b[39m\u001b[33mcontent\u001b[39m\u001b[33m'\u001b[39m: \u001b[33m'\u001b[39m\u001b[33mwhat is the capital of india?\u001b[39m\u001b[33m'\u001b[39m}]\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m response=\u001b[43mgroq\u001b[49m\u001b[43m.\u001b[49m\u001b[43mchat\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcompletions\u001b[49m\u001b[43m.\u001b[49m\u001b[43mcreate\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 3\u001b[39m \u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m=\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mwhisper-large-v3\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 4\u001b[39m \u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 5\u001b[39m \u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m8192\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 6\u001b[39m \u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m=\u001b[49m\u001b[32;43m0.5\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 7\u001b[39m \u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\resources\\chat\\completions.py:461\u001b[39m, in \u001b[36mCompletions.create\u001b[39m\u001b[34m(self, messages, model, citation_options, compound_custom, disable_tool_validation, documents, exclude_domains, frequency_penalty, function_call, functions, include_domains, include_reasoning, logit_bias, logprobs, max_completion_tokens, max_tokens, metadata, n, parallel_tool_calls, presence_penalty, reasoning_effort, reasoning_format, response_format, search_settings, seed, service_tier, stop, store, stream, temperature, tool_choice, tools, top_logprobs, top_p, user, extra_headers, extra_query, extra_body, timeout)\u001b[39m\n\u001b[32m 241\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mcreate\u001b[39m(\n\u001b[32m 242\u001b[39m \u001b[38;5;28mself\u001b[39m,\n\u001b[32m 243\u001b[39m *,\n\u001b[32m (...)\u001b[39m\u001b[32m 300\u001b[39m timeout: \u001b[38;5;28mfloat\u001b[39m | httpx.Timeout | \u001b[38;5;28;01mNone\u001b[39;00m | NotGiven = not_given,\n\u001b[32m 301\u001b[39m ) -> ChatCompletion | Stream[ChatCompletionChunk]:\n\u001b[32m 302\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 303\u001b[39m \u001b[33;03m Creates a model response for the given chat conversation.\u001b[39;00m\n\u001b[32m 304\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 459\u001b[39m \u001b[33;03m timeout: Override the client-level default timeout for this request, in seconds\u001b[39;00m\n\u001b[32m 460\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m461\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_post\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 462\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43m/openai/v1/chat/completions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[32m 463\u001b[39m \u001b[43m \u001b[49m\u001b[43mbody\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmaybe_transform\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 464\u001b[39m \u001b[43m \u001b[49m\u001b[43m{\u001b[49m\n\u001b[32m 465\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmessages\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmessages\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 466\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmodel\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 467\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcitation_options\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcitation_options\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 468\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mcompound_custom\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mcompound_custom\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 469\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mdisable_tool_validation\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mdisable_tool_validation\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 470\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mdocuments\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mdocuments\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 471\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mexclude_domains\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mexclude_domains\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 472\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfrequency_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrequency_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 473\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunction_call\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunction_call\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 474\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mfunctions\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mfunctions\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 475\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43minclude_domains\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43minclude_domains\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 476\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43minclude_reasoning\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43minclude_reasoning\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 477\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogit_bias\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogit_bias\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 478\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mlogprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mlogprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 479\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_completion_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_completion_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 480\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmax_tokens\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmax_tokens\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 481\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mmetadata\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mmetadata\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 482\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mn\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 483\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mparallel_tool_calls\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mparallel_tool_calls\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 484\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mpresence_penalty\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mpresence_penalty\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 485\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mreasoning_effort\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mreasoning_effort\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 486\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mreasoning_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mreasoning_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 487\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mresponse_format\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mresponse_format\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 488\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43msearch_settings\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43msearch_settings\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 489\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mseed\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mseed\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 490\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mservice_tier\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mservice_tier\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 491\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstop\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstop\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 492\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstore\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstore\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 493\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mstream\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 494\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtemperature\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtemperature\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 495\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtool_choice\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtool_choice\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 496\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtools\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtools\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 497\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_logprobs\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_logprobs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 498\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mtop_p\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43mtop_p\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 499\u001b[39m \u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43muser\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m \u001b[49m\u001b[43muser\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 500\u001b[39m \u001b[43m \u001b[49m\u001b[43m}\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 501\u001b[39m \u001b[43m \u001b[49m\u001b[43mcompletion_create_params\u001b[49m\u001b[43m.\u001b[49m\u001b[43mCompletionCreateParams\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 502\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 503\u001b[39m \u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[43m=\u001b[49m\u001b[43mmake_request_options\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 504\u001b[39m \u001b[43m \u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_headers\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_query\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m=\u001b[49m\u001b[43mextra_body\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mtimeout\u001b[49m\n\u001b[32m 505\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 506\u001b[39m \u001b[43m \u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m=\u001b[49m\u001b[43mChatCompletion\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 507\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01mor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[32m 508\u001b[39m \u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mStream\u001b[49m\u001b[43m[\u001b[49m\u001b[43mChatCompletionChunk\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 509\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_base_client.py:1284\u001b[39m, in \u001b[36mSyncAPIClient.post\u001b[39m\u001b[34m(self, path, cast_to, body, content, options, files, stream, stream_cls)\u001b[39m\n\u001b[32m 1275\u001b[39m warnings.warn(\n\u001b[32m 1276\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPassing raw bytes as `body` is deprecated and will be removed in a future version. \u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 1277\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mPlease pass raw bytes via the `content` parameter instead.\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 1278\u001b[39m \u001b[38;5;167;01mDeprecationWarning\u001b[39;00m,\n\u001b[32m 1279\u001b[39m stacklevel=\u001b[32m2\u001b[39m,\n\u001b[32m 1280\u001b[39m )\n\u001b[32m 1281\u001b[39m opts = FinalRequestOptions.construct(\n\u001b[32m 1282\u001b[39m method=\u001b[33m\"\u001b[39m\u001b[33mpost\u001b[39m\u001b[33m\"\u001b[39m, url=path, json_data=body, content=content, files=to_httpx_files(files), **options\n\u001b[32m 1283\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m1284\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m cast(ResponseT, \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mrequest\u001b[49m\u001b[43m(\u001b[49m\u001b[43mcast_to\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopts\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m=\u001b[49m\u001b[43mstream_cls\u001b[49m\u001b[43m)\u001b[49m)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_base_client.py:1071\u001b[39m, in \u001b[36mSyncAPIClient.request\u001b[39m\u001b[34m(self, cast_to, options, stream, stream_cls)\u001b[39m\n\u001b[32m 1068\u001b[39m err.response.read()\n\u001b[32m 1070\u001b[39m log.debug(\u001b[33m\"\u001b[39m\u001b[33mRe-raising status error\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m-> \u001b[39m\u001b[32m1071\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;28mself\u001b[39m._make_status_error_from_response(err.response) \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1073\u001b[39m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[32m 1075\u001b[39m \u001b[38;5;28;01massert\u001b[39;00m response \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m, \u001b[33m\"\u001b[39m\u001b[33mcould not resolve response (should never happen)\u001b[39m\u001b[33m\"\u001b[39m\n",
"\u001b[31mBadRequestError\u001b[39m: Error code: 400 - {'error': {'message': 'The model `whisper-large-v3` does not support chat completions', 'type': 'invalid_request_error'}}"
]
}
],
"source": [
"messages=[{'role':'user','content': 'what is the capital of india?'}]\n",
"response=groq.chat.completions.create(\n",
" model=\"whisper-large-v3\",\n",
" messages=messages,\n",
" max_tokens=8192,\n",
" temperature=0.5,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "41655e37",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'groq' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m messages=[{\u001b[33m'\u001b[39m\u001b[33mrole\u001b[39m\u001b[33m'\u001b[39m:\u001b[33m'\u001b[39m\u001b[33muser\u001b[39m\u001b[33m'\u001b[39m,\u001b[33m'\u001b[39m\u001b[33mcontent\u001b[39m\u001b[33m'\u001b[39m: \u001b[33m'\u001b[39m\u001b[33mwhat is the capital of india?\u001b[39m\u001b[33m'\u001b[39m}]\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m response=\u001b[43mgroq\u001b[49m.chat.completions.create(\n\u001b[32m 3\u001b[39m model=\u001b[33m\"\u001b[39m\u001b[33mgroq/compound-mini\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 4\u001b[39m messages=messages,\n\u001b[32m 5\u001b[39m max_tokens=\u001b[32m8192\u001b[39m,\n\u001b[32m 6\u001b[39m temperature=\u001b[32m0.5\u001b[39m,\n\u001b[32m 7\u001b[39m )\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[31mNameError\u001b[39m: name 'groq' is not defined"
]
}
],
"source": [
"messages=[{'role':'user','content': 'what is the capital of india?'}]\n",
"response=groq.chat.completions.create(\n",
" model=\"groq/compound-mini\",\n",
" messages=messages,\n",
" max_tokens=8192,\n",
" temperature=0.5,\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4de006df",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'os' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m google_api_key= \u001b[43mos\u001b[49m.getenv(\u001b[33m'\u001b[39m\u001b[33mGEMINI_API_KEY\u001b[39m\u001b[33m'\u001b[39m)\n",
"\u001b[31mNameError\u001b[39m: name 'os' is not defined"
]
}
],
"source": [
"google_api_key= os.getenv('GEMINI_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "5e51ff8a",
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "531274e3",
"metadata": {},
"outputs": [],
"source": [
"google_api_key= os.getenv('GEMINI_API_KEY')\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f3775084",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'os' is not defined",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mNameError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m deepseek_api_key=\u001b[43mos\u001b[49m.getenv(\u001b[33m'\u001b[39m\u001b[33mDEEPSEEK_API_KEY\u001b[39m\u001b[33m'\u001b[39m)\n",
"\u001b[31mNameError\u001b[39m: name 'os' is not defined"
]
}
],
"source": [
"deepseek_api_key=os.getenv('DEEPSEEK_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8772de63",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"deepseek_apikey=os.getenv('DEEPSEEK_API_KEY')\n",
"google_api_key= os.getenv('GEMINI_API_KEY')"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7573416e",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9e760898",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"load_dotenv(override= True)\n"
]
},
{
"cell_type": "markdown",
"id": "61b65f25",
"metadata": {},
"source": [
"import os\n",
"from groq import Groq\n",
"\n",
"deepseek_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"client= Groq()\n",
"\n",
"endpoint=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.5,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content' :'what are the natural resources ?'}\n",
" ]\n",
")\n",
"print(endpoint.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "9c3fa94d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**Natural resources** are materials or substances that exist in nature and can be used by humans with little or no processing. They include everything we rely on for food, water, energy, shelter, clothing, manufacturing, and many other aspects of daily life.\n",
"\n",
"### Main categories\n",
"\n",
"| Category | Renewable (can replenish) | Non‑renewable (finite) |\n",
"|----------|---------------------------|------------------------|\n",
"| **Biotic** (from living things) | • Forests / timber
• Fish, wildlife
• Crops & livestock | • Fossil fuels (coal, oil, natural gas)
• Coal, petroleum, natural gas |\n",
"| **Abiotic** (non‑living) | • Sunlight
• Wind
• Water (freshwater, rivers, rain) | • Minerals & metals (iron, copper, gold, uranium, bauxite, etc.)
• Coal, oil, natural gas |\n",
"| **Atmospheric** | • Air (oxygen, nitrogen) | – |\n",
"\n",
"### Common examples\n",
"\n",
"| Renewable resources | Non‑renewable resources |\n",
"|---------------------|--------------------------|\n",
"| **Air / Oxygen** – essential for respiration | **Coal** – used for electricity and steel |\n",
"| **Water** – drinking, irrigation, industry | **Oil / Petroleum** – fuels, plastics, chemicals |\n",
"| **Sunlight** – solar energy, photosynthesis | **Natural gas** – heating, electricity, chemicals |\n",
"| **Timber / Forests** – wood, paper, habitat | **Uranium** – nuclear power |\n",
"| **Marine life** – fish, seaweed | **Metal ores** – iron, copper, gold, bauxite, etc. |\n",
"| **Soil** – agriculture, construction | **Diamonds** – industrial and gemstone uses |\n",
"| **Wind** – wind power | – |\n",
"\n",
"### Why they matter\n",
"- **Survival:** Air, water, food (plants & animals) are essential for life. \n",
"- **Economy:** Minerals, fossil fuels, and timber drive industry, transportation, and trade. \n",
"- **Energy:** Sunlight, wind, water, and fossil fuels generate electricity and heat. \n",
"- **Culture & Science:** Many resources have cultural significance and are used in research.\n",
"\n",
"In short, natural resources are the **raw, naturally occurring materials**—both living (biotic) and non‑living (abiotic)—that humans extract, manage, and use to meet basic needs, produce goods, and power societies.\n"
]
}
],
"source": [
"import os\n",
"from groq import Groq\n",
"\n",
"deepseek_api_key = os.getenv(\"GROQ_API_KEY\")\n",
"client= Groq()\n",
"\n",
"endpoint=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.5,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content' :'what are the natural resources ?'}\n",
" ]\n",
")\n",
"print(endpoint.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6b3d7619",
"metadata": {},
"outputs": [],
"source": [
"import os\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "290b9c7f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"## Real‑Time Clinical Coding Assistant – An Agentic‑AI Solution \n",
"*(Target: In‑workflow coding suggestions while a provider writes a note)* \n",
"\n",
"--- \n",
"\n",
"### 1️⃣ Vision Statement \n",
"\n",
"> **“Turn every discharge note into a claim‑ready, audit‑proof document the moment the clinician clicks ‘Finish’.”** \n",
"\n",
"The system acts as an **AI‑driven “coding co‑pilot”** that **plans**, **orchestrates**, and **executes** a multi‑step workflow, then **hands the final decision back to the clinician**. The result is ‑ minutes saved per chart, ‑ higher coding accuracy, ‑ fewer claim denials, ‑ and a measurable reduction in clinician burnout.\n",
"\n",
"--- \n",
"\n",
"## 2️⃣ High‑Level Architecture \n",
"\n",
"```\n",
"+-------------------+ +-------------------+ +-------------------+\n",
"| EHR / EMR (FHIR) | <----> | Secure API GW | <----> | Agentic AI Service|\n",
"+-------------------+ +-------------------+ +-------------------+\n",
" | | |\n",
" | | |\n",
" +--------------------------+ | +--------------------------+\n",
" | | |\n",
" v v v\n",
"+---------------+ +----------------+ +----------------+ +-------------------+\n",
"| Orchestrator | | Extraction | | Code‑Mapper | | Compliance Guard |\n",
"| (Planner) | | Engine (LLM+ | | Engine (Rules/ | | (HIPAA, CPT, |\n",
"| | | NER) | | Knowledge) | | payer rules) |\n",
"+---------------+ +----------------+ +----------------+ +-------------------+\n",
" | | | |\n",
" v v v v\n",
"+----------------+ +----------------+ +----------------+ +-------------------+\n",
"| UI Overlay / | | Structured Data| | Suggestion | | Audit & Learning |\n",
"| Clinician Hub | | Puller (Labs, | | Engine (ranked| | Engine (feedback |\n",
"| (EHR‑embedded) | | Meds, Imaging) | | by confidence)| | loop, drift) |\n",
"+----------------+ +----------------+ +----------------+ +-------------------+\n",
"```\n",
"\n",
"*All components run inside a **FIPS‑140‑2‑validated** VPC, communicate over **mutual TLS**, and are logged for **HIPAA audit trails**.*\n",
"\n",
"--- \n",
"\n",
"## 3️⃣ Core Agentic‑AI Modules \n",
"\n",
"| Module | Function | Key Technologies |\n",
"|--------|----------|-------------------|\n",
"| **Orchestrator (Planner)** | Receives “note‑completed” event, creates a **task graph** (extract → map → validate → present). Dynamically decides which external services to call based on note type, payer, and confidence thresholds. | LangChain / CrewAI style planner, OpenAI GPT‑4o / Anthropic Claude‑3.5, custom graph engine (NetworkX). |\n",
"| **Extraction Engine** | Performs **clinical concept extraction** (diagnoses, procedures, devices, labs) from free‑text and from structured EHR resources. Returns spans with provenance (sentence #, timestamp). | LLM‑augmented NER (MedSpaCy + BioClinicalBERT), few‑shot prompting, fallback regex for lab codes. |\n",
"| **Code‑Mapper Engine** | **Deterministic mapping** of extracted concepts to ICD‑10‑CM, CPT, HCPCS, DRG, and payer‑specific modifiers. Applies hierarchy, exclusion rules, and bundling logic. | Knowledge graph (Neo4j) of code sets, rule engine (Drools), OpenAI function calling for ambiguous cases. |\n",
"| **Compliance Guard** | Enforces **HIPAA, payer contracts, state‑level coding policies**; masks PHI before any LLM call; validates that suggested codes meet payer‑specific bundling and sequencing rules. | Policy engine (OPA – Open Policy Agent), token‑level redaction, audit logs. |\n",
"| **Suggestion UI Overlay** | Embedded in the EHR (via SMART on FHIR or native widget). Shows **rank‑ordered suggestions**, confidence scores, and **source snippets** (e.g., “SpO₂ = 88 % → CPT 99291”). Allows **Approve / Edit / Reject** in a single click. | React + TypeScript, FHIR UI components, real‑time WebSocket updates. |\n",
"| **Audit & Learning Engine** | Captures clinician actions (accept/reject/edit), stores them in a **secure data lake**, runs nightly **model‑drift** detection, and triggers **re‑training** or **rule‑update** cycles. | Snowflake / Azure Synapse, MLflow, SageMaker Pipelines, drift detection (Alibi‑Detect). |\n",
"| **Secure API Gateway** | Central point for **authentication (OAuth 2.0 + SMART on FHIR), rate‑limiting, logging, and encryption**. | Kong / Apigee, AWS PrivateLink, AWS KMS for key management. |\n",
"\n",
"--- \n",
"\n",
"## 4️⃣ Data Flow – Step‑by‑Step (Real‑Time Use Case)\n",
"\n",
"1. **Trigger** – Clinician clicks **“Finish Note”** in the EHR → EHR emits a **FHIR `DocumentReference`** event to the API gateway. \n",
"2. **Orchestrator** builds a **plan**: \n",
" - `extract_concepts(note_id)` → `map_codes(concepts)` → `apply_payer_rules(codes)` → `present_suggestions`. \n",
"3. **Extraction Engine** pulls the note text, runs LLM‑augmented NER, returns a JSON list of entities with **source FHIR references** (e.g., LabResult `Observation/1234`). \n",
"4. **Code‑Mapper** queries the **code graph** (Neo4j) and applies **payer‑specific rule sets** (e.g., “If CPT 99291 is used, add modifier -25”). \n",
"5. **Compliance Guard** validates the mapping, redacts any residual PHI, and logs the decision. \n",
"6. **UI Overlay** receives the ranked suggestions via a secure WebSocket, renders them inline next to the note. Clinician **approves** or **edits**. \n",
"7. **Audit Engine** records the action (`approved`, `edited → new code`, `rejected`). If edited, the delta is stored for **continuous learning**. \n",
"8. **Claim Payload** – Approved codes are pushed back to the EHR’s billing module (FHIR `Claim` resource) and to the payer interface. \n",
"\n",
"--- \n",
"\n",
"## 5️⃣ Security & Compliance Blueprint \n",
"\n",
"| Requirement | Implementation |\n",
"|-------------|----------------|\n",
"| **HIPAA‑Breach‑Proof** | All PHI stays **inside the VPC**; any LLM call that needs raw text is performed on **on‑premise LLM** (e.g., Llama 3‑8B‑Chat with encrypted inference) or via **OpenAI’s HIPAA‑covered** endpoint. |\n",
"| **Data Encryption** | Rest‑at‑AES‑256, in‑flight‑TLS 1.3 + mTLS for service‑to‑service calls. |\n",
"| **Access Control** | Role‑based access (RBAC) enforced by OIDC; only “Clinical Documentation” role can invoke the agent. |\n",
"| **Audit Trail** | Immutable CloudTrail / Azure Monitor logs; each suggestion includes `user_id`, `timestamp`, `source_fhir_id`, `confidence`, and final decision. |\n",
"| **Payer‑Specific Rules** | Stored in a **policy store** (OPA) that can be version‑controlled and signed (e.g., using Git‑signed commits). |\n",
"| **Incident Response** | Automated alert on any anomalous API usage (spike in calls, out‑of‑policy code suggestions). |\n",
"\n",
"--- \n",
"\n",
"## 6️⃣ Human‑in‑the‑Loop (HITL) Design \n",
"\n",
"1. **Confidence Threshold UI** – Only codes **≥ 85 %** confidence are shown as “auto‑accept”; lower‑confidence suggestions are highlighted with a **“review required”** badge. \n",
"2. **Rationale Pop‑over** – Click a suggestion → see the exact sentence(s) that triggered it, plus any lab/imaging evidence. \n",
"3. **One‑Click Approval** – A single “✓” inserts the code into the claim; a “✎” opens a quick edit modal. \n",
"4. **Escalation Path** – If a clinician rejects > 3 suggestions in a row, the system surfaces a **“Contact Coding Specialist”** button. \n",
"5. **Feedback Capture** – Every edit is sent back to the **Learning Engine** with a **label** (“false positive”, “missing code”) for supervised fine‑tuning. \n",
"\n",
"--- \n",
"\n",
"## 7️⃣ Continuous Learning & Drift Management \n",
"\n",
"| Activity | Frequency | Tooling |\n",
"|----------|-----------|---------|\n",
"| **Rule‑Set Sync** (CPT/ICD updates) | Weekly pull from CMS & AMA feeds | Python ETL → Neo4j update |\n",
"| **Model Retraining** (NER & LLM prompting) | Monthly (or when drift > 5 %) | SageMaker Pipelines, MLflow tracking |\n",
"| **Drift Detection** (confidence distribution shift) | Daily batch job | Alibi‑Detect, statistical KS test |\n",
"| **Human Review Audits** | Quarterly random sample of 5 % of claims | Internal audit dashboard, export to Excel/PowerBI |\n",
"\n",
"--- \n",
"\n",
"## 8️⃣ Pilot Blueprint \n",
"\n",
"| Phase | Goal | Duration | Key Deliverables |\n",
"|-------|------|----------|------------------|\n",
"| **1️⃣ Discovery & Data Mapping** | Identify a single service line (e.g., **Cardiology discharge**). Map all relevant FHIR resources (Note, Observation, Procedure). | 4 weeks | Data dictionary, API contracts, compliance sign‑off. |\n",
"| **2️⃣ MVP Build** | Implement end‑to‑end flow for **ICD‑10‑CM + CPT** only, with static rule set. | 8 weeks | Working UI overlay in a sandbox EHR, logging pipeline, basic audit dashboard. |\n",
"| **3️⃣ Validation & Safety** | Run **dual‑run**: AI suggestions **parallel** to existing manual coding for 2 weeks. Measure **agreement** and **false‑positive rate**. | 2 weeks | Accuracy report (target ≥ 90 % match), revised confidence thresholds. |\n",
"| **4️⃣ Live Pilot** | Deploy to **10 clinicians** in the chosen department. Capture **time‑saved**, **denial reduction**, **user satisfaction**. | 6 weeks | KPI dashboard (time per note, claim denial %), NPS score. |\n",
"| **5️⃣ Scale‑Readiness** | Incorporate **payer‑specific modifiers**, extend to **DRG** for inpatient stays, add **auto‑billing** push. | 8 weeks | Full rule engine, multi‑payer support, documentation for IT ops. |\n",
"\n",
"**Success Metrics (to be reported after 6‑week live pilot)** \n",
"\n",
"| KPI | Baseline | Target | Measurement |\n",
"|-----|----------|--------|--------------|\n",
"| Avg. chart‑completion → coded claim time | 22 min | ≤ 14 min (≈ 35 % reduction) | Timestamp diff in EHR logs |\n",
"| Coding accuracy (vs. audit) | 84 % | ≥ 93 % | Random chart audit (n = 200) |\n",
"| Claim denial rate (target service line) | 12 % | ≤ 6 % | Billing system denial reports |\n",
"| Clinician “coding fatigue” score (survey) | 4.2/5 (high) | ≤ 2.8/5 | 5‑point Likert post‑pilot |\n",
"| ROI (per‑provider) | $0 | ≥ $12k/yr (based on time saved & extra capture) | Salary cost + additional revenue |\n",
"\n",
"--- \n",
"\n",
"## 9️⃣ Operational & Governance Model \n",
"\n",
"| Role | Responsibility |\n",
"|------|----------------|\n",
"| **Product Owner (Clinical Ops)** | Prioritise coding rules, define KPIs, manage clinician feedback. |\n",
"| **AI Engineering Lead** | Maintain Orchestrator, LLM prompts, model versioning, drift pipeline. |\n",
"| **Compliance Officer** | Review policy updates, audit logs, ensure HIPAA & payer contracts are met. |\n",
"| **EHR Integration Team** | Manage SMART‑on‑FHIR app registration, UI embedding, API versioning. |\n",
"| **Clinical Coding Specialist** | Curate rule base, adjudicate edge‑case disagreements, supervise learning data. |\n",
"| **Data Security Engineer** | VPC hardening, key management, incident‑response playbooks. |\n",
"\n",
"--- \n",
"\n",
"## 10️⃣ Technology Stack Summary \n",
"\n",
"| Layer | Preferred Tech (AWS‑centric) |\n",
"|-------|------------------------------|\n",
"| **Compute** | Amazon ECS (Fargate) for stateless services, EC2 GPU instances for on‑prem LLM inference (if needed). |\n",
"| **LLM** | OpenAI GPT‑4o (HIPAA‑covered) **or** on‑prem Llama 3‑8B‑Chat with NVIDIA T4 GPUs (encrypted at rest). |\n",
"| **Knowledge Graph** | Neo4j Aura (managed) storing ICD‑10, CPT hierarchies, payer rule edges. |\n",
"| **Rule Engine** | Drools (Java) + OPA policies (JSON‑OPA). |\n",
"| **Data Lake** | Amazon S3 (object lock, SSE‑KMS). |\n",
"| **Orchestration** | AWS Step Functions +\n"
]
}
],
"source": [
"from dotenv import load_dotenv\n",
"import os\n",
"\n",
"load_dotenv()\n",
"\n",
"groq_api=os.getenv(\"GROQ_API_KEY\")\n",
"\n",
"from groq import Groq\n",
"\n",
"\n",
"client=Groq()\n",
"response=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=1.4,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':'pick a business area that might be worth exploring for an Agentic AI opportunity'\n",
" }]\n",
")\n",
"bussiness_idea=response.choices[0].message.content\n",
"response=client.chat.completions.create(\n",
" model='groq/compound-mini',\n",
" temperature=0.8,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':f\"\"\"\n",
" bussiness_idea={bussiness_idea}\n",
" present a pain-point in that industry - something challenging that might be ripe for an Agentic solution\"\"\"\n",
" }]\n",
")\n",
"pinpoint=response.choices[0].message.content\n",
"response=client.chat.completions.create(\n",
" model='openai/gpt-oss-120b',\n",
" temperature=0.8,\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':f\"\"\"\n",
" bussiness_idea={bussiness_idea}\n",
" pinpoint={pinpoint}\n",
" propose the Agentic AI solution\"\"\"\n",
" }]\n",
") \n",
"solution=response.choices[0].message.content\n",
"print(solution)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "cd0c55e6",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"google_api=os.getenv(\"GOOGLE_API_KEY\")\n",
"if google_api:\n",
" print(\"hello , all set\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d3d722e8",
"metadata": {},
"outputs": [
{
"ename": "GroqError",
"evalue": "The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mGroqError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 7\u001b[39m\n\u001b[32m 4\u001b[39m load_dotenv(override=\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[32m 5\u001b[39m groq_apo=os.getenv(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m----> \u001b[39m\u001b[32m7\u001b[39m client = \u001b[43mGroq\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 8\u001b[39m response=client.chat.completions.create(\n\u001b[32m 9\u001b[39m model=\u001b[33m'\u001b[39m\u001b[33mllama-3.3-70b-versatile\u001b[39m\u001b[33m'\u001b[39m,\n\u001b[32m 10\u001b[39m messages=[{\n\u001b[32m (...)\u001b[39m\u001b[32m 13\u001b[39m }]\n\u001b[32m 14\u001b[39m )\n\u001b[32m 15\u001b[39m \u001b[38;5;28mprint\u001b[39m(response.choices[\u001b[32m0\u001b[39m].message.content)\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_client.py:83\u001b[39m, in \u001b[36mGroq.__init__\u001b[39m\u001b[34m(self, api_key, base_url, timeout, max_retries, default_headers, default_query, http_client, _strict_response_validation)\u001b[39m\n\u001b[32m 81\u001b[39m api_key = os.environ.get(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 82\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m api_key \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m83\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m GroqError(\n\u001b[32m 84\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mThe api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 85\u001b[39m )\n\u001b[32m 86\u001b[39m \u001b[38;5;28mself\u001b[39m.api_key = api_key\n\u001b[32m 88\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m base_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
"\u001b[31mGroqError\u001b[39m: The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable"
]
}
],
"source": [
"from dotenv import load_dotenv\n",
"from groq import Groq\n",
"import os\n",
"load_dotenv(override=True)\n",
"groq_apo=os.getenv(\"GROQ_API_KEY\")\n",
"\n",
"client = Groq()\n",
"response=client.chat.completions.create(\n",
" model='llama-3.3-70b-versatile',\n",
" messages=[{\n",
" 'role':'user',\n",
" 'content':'explain about yourself'\n",
" }]\n",
")\n",
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"id": "ad9dd9c2",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "7703702a",
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"from groq import Groq\n",
"import json\n",
"import os\n",
"import requests\n",
"from pypdf import PdfReader\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "220a7fe3",
"metadata": {},
"outputs": [],
"source": [
"load_dotenv(override=True)\n",
"groq_api_key=os.getenv('GROQ_API_KEY')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5e5c9b5d",
"metadata": {},
"outputs": [
{
"ename": "GroqError",
"evalue": "The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mGroqError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[10]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m client=\u001b[43mGroq\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32mc:\\Users\\govindh vaila\\projects\\agents\\.venv\\Lib\\site-packages\\groq\\_client.py:83\u001b[39m, in \u001b[36mGroq.__init__\u001b[39m\u001b[34m(self, api_key, base_url, timeout, max_retries, default_headers, default_query, http_client, _strict_response_validation)\u001b[39m\n\u001b[32m 81\u001b[39m api_key = os.environ.get(\u001b[33m\"\u001b[39m\u001b[33mGROQ_API_KEY\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 82\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m api_key \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[32m---> \u001b[39m\u001b[32m83\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m GroqError(\n\u001b[32m 84\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mThe api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 85\u001b[39m )\n\u001b[32m 86\u001b[39m \u001b[38;5;28mself\u001b[39m.api_key = api_key\n\u001b[32m 88\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m base_url \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n",
"\u001b[31mGroqError\u001b[39m: The api_key client option must be set either by passing api_key to the client or by setting the GROQ_API_KEY environment variable"
]
}
],
"source": [
"if groq_api_key:\n",
" print(\"all set\")\n",
"else:\n",
" print(\"no\") \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f36a35b",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.12.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}