Skip to content

Commit

Permalink
aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirAgassi committed Nov 24, 2024
1 parent 9a1de48 commit aa59b93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 7 additions & 4 deletions backend/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import dotenv
import os
from pathlib import Path
from dotenv import load_dotenv

dotenv.load_dotenv()
# load from the correct path
BASE_DIR = Path(__file__).resolve().parent
load_dotenv(BASE_DIR / '.env')

class Config:
USE_GROQ: bool = False
GROQ_API_KEY: str = os.getenv("GROQ_API_KEY", "")
USE_GROQ: bool = True
GROQ_API_KEY: str = os.getenv("GROQ_API_KEY")
MODEL_NAME: str = "meta-llama/Llama-3.2-3B-Instruct"
DEFAULT_MAX_TOKENS: int = 100
DEFAULT_TEMPERATURE: float = 0.5
Expand Down
9 changes: 8 additions & 1 deletion backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import database
from database import engine, get_db
from models import User, UserRole, Course, Section, Page, Enrollment, Quiz, QuizQuestion, QuizQuestionChoice, QuizResult # update imports
from utils.grok import query_grok, process_pdf_content, generate_quiz, generate_course_details
from utils.grok import query_grok, process_pdf_content, generate_quiz, generate_course_details, GROQ_API_KEY
from utils.pdf_processor import process_pdf, process_pdfs
import PyPDF2

Expand Down Expand Up @@ -1023,6 +1023,13 @@ async def submit_review_feedback(

return {"status": "success"}

@app.on_event("startup")
async def startup_event():
if not GROQ_API_KEY:
print("WARNING: GROQ_API_KEY not found in environment variables")
else:
print("GROQ_API_KEY loaded successfully")

if __name__ == "__main__":
uvicorn.run(
"main:app",
Expand Down
5 changes: 2 additions & 3 deletions backend/utils/grok.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ async def process_pdf_content(content: str) -> str:

async def query_grok_quiz(content: str) -> str:
try:
api_key = GROQ_API_KEY
if not api_key:
if not GROQ_API_KEY:
print("warning: groq_api_key not found")
return "Error: Missing API key"

Expand Down Expand Up @@ -178,7 +177,7 @@ async def query_grok_quiz(content: str) -> str:
}

headers = {
"Authorization": f"Bearer {api_key}",
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
}

Expand Down

0 comments on commit aa59b93

Please sign in to comment.