| import requests |
| import google.generativeai as genai |
| import os |
| from dotenv import load_dotenv |
|
|
| |
| |
| ROOT_DIR = os.environ.get('WORKSPACE_ROOT', '.') |
| env_address = os.path.join(ROOT_DIR, 'backend/.env') |
| load_dotenv(dotenv_path=env_address) |
|
|
| |
| GEMINI_API_KEY = os.environ.get("GEMINI_API_KEY") |
| JINA_API_KEY = os.environ.get("JINA_API_KEY") |
|
|
| genai.configure(api_key=GEMINI_API_KEY) |
|
|
| def scrape_website_to_markdown(url: str) -> str: |
| """ |
| Uses Jina Reader API to cleanly extract text from any URL. |
| It automatically strips out ads, navbars, and messy HTML. |
| """ |
| print(f"π΅οΈββοΈ Scraping {url}...") |
| jina_url = f"https://r.jina.ai/{url}" |
| |
| headers = { |
| |
| "Authorization": f"Bearer {JINA_API_KEY}", |
| "X-Retain-Images": "none" |
| } |
| |
| response = requests.get(jina_url, headers=headers) |
| |
| if response.status_code == 200: |
| return response.text |
| else: |
| raise Exception(f"Failed to scrape website. Status code: {response.status_code}\nResponse: {response.text}") |
|
|
| def generate_interview_answer(company_text: str, company_website: str, max_chars: int = 10000) -> str: |
| """ |
| Feeds the scraped text into the LLM with a highly specific prompt. |
| Safely truncates the text to avoid API Quota limit errors. |
| """ |
| |
| if len(company_text) > max_chars: |
| print(f"βοΈ Truncating scraped text from {len(company_text)} to {max_chars} characters...") |
| company_text = company_text[:max_chars] |
| |
| print("π§ Synthesizing data and drafting answer...") |
| |
| |
| model = genai.GenerativeModel('gemini-flash-lite-latest') |
| |
| prompt = f""" |
| You are an intelligent, well-prepared job bot for {company_website}. |
| |
| I am going to provide you with the scraped text from their official website. |
| Based ONLY on this text, I want you to answer the classic question: |
| "What things company working on and what is their mission? What is their focus and what is there vision?" |
| |
| Guidelines for your answer: |
| 1. Keep it conversational, confident, and professional (around 3-4 short paragraphs). |
| 2. Identify their core product/service and who their target audience is. |
| 3. Highlight their overarching mission or the main problem they are trying to solve. |
| 4. Mention any recent milestones, unique features, or company values explicitly stated in the text. |
| 5. Do not hallucinate external information. If a detail isn't in the text, don't invent it. |
| |
| Here is the company website text: |
| ----------------------------------- |
| {company_text} |
| """ |
| |
| response = model.generate_content(prompt) |
| return response.text |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |