Refactor summarize_to_words to accept text and title.

Updated the `summarize_to_words` function to take `text` and `title` as separate parameters instead of a single `article` dictionary. Adjusted payload and function calls accordingly for better clarity and flexibility.
This commit is contained in:
ThomasTaroni 2025-06-21 21:35:54 +02:00
parent 1d5aeb1644
commit 6f9f74dae0

View file

@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
# Initialize FastMCP server # Initialize FastMCP server
mcp = FastMCP("SMD Researcher", host="0.0.0.0", port=8000, timeout_keep_alive=720) mcp = FastMCP("SMD Researcher", host="0.0.0.0", port=8000, timeout_keep_alive=720)
async def summarize_to_words(article: dict, target_word_count: int = 1000) -> str: async def summarize_to_words(text: str, title: str, target_word_count: int = 1000) -> str:
url = f"https://maas.ai-2.kvant.cloud/engines/{os.getenv('SWISSDOX_SUMMARIZING_MODEL', '')}/chat/completions" url = f"https://maas.ai-2.kvant.cloud/engines/{os.getenv('SWISSDOX_SUMMARIZING_MODEL', '')}/chat/completions"
headers = { headers = {
"x-litellm-api-key": f"Bearer {os.getenv('SWISSDOX_SUMMARIZING_MODEL_APIKEY', '')}", "x-litellm-api-key": f"Bearer {os.getenv('SWISSDOX_SUMMARIZING_MODEL_APIKEY', '')}",
@ -41,7 +41,7 @@ async def summarize_to_words(article: dict, target_word_count: int = 1000) -> st
}, },
{ {
"role": "user", "role": "user",
"content": f"{str(article)}" "content": f"{title} - {text}"
} }
] ]
} }
@ -65,7 +65,7 @@ async def smd_detail_article(article_id):
async with session.post(url, headers=headers, json=payload) as response: async with session.post(url, headers=headers, json=payload) as response:
if response.status == 200: if response.status == 200:
data = await response.json() data = await response.json()
summarized_content = await summarize_to_words(data, target_word_count=10000) summarized_content = await summarize_to_words(title=data.get("title"), text=data.get("text"), target_word_count=10000)
return summarized_content return summarized_content
else: else:
return { return {