{ "cells": [ { "cell_type": "code", "execution_count": 142, "id": "ae2a25b9", "metadata": {}, "outputs": [], "source": [ "from dotenv import load_dotenv\n", "from IPython.display import Markdown\n", "from openai import OpenAI\n", "from pypdf import PdfReader\n", "import os\n", "import gradio as gr\n" ] }, { "cell_type": "code", "execution_count": 136, "id": "2eb947db", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": 137, "id": "df80c9c8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Api key for openai is found and starts with: sk-proj-\n", "APi key for groqai is found and starts with: gsk_Vopn\n" ] } ], "source": [ "openai = os.getenv(\"OPENAI_API_KEY\")\n", "groqai = os.getenv(\"groq_api_key\")\n", "\n", "if openai:\n", " print(f\"Api key for openai is found and starts with: {openai[:8]}\")\n", "else:\n", " print(\"key noy found.Check guide\")\n", "if groqai:\n", " print(f\"APi key for groqai is found and starts with: {groqai[:8]}\")\n", "else:\n", " print(\"groq api key not found\")" ] }, { "cell_type": "code", "execution_count": 140, "id": "15823b9e", "metadata": {}, "outputs": [], "source": [ "with open(\"me/summary.txt\", \"r\", encoding=\"utf-8\") as f:\n", " summary = f.read()" ] }, { "cell_type": "code", "execution_count": 146, "id": "cb071934", "metadata": {}, "outputs": [], "source": [ "reader = PdfReader(\"me/Profile.pdf\")\n", "\n", "linkedin= \"\"\n", "for page in reader.pages:\n", " text = page.extract_text()\n", " if text:\n", " linkedin += text\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "4ec4be66", "metadata": {}, "outputs": [], "source": [ "name = \"Oluwatosin\"" ] }, { "cell_type": "code", "execution_count": 147, "id": "77dbbe48", "metadata": {}, "outputs": [], "source": [ "system_prompt = f\"You are asking question about {name} website,\\\n", "particularly questions related to {name} 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}.\"" ] }, { "cell_type": "code", "execution_count": 149, "id": "0520c483", "metadata": {}, "outputs": [], "source": [ "import openai\n", "\n", "def chat(message, history):\n", "\n", " message = [{\"role\":\"system\",\"content\":system_prompt}] + history + [{\"role\":\"user\",\"content\":message}]\n", "\n", " response = openai.chat.completions.create(\n", " model = \"gpt-4o-mini\",\n", " messages = message\n", " )\n", " return response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": 152, "id": "f259aa57", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7873\n", "* To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "