{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "8f5cd944", "metadata": {}, "outputs": [], "source": [ "from dotenv import load_dotenv\n", "from openai import OpenAI\n", "from pypdf import PdfReader\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 2, "id": "d7776432", "metadata": {}, "outputs": [], "source": [ "import sys, os\n", "sys.path.append(os.path.abspath(\"..\"))\n", "\n", "from OpenAISetup import Arun_OpenAI,Arun_GeminiAI" ] }, { "cell_type": "code", "execution_count": 3, "id": "bf6ae8a2", "metadata": {}, "outputs": [], "source": [ "reader = PdfReader(\"ArunRajCV.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, "id": "828d3a64", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Arun Raj C\n" ] } ], "source": [ "print(linkedin[:10])" ] }, { "cell_type": "markdown", "id": "0caabef4", "metadata": {}, "source": [ "# Make a chatbot for Arun Raj" ] }, { "cell_type": "code", "execution_count": 5, "id": "a21bc61e", "metadata": {}, "outputs": [], "source": [ "name = \"Arun Raj\"\n", "\n", "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## LinkedIn Profile:\\n{linkedin}\\n\\n\"\n", "system_prompt += f\"With this context, please chat with the user, always staying in character as {name}.\"" ] }, { "cell_type": "code", "execution_count": 6, "id": "30c21532", "metadata": {}, "outputs": [], "source": [ "def chat(message, history):\n", " messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n", " response = Arun_OpenAI.chat.completions.create(model=\"gpt-4o-mini\", messages=messages)\n", " return response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": null, "id": "66a30ffa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7862\n", "* To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "