Refactor response handling to parse JSON content.

Replace raw response text retrieval with JSON parsing to extract specific content. This ensures more precise data handling and aligns with expected response structure.
This commit is contained in:
ThomasTaroni 2025-06-21 22:19:50 +02:00
parent 4c554b1472
commit bbec6df3fd

View file

@ -49,7 +49,8 @@ async def summarize_to_words(text: str, title: str, target_word_count: int = 100
async with aiohttp.ClientSession() as session:
async with session.post(url, headers=headers, json=payload) as response:
if response.status == 200:
return await response.text()
data = await response.json()
return data.get("choices")[0].get("message").get("content")
else:
return await response.text()