devZenaight commited on
Commit
d35dd88
Β·
1 Parent(s): 616cd48

GenerateId Added to backend

Browse files

The generateId is now added to the backend and is also now fixed, so each procedure contains it now on the backend

Files changed (2) hide show
  1. app/main.py +16 -8
  2. app/models.py +4 -1
app/main.py CHANGED
@@ -391,6 +391,7 @@ class GenerateRequest(BaseModel):
391
  countryCode: Optional[str] = None
392
  sectionKey: Optional[str] = None # e.g. "prompt_ExecutiveSummary"
393
  returnContent: Optional[bool] = False # NEW β€” default to id-only responses
 
394
 
395
  # ──────────────────────────────────────────────────────────────────────────────
396
  # LLM plumbing
@@ -930,7 +931,7 @@ def _compose_prompt_vars(
930
  async def _ensure_business_plan(pool, *, bp_id: Optional[str], summary: str, full_plan: str,
931
  model: str, answers: List[str], plan_type: Optional[str],
932
  user_id: Optional[str], anon_id: Optional[str],
933
- country_code: Optional[str]) -> str:
934
  async with pool.acquire() as conn:
935
  if bp_id:
936
  exists = await conn.fetchval('SELECT 1 FROM "BusinessPlan" WHERE id = $1', bp_id)
@@ -939,19 +940,20 @@ async def _ensure_business_plan(pool, *, bp_id: Optional[str], summary: str, ful
939
  'UPDATE "BusinessPlan" SET '
940
  '"summary"=$1, "model"=$2, "answers"=$3, '
941
  '"planType"=COALESCE($4,\'free\'), "countryCode"=$5, '
942
- '"updatedAt"=now(), "userId"=COALESCE($6,"userId") '
943
- 'WHERE id=$7',
944
- summary, model, answers, plan_type, country_code, user_id, bp_id
 
945
  )
946
  return bp_id
947
 
948
  new_id = new_cuid()
949
  row = await conn.fetchrow(
950
  'INSERT INTO "BusinessPlan" '
951
- '("id","summary","fullPlan","model","answers","planType","userId","anonymousId","countryCode","updatedAt") '
952
- 'VALUES ($1,$2,$3,$4,$5,COALESCE($6,\'free\'),$7,$8,$9, now()) '
953
  'RETURNING id',
954
- new_id, summary, "", model, answers, plan_type, user_id, anon_id, country_code # fullPlan is intentionally ""
955
  )
956
  return row["id"]
957
 
@@ -1077,6 +1079,7 @@ class CreatePlanRequest(BaseModel):
1077
  countryCode: Optional[str] = None
1078
  anonymousId: Optional[str] = None
1079
  businessIdea: Optional[str] = None
 
1080
 
1081
  @app.post("/plan")
1082
  async def create_plan_shell(request: Request, data: CreatePlanRequest):
@@ -1099,13 +1102,14 @@ async def create_plan_shell(request: Request, data: CreatePlanRequest):
1099
  user_id=user_id,
1100
  anon_id=anon_id,
1101
  country_code=data.countryCode,
 
1102
  )
1103
  await _ensure_sections_row(pool, bp_id)
1104
 
1105
  # Tell subscribers a plan exists
1106
  await _publish(bp_id, "plan.created", {"businessPlanId": bp_id})
1107
 
1108
- return {"businessPlanId": bp_id}
1109
 
1110
  @app.post("/generate/batch")
1111
  async def generate_business_plan_batch(request: Request, data: BatchGenerateRequest):
@@ -1134,6 +1138,7 @@ async def generate_business_plan_batch(request: Request, data: BatchGenerateRequ
1134
  user_id=user_id,
1135
  anon_id=anon_id,
1136
  country_code=data.countryCode,
 
1137
  )
1138
  # logging.info(f"[plan] ensured id={bp_id} linked to user_id={user_id} anon_id={anon_id}")
1139
 
@@ -1225,6 +1230,7 @@ async def generate_business_plan_batch(request: Request, data: BatchGenerateRequ
1225
  user_id=user_id,
1226
  anon_id=anon_id,
1227
  country_code=data.countryCode,
 
1228
  )
1229
 
1230
  await _publish(bp_id, "plan.updated", {
@@ -1363,6 +1369,7 @@ async def generate_business_plan(request: Request, data: GenerateRequest):
1363
  user_id=user_id,
1364
  anon_id=anon_id,
1365
  country_code=data.countryCode,
 
1366
  )
1367
  # logging.info(f"[plan] ensured section id={business_plan_id} linked to user_id={user_id} anon_id={anon_id}")
1368
 
@@ -1427,6 +1434,7 @@ async def generate_business_plan(request: Request, data: GenerateRequest):
1427
  user_id=user_id,
1428
  anon_id=anon_id,
1429
  country_code=data.countryCode,
 
1430
  )
1431
  logging.info(f"[plan] ensured whole plan id={business_plan_id} linked to user_id={user_id} anon_id={anon_id}")
1432
 
 
391
  countryCode: Optional[str] = None
392
  sectionKey: Optional[str] = None # e.g. "prompt_ExecutiveSummary"
393
  returnContent: Optional[bool] = False # NEW β€” default to id-only responses
394
+ generateId: Optional[str] = None
395
 
396
  # ──────────────────────────────────────────────────────────────────────────────
397
  # LLM plumbing
 
