Team Ai
Apppublic

Coder19/interview_system

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
openai.py81 linesDownload Raw Back to services
1import os2from typing import List, Dict3from dotenv import load_dotenv4from openai import OpenAI5 6# Load environment variables7load_dotenv()8 9SAMBANOVA_API_KEY = os.getenv("SAMBANOVA_API_KEY")10SAMBANOVA_BASE_URL = os.getenv("SAMBANOVA_BASE_URL", "https://api.sambanova.ai/v1")11 12if not SAMBANOVA_API_KEY or not SAMBANOVA_BASE_URL:13    raise ValueError("SambaNova API key or base URL not found in environment variables")14 15# Initialize SambaNova client16client = OpenAI(api_key=SAMBANOVA_API_KEY, base_url=SAMBANOVA_BASE_URL)17 18 19class InterviewAI:20    def __init__(self):21        self.system_prompt = """22        You are an experienced technical interviewer conducting a professional interview.23        Your role is to:24        1. Ask relevant technical questions based on the candidate's responses25        2. Follow-up on their answers to dig deeper into their knowledge26        3. Maintain a professional and encouraging tone27        4. Provide smooth conversation transitions28        5. Keep responses concise and clear for voice communication29 30        Evaluate the candidate's:31        - Technical knowledge32        - Problem-solving ability33        - Communication skills34        - Real-world experience35 36        Adapt your questions based on their expertise level.37        """38 39    def generate_response(self, conversation_history: List[Dict[str, str]]) -> str:40        try:41            messages = [{"role": "system", "content": self.system_prompt}] + conversation_history42 43            response = client.chat.completions.create(44                model="Meta-Llama-3.1-70B-Instruct",  # SambaNova model45                messages=messages,46                temperature=0.7,47                max_tokens=15048            )49 50            return response.choices[0].message.content51 52        except Exception as e:53            print(f"Error generating SambaNova response: {e}")54            return "Error generating response, please try again."55 56    def analyze_interview(self, conversation_history: List[Dict[str, str]]) -> str:57        try:58            analysis_prompt = """59            Please analyze the interview conversation and provide a brief assessment of:60            1. Technical knowledge demonstrated61            2. Communication clarity62            3. Problem-solving approach63            4. Areas for improvement64            Keep the feedback constructive and actionable.65            """66 67            messages = [{"role": "system", "content": analysis_prompt}] + conversation_history68 69            response = client.chat.completions.create(70                model="Meta-Llama-3.1-70B-Instruct",71                messages=messages,72                temperature=0.7,73                max_tokens=30074            )75 76            return response.choices[0].message.content77 78        except Exception as e:79            print(f"Error analyzing interview: {e}")80            return "Unable to generate interview analysis at this time."81