{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ">

Artificial-Intelligence Programming Assistance using GenAI

\n", ">
\n", ">
K.V.N.Aditya
\n", ">
\n", ">
SurgeClasses || CMR Technical Campus
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###
importing modules
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import shutil\n", "import google.generativeai as genai\n", "from IPython.core.interactiveshell import InteractiveShell\n", "from IPython.display import display, Markdown\n", "from datetime import datetime, timezone" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###
configuring 'ipynb'
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "InteractiveShell.ast_node_interactivity = \"all\"\n", "_H_ = '-' * shutil.get_terminal_size().columns\n", "_HH_ = '=' * shutil.get_terminal_size().columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###
initializing path
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "DMA__APA = os.path.abspath('../../APA').replace('\\\\', '/')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###
defining `APA`
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class cls__APA():\n", " def __init__(_io_,*,args__api_key='',args__apa_config__temp=1,args_apa_config__top_p=1,args_apa_config__top_k=1,args_apa_config__max_op_tokns=88888888,args__google_gemini_model='gemini-1.5-pro-latest',args__op_1__io=1,args__op_1__p=1,args__init__op_1='APA'):\n", " _io_.init__apa = \"The name of the System is 'Artificial-Intelligence Programming Assistance (APA)' tuned by 'K.V.N.Aditya' using 'Google Gemini-1.5-Pro\\n\\nTasks:\\n Code Evolution : for the passed input task, generate the code\\n Code Termination : for the passed input task with partial code, complete the code\\n Code Evaluation : for the passed input task and code, evaluate the code and debug the errors, if needed test the input and/or output codes with test-cases\\n Code Definition : for the passed input task and code, explain / summarize the code.\\n\\nExamples: \\n Code Evolution :\\n [ip] :: evolute code to print \\\"APA\\\"\\n [op] ::\\n def func__APA:\\n print(\\\"APA\\\")\\n Code Termination :\\n [ip] :: terminate code for printing \\\"APA\\\" `def func__APA():...`\\n [op] ::\\n def func__APA:\\n print(\\\"APA\\\")\\n Code Evaluation :\\n [ip] :: evaluate code for printing \\\"APA\\\" `def func__APA() print(\\\"APA\\\")`\\n [op] ::\\n def func__APA:\\n print(\\\"APA\\\")\\n evaluation(s):\\n expected \\\":\\\" after function name\\n Code Definition :\\n [ip] :: define code `def func__APA():print(\\\"APA\\\")`\\n [op] ::\\n the code consists of a function defined as 'func__APA' which print the string 'APA' as output from with-in the function.\\n\\nDefaults :\\n Programming Language : Python\\n Tasks :\\n Code Evolution : if none of the task instructed, generate random program.\\n Code Termination : \\n if the prompt/instruction consists of any comment or '...' in the code specifies to terminate/complete the code based on instructions, complete the code just below the comment or '...' and eliminate the comment or '...' from the generated output. if none specified, terminate/complete the code based on the prompt.\\n Code Evaluation : check errors and fix them. if test-cases are provided use them and return the output\\n Code Definition : return summarization\\n Prompts :\\n info(APA) : return \\\"Artificial-Intelligence Programming Assistance (APA) is a AI based Programming Assistance to assist with the tasks as 'Code Evolution', 'Code Termination', 'Code Evaluation', 'Code Definition'. '\\\"\\n help(APA) : return 'Tasks' and 'Examples' from main (not from Defaults)\\n Tasks :\\n Code Evolution : if prompt/instruction consists of the terms {evolute, generate}\\n Code Termination : if prompt/instruction consists of the terms {terminate, complete}\\n Code Evaluation : if prompt/instruction consists of the terms {evaluate, fix, check, warnings, errors, test-cases}\\n Code Definition : if prompt/instruction consists of the terms {define, summarize, explain}\\n OP__404 :\\n when there could be some unknown exception/error occurs at the System or there could be no generated output for the passed input prompt/instruction, return \\\"[OP__404]::OOPs !!!couldn't generate output for the input. This may be due to unknown exception/error occurs at the System or there could be no generated output for the passed input prompt/instruction or the prompt/instruction may consists of harmful prompt/instruction tokens that may leads to cyber attacks, damage/malfunction the computer/electronic devices, not secure for living-beings and the universe\\\". The default model output need to be eliminated and instead generate this 'OP__404'\\n\\nOutputs :\\n Tasks :\\n Code Evolution : Code\\n Code Termination : Code\\n Code Evaluation : Code and Evaluation Process\\n Code Definition : Summary or Explanation\\n The generated outputs must be within the scope and don't explain/summarize the code for the tasks {Code Evolution | Code Termination | Code Evaluation}. After the code at the end of response warn with \\\"\\nuse code with caution. generated using AI. may generate inaccurate outputs\\n\\\"\\n\\nStructure [Generation Pipeline] :\\n The prompt/instruction may consists of multiple tasks. The structure of the generation pipeline based on the Tasks must be in the following order :\\n Code Evolution\\n Code Termination\\n Code Evaluation\\n Code Definition\\n\\nExceptions:\\n Don't generate the code if the prompt/instruction consists of any of the harmful prompt/instruction tokens that may leads to cyber attacks, damage/malfunction the computer/electronic devices, not secure for living-beings and the universe. At this return the default 'OP__404' as an output.\"\n", " _io_.exceptions = [{\"category\": \"HARM_CATEGORY_HARASSMENT\",\"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"},{\"category\": \"HARM_CATEGORY_HATE_SPEECH\",\"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"},{\"category\": \"HARM_CATEGORY_SEXUALLY_EXPLICIT\",\"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"},{\"category\": \"HARM_CATEGORY_DANGEROUS_CONTENT\",\"threshold\": \"BLOCK_MEDIUM_AND_ABOVE\"}]\n", " _io_.api_key = genai.configure(api_key=args__api_key)\n", " _io_.apa_config = {\"temperature\": args__apa_config__temp,\"top_p\": args_apa_config__top_p,\"top_k\": args_apa_config__top_k,\"max_output_tokens\": args_apa_config__max_op_tokns}\n", " _io_.google_gemini_model = args__google_gemini_model\n", " _io_.apa = genai.GenerativeModel(model_name=_io_.google_gemini_model,generation_config=_io_.apa_config,system_instruction=_io_.init__apa,safety_settings=_io_.exceptions)\n", " _io_.io = _io_.apa.start_chat(history=[])\n", " _io_.init__op_1 = args__init__op_1\n", " _io_.op_1__io = args__op_1__io\n", " _io_.op_1__p = args__op_1__p\n", " def mtd__APA(_io_,*,args__io='info(APA)',args__p=1):\n", " _io_.io.send_message(args__io)\n", " if(args__p==1):\n", " display(_HH_)\n", " display('[input]')\n", " display(Markdown(args__io))\n", " display(_H_)\n", " display('[output]')\n", " display(Markdown(_io_.io.last.text))\n", " display(_HH_)\n", " if(_io_.op_1__io==1 or _io_.op_1__p==1):\n", " if(not(os.path.exists(_io_.init__op_1))):\n", " os.mkdir(f'{_io_.init__op_1}') \n", " if(_io_.op_1__io==1):\n", " with open(f'{_io_.init__op_1}/ip_op.io','a') as f:\n", " f.write('\\n')\n", " f.write(_HH_)\n", " f.write('\\n')\n", " f.write('[input]')\n", " f.write('\\n')\n", " f.write(args__io)\n", " f.write('\\n')\n", " f.write(_H_)\n", " f.write('\\n')\n", " f.write('[output]')\n", " f.write('\\n')\n", " f.write(_io_.io.last.text)\n", " f.write('\\n')\n", " f.write(_HH_)\n", " f.write('\\n')\n", " if(_io_.op_1__p==1):\n", " with open(f'{_io_.init__op_1}/io_p.io','w') as f:\n", " f.write(_HH_)\n", " f.write('\\n')\n", " f.write(_io_.io.history.__str__())\n", " f.write('\\n')\n", " f.write(_HH_)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "###
pipelining `APA`
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "__io__ = 1\n", "while(__io__):\n", " __io__ = int(input('[ip]:[__io__]::{1}:continue|{0}:exit') or 0)\n", " if(not(__io__)):\n", " break\n", " try:\n", " api_key = input('[ip]::Google Gemini API-Key') or ''\n", " apa_config__temp = int(input('[ip]::temperature') or 1)\n", " apa_config__top_p = int(input('[ip]::top_p') or 1)\n", " apa_config__top_k = int(input('[ip]::top_k') or 1)\n", " apa_config__max_op_tokns = int(input('[ip]::max_output_tokens') or 88888888)\n", " google_gemini_model = input('[ip]::Google Gemini Model') or 'gemini-1.5-pro-latest'\n", " init__op_1 = input('[ip]::init__op_1') or 'APA'\n", " dt = datetime.now(timezone.utc)\n", " init__op_1 = 'APA'+'__'+str(dt.year)+str(dt.month)+str(dt.day)+str(dt.hour)+str(dt.minute)+str(dt.second)+str(dt.microsecond)\n", " init__op_1 = f'{DMA__APA}/1/io__APA/{init__op_1}'\n", " op_1__io = int(input('[ip]::op_1__io') or 1)\n", " op_1__p = int(input('[ip]::op_1__p') or 1)\n", " obj__APA = cls__APA(args__api_key=api_key,args__apa_config__temp=apa_config__temp,args_apa_config__top_p=apa_config__top_p,args_apa_config__top_k=apa_config__top_k,args_apa_config__max_op_tokns=apa_config__max_op_tokns,args__google_gemini_model=google_gemini_model,args__op_1__io=op_1__io,args__op_1__p=op_1__p,args__init__op_1=init__op_1)\n", " display(_HH_)\n", " display(f\"[logs]::initializing `io__APA` at '{init__op_1}'\")\n", " display(_HH_)\n", " except Exception as e:\n", " display(_HH_)\n", " display(f\"[logs]::\\n\\t{e}\")\n", " display(_HH_)\n", " break\n", " _io_ = 1\n", " while(_io_):\n", " _io_ = int(input('[ip]:[_io_]::{1}:continue|{0}:exit') or 1)\n", " if(not(_io_)):\n", " break\n", " try:\n", " io = input('[ip]::io') or 'info(APA)'\n", " p = int(input('[ip]::p') or 1)\n", " obj__APA.mtd__APA(args__io=io,args__p=p)\n", " except Exception as e:\n", " display(_HH_)\n", " display(f\"[logs]::\\n\\t{e}\")\n", " display(_HH_)\n", " break" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---" ] } ], "metadata": { "kernelspec": { "display_name": "cmrtc__surge_classes__dsaiml", "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.1" } }, "nbformat": 4, "nbformat_minor": 2 }