931
  async def _ensure_business_plan(pool, *, bp_id: Optional[str], summary: str, full_plan: str,
932
  model: str, answers: List[str], plan_type: Optional[str],
933
  user_id: Optional[str], anon_id: Optional[str],
934
+ country_code: Optional[str], generate_id: Optional[str] = None) -> str:
935
  async with pool.acquire() as conn:
936
  if bp_id:
937
  exists = await conn.fetchval('SELECT 1 FROM "BusinessPlan" WHERE id = $1', bp_id)
 
940
  'UPDATE "BusinessPlan" SET '
941
  '"summary"=$1, "model"=$2, "answers"=$3, '
942
  '"planType"=COALESCE($4,\'free\'), "countryCode"=$5, '
943
+ '"generateId"=COALESCE($6,"generateId"), '
944
+ '"updatedAt"=now(), "userId"=COALESCE($7,"userId") '
945
+ 'WHERE id=$8',
946
+ summary, model, answers, plan_type, country_code, generate_id, user_id, bp_id
947
  )
948
  return bp_id
949
 
950
  new_id = new_cuid()
951
  row = await conn.fetchrow(
952
  'INSERT INTO "BusinessPlan" '
953
+ '("id","summary","fullPlan","model","answers","planType","userId","anonymousId","countryCode","generateId","updatedAt") '
954
+ 'VALUES ($1,$2,$3,$4,$5,COALESCE($6,\'free\'),$7,$8,$9,$10, now()) '
955
  'RETURNING id',
956
+ new_id, summary, "", model, answers, plan_type, user_id, anon_id, country_code, generate_id
957
  )
958
  return row["id"]
959
 
 
1079
  countryCode: Optional[str] = None
1080
  anonymousId: Optional[str] = None
1081
  businessIdea: Optional[str] = None
1082
+ generateId: Optional[str] = None
1083
 
1084
  @app.post("/plan")
1085
  async def create_plan_shell(request: Request, data: CreatePlanRequest):
 
1102
  user_id=user_id,
1103
  anon_id=anon_id,
1104
  country_code=data.countryCode,
1105
+ generate_id=data.generateId,
1106
  )
1107
  await _ensure_sections_row(pool, bp_id)
1108
 
1109
  # Tell subscribers a plan exists
1110
  await _publish(bp_id, "plan.created", {"businessPlanId": bp_id})
1111
 
1112
+ return {"businessPlanId": bp_id, "generateId": data.generateId}
1113
 
1114
  @app.post("/generate/batch")
1115
  async def generate_business_plan_batch(request: Request, data: BatchGenerateRequest):
 
1138
  user_id=user_id,
1139
  anon_id=anon_id,
1140
  country_code=data.countryCode,
1141
+ generate_id=data.generateId,
1142
  )
1143
  # logging.info(f"[plan] ensured id={bp_id} linked to user_id={user_id} anon_id={anon_id}")
1144
 
 
1230
  user_id=user_id,
1231
  anon_id=anon_id,
1232
  country_code=data.countryCode,
1233
+ generate_id=data.generateId,
1234
  )
1235
 
1236
  await _publish(bp_id, "plan.updated", {
 
1369
  user_id=user_id,
1370
  anon_id=anon_id,
1371
  country_code=data.countryCode,
1372
+ generate_id=data.generateId,
1373
  )
1374
  # logging.info(f"[plan] ensured section id={business_plan_id} linked to user_id={user_id} anon_id={anon_id}")
1375
 
 
1434
  user_id=user_id,
1435
  anon_id=anon_id,
1436
  country_code=data.countryCode,
1437
+ generate_id=data.generateId,
1438
  )
1439
  logging.info(f"[plan] ensured whole plan id={business_plan_id} linked to user_id={user_id} anon_id={anon_id}")
1440
 
app/models.py CHANGED
@@ -50,6 +50,7 @@ class BatchGenerateRequest(BaseModel):
50
  countryCode: Optional[str] = None
51
  businessIdea: Optional[str] = None
52
  anonymousId: Optional[str] = None
 
53
  feedback: Optional[str] = None
54
  sections: List[SectionJob]
55
  format: Optional[str] = None
@@ -72,6 +73,7 @@ class GenerateRequest(BaseModel):
72
  countryCode: Optional[str] = None
73
  sectionKey: Optional[str] = None # e.g. "prompt_ExecutiveSummary"
74
  returnContent: Optional[bool] = False # NEW β€” default to id-only responses
 
75
 
76
  class CreatePlanRequest(BaseModel):
77
  """Request model for creating a new business plan"""
@@ -79,4 +81,5 @@ class CreatePlanRequest(BaseModel):
79
  planType: Optional[str] = "free"
80
  countryCode: Optional[str] = None
81
  anonymousId: Optional[str] = None
82
- businessIdea: Optional[str] = None
 
 
50
  countryCode: Optional[str] = None
51
  businessIdea: Optional[str] = None
52
  anonymousId: Optional[str] = None
53
+ generateId: Optional[str] = None
54
  feedback: Optional[str] = None
55
  sections: List[SectionJob]
56
  format: Optional[str] = None
 
73
  countryCode: Optional[str] = None
74
  sectionKey: Optional[str] = None # e.g. "prompt_ExecutiveSummary"
75
  returnContent: Optional[bool] = False # NEW β€” default to id-only responses
76
+ generateId: Optional[str] = None
77
 
78
  class CreatePlanRequest(BaseModel):
79
  """Request model for creating a new business plan"""
 
81
  planType: Optional[str] = "free"
82
  countryCode: Optional[str] = None
83
  anonymousId: Optional[str] = None
84
+ businessIdea: Optional[str] = None
85
+ generateId: Optional[str] = None