{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "cc295f7f", "metadata": {}, "outputs": [], "source": [ "from openai import OpenAI" ] }, { "cell_type": "code", "execution_count": 3, "id": "cf64d29f", "metadata": {}, "outputs": [], "source": [ "messages = [{\"role\": \"user\", \"content\": \"What is the capital of France?\"}]" ] }, { "cell_type": "code", "execution_count": 4, "id": "e6d3f271", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The capital of France is Paris.\n" ] } ], "source": [ "ollama = OpenAI(base_url='http://localhost:11434/v1', api_key='ollama')\n", "model_name = \"llama3.2\"\n", "\n", "response = ollama.chat.completions.create(model=model_name, messages=messages)\n", "answer = response.choices[0].message.content\n", "\n", "print(answer)" ] }, { "cell_type": "code", "execution_count": 14, "id": "adaa6df1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from dotenv import load_dotenv\n", "from pypdf import PdfReader\n", "import gradio as gr\n", "from openai import OpenAI\n", "import os\n", "\n", "load_dotenv(override=True)" ] }, { "cell_type": "code", "execution_count": 15, "id": "60108c91", "metadata": {}, "outputs": [], "source": [ "gemini = OpenAI(\n", " api_key=os.getenv(\"GOOGLE_API_KEY\"), \n", " base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n", ")" ] }, { "cell_type": "code", "execution_count": 16, "id": "47c4ba19", "metadata": {}, "outputs": [], "source": [ "reader = PdfReader(\"linkedin.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": 17, "id": "a0eb927b", "metadata": {}, "outputs": [], "source": [ "name = \"Surbhit Kumar\"" ] }, { "cell_type": "code", "execution_count": 18, "id": "45de1de0", "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 background and LinkedIn profile of {name}'s 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\"## 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": 20, "id": "b26dabc1", "metadata": {}, "outputs": [], "source": [ "def chat(message, history):\n", " messages = [{\"role\": \"system\", \"content\": system_prompt}] + history + [{\"role\": \"user\", \"content\": message}]\n", " response = gemini.beta.chat.completions.parse(model=\"gemini-2.0-flash\", messages=messages)\n", " return response.choices[0].message.content" ] }, { "cell_type": "code", "execution_count": 21, "id": "a3e34a87", "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": [ "