zeetay commited on
Commit
9abc49e
·
1 Parent(s): 889ca34

* working backend without llm output

Browse files
__init__.py ADDED
File without changes
__pycache__/__init__.cpython-313.pyc ADDED
Binary file (168 Bytes). View file
 
__pycache__/ai_prompts.cpython-313.pyc ADDED
Binary file (895 Bytes). View file
 
__pycache__/app.cpython-313.pyc ADDED
Binary file (3.18 kB). View file
 
__pycache__/utils.cpython-313.pyc ADDED
Binary file (1.42 kB). View file
 
app.py CHANGED
@@ -8,6 +8,15 @@ import logging
8
  import openai
9
  from .ai_prompts import TEMPLATES
10
  from .utils import call_openai_with_retries
 
 
 
 
 
 
 
 
 
11
 
12
  logging.basicConfig(level=logging.INFO)
13
  app = FastAPI(title="Pseudogen V1 API")
@@ -29,9 +38,9 @@ if not OPENAI_KEY:
29
  openai.api_key = OPENAI_KEY
30
 
31
  class GenerateRequest(BaseModel):
32
- problem_description: constr(min_length=1, max_length=4000)
33
- style: constr(regex="^(Academic|Developer-Friendly|English-Like|Step-by-Step)$")
34
- detail: constr(regex="^(Concise|Detailed)$")
35
 
36
  @app.post("/generate-pseudocode")
37
  async def generate(req: GenerateRequest):
@@ -44,7 +53,7 @@ async def generate(req: GenerateRequest):
44
 
45
  prompt = template.format(user_input=req.problem_description, detail=req.detail)
46
  try:
47
- response_text = call_openai_with_retries(prompt, model=OPENAI_MODEL)
48
  except Exception as e:
49
  logging.exception("OpenAI call failed")
50
  raise HTTPException(status_code=502, detail=str(e))
 
8
  import openai
9
  from .ai_prompts import TEMPLATES
10
  from .utils import call_openai_with_retries
11
+ from pydantic import BaseModel, constr, Field
12
+ from typing import Annotated
13
+
14
+ from pathlib import Path
15
+ from dotenv import load_dotenv
16
+
17
+ # Force it to load .env from backend folder
18
+ load_dotenv(dotenv_path=Path(__file__).resolve().parent / ".env")
19
+
20
 
21
  logging.basicConfig(level=logging.INFO)
22
  app = FastAPI(title="Pseudogen V1 API")
 
38
  openai.api_key = OPENAI_KEY
39
 
40
  class GenerateRequest(BaseModel):
41
+ problem_description: Annotated[str, Field(min_length=1, max_length=4000)]
42
+ style: Annotated[str, Field(pattern="^(Academic|Developer-Friendly|English-Like|Step-by-Step)$")]
43
+ detail: Annotated[str, Field(pattern="^(Concise|Detailed)$")]
44
 
45
  @app.post("/generate-pseudocode")
46
  async def generate(req: GenerateRequest):
 
53
 
54
  prompt = template.format(user_input=req.problem_description, detail=req.detail)
55
  try:
56
+ response_text = "test response 1234" #call_openai_with_retries(prompt, model=OPENAI_MODEL)
57
  except Exception as e:
58
  logging.exception("OpenAI call failed")
59
  raise HTTPException(status_code=502, detail=str(e))