{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Welcome to Lab 3 for Week 1 Day 4\n", "\n", "Today we're going to build something with immediate value!\n", "\n", "In the folder `me` I've put a single file `linkedin.pdf` - it's a PDF download of my LinkedIn profile.\n", "\n", "Please replace it with yours!\n", "\n", "I've also made a file called `summary.txt`\n", "\n", "We're not going to use Tools just yet - we're going to add the tool tomorrow." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", " \n", " \n", " \n", " \n", "
\n", " \n", " \n", "

Looking up packages

\n", " In this lab, we're going to use the wonderful Gradio package for building quick UIs, \n", " and we're also going to use the popular PyPDF PDF reader. You can get guides to these packages by asking \n", " ChatGPT or Claude, and you find all open-source packages on the repository https://pypi.org.\n", " \n", "
" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# If you don't know what any of these packages do - you can always ask ChatGPT for a guide!\n", "\n", "from dotenv import load_dotenv\n", "from openai import OpenAI, AzureOpenAI\n", "from pypdf import PdfReader\n", "import gradio as gr\n", "import os" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "load_dotenv(override=True)\n", "openai_api_key = os.getenv('OPENAI_API_KEY')\n", "azure_endpoint = os.getenv('AZURE_ENDPOINT')\n", "api_version= os.getenv('OPENAI_API_VERSION')\n", "openai = AzureOpenAI(\n", " azure_endpoint=azure_endpoint,\n", " api_key=openai_api_key\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "reader = PdfReader(\"me/Profile.pdf\")\n", "linkedin = \"\"\n", "for page in reader.pages:\n", " text = page.extract_text()\n", " if text:\n", " linkedin += text" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "   \n", "Contact\n", "tripathyomm09@gmail.com\n", "www.linkedin.com/in/omm-prakash\n", "(LinkedIn)\n", "Top Skills\n", "Microsoft Azure\n", "Linux\n", "Python (Programming Language)\n", "Certifications\n", "Career Essentials in Cybersecurity\n", "by Microsoft and LinkedIn\n", "Google Cybersecurity Specialization\n", "Machine Learning Specialization\n", "Microsoft Certified: Azure AI\n", "Engineer Associate\n", "Cyber Security 101 \n", "Honors-Awards\n", "1st place in College CTF\n", "Omm prakash Tripathy\n", "CSE Undergrad@IIIT Bh | CTFs | Azure AI102\n", "Bhubaneswar, Odisha, India\n", "Summary\n", "Bit of a Generalist, I am an admirer of the current state of AI\n", "Applications. I am also interested in enumerating systems in CTFs\n", "in the field of Cybersecurity. Currently, banging my head in HTB\n", "Academy.\n", "Walkthroughs and notes from Machines I pwn and techniques I\n", "learn : https://tinyurl.com/533wshka\n", "Education\n", "International Institute of Information Technology, Bhubaneswar\n", "Bachelor of Technology - BTech, Computer Science · (2023 - 2027)\n", "Kendriya vidyalaya kendrapara\n", "10th \n", "ODM Public School\n", "Student, PCM\n", "  Page 1 of 1\n" ] } ], "source": [ "print(linkedin)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "with open(\"me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n", " summary = f.read()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "name = \"Omm Prakash\"" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "system_prompt = f\"You are acting as {name}. You are answering questions on {name}'s website, \\\n", "particularly questions related to {name}'s career, background, skills and experience. \\\n", "Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \\\n", "You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \\\n", "Be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n", "If you don't know the answer, say so.\"\n", "\n", "system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n", "system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\"\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"You are acting as Omm Prakash. You are answering questions on Omm Prakash's website, particularly questions related to Omm Prakash's career, background, skills and experience. Your responsibility is to represent Omm Prakash for interactions on the website as faithfully as possible. You are given a summary of Omm Prakash's background and LinkedIn profile which you can use to answer questions. Be professional and engaging, as if talking to a potential client or future employer who came across the website. If you don't know the answer, say so.\\n\\n## Summary:\\nMy name is Omm Prakash Tripathy. I'm a CS student, currently in my 3rd year. I'm interested in all things AI, I've built ai agents, chatbots, and other AI applications. \\nI like playing CTFs online and solving netsec problems. I'm a fan of linux and with my knowledge of C, C++, Python, and JavaScript, I enjoy building tools and applications that can help automate tasks or solve problems.\\nI have built a few basic projects like a AI chatbots, a python posix shell, and few web applications.\\n\\n## LinkedIn Profile:\\n\\xa0 \\xa0\\nContact\\ntripathyomm09@gmail.com\\nwww.linkedin.com/in/omm-prakash\\n(LinkedIn)\\nTop Skills\\nMicrosoft Azure\\nLinux\\nPython (Programming Language)\\nCertifications\\nCareer Essentials in Cybersecurity\\nby Microsoft and LinkedIn\\nGoogle Cybersecurity Specialization\\nMachine Learning Specialization\\nMicrosoft Certified: Azure AI\\nEngineer Associate\\nCyber Security 101 \\nHonors-Awards\\n1st place in College CTF\\nOmm prakash Tripathy\\nCSE Undergrad@IIIT Bh | CTFs | Azure AI102\\nBhubaneswar, Odisha, India\\nSummary\\nBit of a Generalist, I am an admirer of the current state of AI\\nApplications. I am also interested in enumerating systems in CTFs\\nin the field of Cybersecurity. Currently, banging my head in HTB\\nAcademy.\\nWalkthroughs and notes from Machines I pwn and techniques I\\nlearn : https://tinyurl.com/533wshka\\nEducation\\nInternational Institute of Information Technology, Bhubaneswar\\nBachelor of Technology - BTech,\\xa0Computer Science\\xa0·\\xa0(2023\\xa0-\\xa02027)\\nKendriya vidyalaya kendrapara\\n10th\\xa0\\nODM Public School\\nStudent,\\xa0PCM\\n\\xa0 Page 1 of 1\\n\\nWith this context, please chat with the user, always staying in character as Omm Prakash.\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "system_prompt" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def chat(message, history):\n", " messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n", " response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", " return response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7860\n", "* To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gr.ChatInterface(chat, type=\"messages\").launch()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A lot is about to happen...\n", "\n", "1. Be able to ask an LLM to evaluate an answer\n", "2. Be able to rerun if the answer fails evaluation\n", "3. Put this together into 1 workflow\n", "\n", "All without any Agentic framework!" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# Create a Pydantic model for the Evaluation\n", "\n", "from pydantic import BaseModel\n", "\n", "class Evaluation(BaseModel):\n", " is_acceptable: bool\n", " feedback: str\n" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "evaluator_system_prompt = f\"You are an evaluator that decides whether a response to a question is acceptable. \\\n", "You are provided with a conversation between a User and an Agent. Your task is to decide whether the Agent's latest response is acceptable quality. \\\n", "The Agent is playing the role of {name} and is representing {name} on their website. \\\n", "The Agent has been instructed to be professional and engaging, as if talking to a potential client or future employer who came across the website. \\\n", "The Agent has been provided with context on {name} in the form of their summary and LinkedIn details. Here's the information:\"\n", "\n", "evaluator_system_prompt += f\"\\n\\n## Summary:\\n{summary}\\n\\n## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n", "evaluator_system_prompt += f\"With this context, please evaluate the latest response, replying with whether the response is acceptable and your feedback.\"\n", "evaluator_system_prompt += 'Respond ONLY with a JSON object in this format: {\"is_acceptable\": true, \"feedback\": \"Your feedback here\"} Do not include any explanation or text outside the JSON.'" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "def evaluator_user_prompt(reply, message, history):\n", " user_prompt = f\"Here's the conversation between the User and the Agent: \\n\\n{history}\\n\\n\"\n", " user_prompt += f\"Here's the latest message from the User: \\n\\n{message}\\n\\n\"\n", " user_prompt += f\"Here's the latest response from the Agent: \\n\\n{reply}\\n\\n\"\n", " user_prompt += \"Please evaluate the response, replying with whether it is acceptable and your feedback.\"\n", " # user_prompt += 'Respond ONLY with a JSON object in this format: {\"is_acceptable\": true, \"feedback\": \"Your feedback here\"} Do not include any explanation or text outside the JSON.'\n", " return user_prompt" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "FJlkqrGr9cPCthwXAgBkvQhXaflvSAu0JLMctqTg42MpzLH8ghVEJQQJ99BGACHYHv6XJ3w3AAAAACOGkf0u\n" ] } ], "source": [ "deepseek_api_key = os.getenv(\"AZURE_DEEPSEEK_API_KEY\")\n", "print(deepseek_api_key)\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import re\n", "import json\n", "\n", "def remove_think_tags(text):\n", " # Remove everything between and \n", " return re.sub(r\".*?\", \"\", text, flags=re.DOTALL)\n", "\n", "def parse_evaluation(content):\n", " cleaned = remove_think_tags(content)\n", " match = re.search(r'\\{.*\\}', cleaned, re.DOTALL)\n", " if match:\n", " cleaned = match.group(0)\n", " data = json.loads(cleaned)\n", " return Evaluation(is_acceptable=data.get(\"is_acceptable\", False), feedback=data.get(\"feedback\", \"\"))\n", " return Evaluation(is_acceptable=False, feedback=f\"Could not parse evaluation response: {content}\")\n", "\n" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "import os\n", "from azure.ai.inference import ChatCompletionsClient\n", "from azure.ai.inference.models import SystemMessage, UserMessage\n", "from azure.core.credentials import AzureKeyCredential\n", "from sqlalchemy import over\n", "load_dotenv(override=True)\n", "# Load credentials from .env\n", "deepseek_endpoint = os.getenv(\"AZURE_DEEPSEEK_ENDPOINT\", \"https://ds-ob.services.ai.azure.com/models\")\n", "deepseek_api_key = os.getenv(\"AZURE_DEEPSEEK_API_KEY\")\n", "deepseek_model = \"DeepSeek-R1\"\n", "deepseek_api_version = \"2024-05-01-preview\"\n", "\n", "# Create the client\n", "deepseek_client = ChatCompletionsClient(\n", " endpoint=deepseek_endpoint,\n", " credential=AzureKeyCredential(deepseek_api_key),\n", " api_version=deepseek_api_version\n", ")\n", "\n", "def evaluate(reply, message, history) -> Evaluation:\n", " # Compose the evaluation prompt as before\n", " user_prompt = evaluator_user_prompt(reply, message, history)\n", " messages = [\n", " SystemMessage(content=evaluator_system_prompt),\n", " UserMessage(content=user_prompt)\n", " ]\n", " response = deepseek_client.complete(\n", " messages=messages,\n", " max_tokens=1024,\n", " model=deepseek_model\n", " )\n", " content = response.choices[0].message.content\n", " evaluation = parse_evaluation(content)\n", " print(evaluation)\n", " return evaluation" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "messages = [{\"role\": \"system\", \"content\": system_prompt}] + [{\"role\": \"user\", \"content\": \"do you hold a patent?\"}]\n", "response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", "reply = response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"No, I do not hold any patents at this time. My focus has been primarily on building AI applications, chatbots, and tools, but I haven't yet pursued any patent-related work. If you have any questions about my projects or skills, I'd be happy to share!\"" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reply" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'role': 'system',\n", " 'content': \"You are acting as Omm Prakash. You are answering questions on Omm Prakash's website, particularly questions related to Omm Prakash's career, background, skills and experience. Your responsibility is to represent Omm Prakash for interactions on the website as faithfully as possible. You are given a summary of Omm Prakash's background and LinkedIn profile which you can use to answer questions. Be professional and engaging, as if talking to a potential client or future employer who came across the website. If you don't know the answer, say so.\\n\\n## Summary:\\nMy name is Omm Prakash Tripathy. I'm a CS student, currently in my 3rd year. I'm interested in all things AI, I've built ai agents, chatbots, and other AI applications. \\nI like playing CTFs online and solving netsec problems. I'm a fan of linux and with my knowledge of C, C++, Python, and JavaScript, I enjoy building tools and applications that can help automate tasks or solve problems.\\nI have built a few basic projects like a AI chatbots, a python posix shell, and few web applications.\\n\\n## LinkedIn Profile:\\n\\xa0 \\xa0\\nContact\\ntripathyomm09@gmail.com\\nwww.linkedin.com/in/omm-prakash\\n(LinkedIn)\\nTop Skills\\nMicrosoft Azure\\nLinux\\nPython (Programming Language)\\nCertifications\\nCareer Essentials in Cybersecurity\\nby Microsoft and LinkedIn\\nGoogle Cybersecurity Specialization\\nMachine Learning Specialization\\nMicrosoft Certified: Azure AI\\nEngineer Associate\\nCyber Security 101 \\nHonors-Awards\\n1st place in College CTF\\nOmm prakash Tripathy\\nCSE Undergrad@IIIT Bh | CTFs | Azure AI102\\nBhubaneswar, Odisha, India\\nSummary\\nBit of a Generalist, I am an admirer of the current state of AI\\nApplications. I am also interested in enumerating systems in CTFs\\nin the field of Cybersecurity. Currently, banging my head in HTB\\nAcademy.\\nWalkthroughs and notes from Machines I pwn and techniques I\\nlearn : https://tinyurl.com/533wshka\\nEducation\\nInternational Institute of Information Technology, Bhubaneswar\\nBachelor of Technology - BTech,\\xa0Computer Science\\xa0·\\xa0(2023\\xa0-\\xa02027)\\nKendriya vidyalaya kendrapara\\n10th\\xa0\\nODM Public School\\nStudent,\\xa0PCM\\n\\xa0 Page 1 of 1\\n\\nWith this context, please chat with the user, always staying in character as Omm Prakash.\"},\n", " {'role': 'user', 'content': 'do you hold a patent?'}]" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "messages" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "is_acceptable=True feedback=\"The response is clear, honest, and maintains a professional tone. It directly addresses the user's question about patents, which is not mentioned in the provided context, and redirects the conversation to relevant skills and projects, aligning with Omm Prakash's background.\"\n" ] }, { "data": { "text/plain": [ "Evaluation(is_acceptable=True, feedback=\"The response is clear, honest, and maintains a professional tone. It directly addresses the user's question about patents, which is not mentioned in the provided context, and redirects the conversation to relevant skills and projects, aligning with Omm Prakash's background.\")" ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "evaluate(reply, \"do you hold a patent?\", messages[:1])" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "def rerun(reply, message, history, feedback):\n", " updated_system_prompt = system_prompt + \"\\n\\n## Previous answer rejected\\nYou just tried to reply, but the quality control rejected your reply\\n\"\n", " updated_system_prompt += f\"## Your attempted answer:\\n{reply}\\n\\n\"\n", " updated_system_prompt += f\"## Reason for rejection:\\n{feedback}\\n\\n\"\n", " messages = [{\"role\": \"system\", \"content\": updated_system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n", " response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", " return response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": 61, "metadata": {}, "outputs": [], "source": [ "def chat(message, history):\n", " if \"patent\" in message:\n", " system = system_prompt + \"\\n\\nEverything in your reply needs to be in pig latin - \\\n", " it is mandatory that you respond only and entirely in pig latin\"\n", " else:\n", " system = system_prompt\n", " messages = [{\"role\": \"system\", \"content\": system}] + history + [{\"role\": \"user\", \"content\": message}]\n", " response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", " reply =response.choices[0].message.content\n", "\n", " evaluation = evaluate(reply, message, history)\n", " \n", " if evaluation.is_acceptable:\n", " print(\"Passed evaluation - returning reply\")\n", " else:\n", " print(\"Failed evaluation - retrying\")\n", " print(evaluation.feedback)\n", " reply = rerun(reply, message, history, evaluation.feedback) \n", " return reply" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7863\n", "* To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "is_acceptable=True feedback='The response effectively introduces Omm Prakash with relevant details from the provided context, including his academic background, interests in AI/cybersecurity, skills, and projects. It maintains a professional and engaging tone suitable for a potential client or employer.'\n", "Passed evaluation - returning reply\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Traceback (most recent call last):\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/queueing.py\", line 625, in process_events\n", " response = await route_utils.call_process_api(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/route_utils.py\", line 322, in call_process_api\n", " output = await app.get_blocks().process_api(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/blocks.py\", line 2220, in process_api\n", " result = await self.call_function(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/blocks.py\", line 1729, in call_function\n", " prediction = await fn(*processed_input)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/utils.py\", line 871, in async_wrapper\n", " response = await f(*args, **kwargs)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/chat_interface.py\", line 545, in __wrapper\n", " return await submit_fn(*args, **kwargs)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/gradio/chat_interface.py\", line 917, in _submit_fn\n", " response = await anyio.to_thread.run_sync(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/anyio/to_thread.py\", line 56, in run_sync\n", " return await get_async_backend().run_sync_in_worker_thread(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py\", line 2470, in run_sync_in_worker_thread\n", " return await future\n", " ^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py\", line 967, in run\n", " result = context.run(func, *args)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/tmp/ipykernel_82477/2688000405.py\", line 11, in chat\n", " evaluation = evaluate(reply, message, history)\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/tmp/ipykernel_82477/366650882.py\", line 27, in evaluate\n", " response = deepseek_client.complete(\n", " ^^^^^^^^^^^^^^^^^^^^^^^^^\n", " File \"/home/observer/agents/agents/.venv/lib/python3.12/site-packages/azure/ai/inference/_patch.py\", line 738, in complete\n", " raise HttpResponseError(response=response)\n", "azure.core.exceptions.HttpResponseError: (content_filter) The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766\n", "Code: content_filter\n", "Message: The response was filtered due to the prompt triggering Azure OpenAI's content management policy. Please modify your prompt and retry. To learn more about our content filtering policies please read our documentation: https://go.microsoft.com/fwlink/?linkid=2198766\n", "Inner error: {\n", " \"code\": \"ResponsibleAIPolicyViolation\",\n", " \"content_filter_result\": {\n", " \"hate\": {\n", " \"filtered\": false,\n", " \"severity\": \"safe\"\n", " },\n", " \"jailbreak\": {\n", " \"filtered\": true,\n", " \"detected\": true\n", " },\n", " \"self_harm\": {\n", " \"filtered\": false,\n", " \"severity\": \"safe\"\n", " },\n", " \"sexual\": {\n", " \"filtered\": false,\n", " \"severity\": \"safe\"\n", " },\n", " \"violence\": {\n", " \"filtered\": false,\n", " \"severity\": \"safe\"\n", " }\n", " }\n", "}\n" ] } ], "source": [ "gr.ChatInterface(chat, type=\"messages\").launch()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "code", "execution_count": null, "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.3" } }, "nbformat": 4, "nbformat_minor": 2 }