diff --git a/src/phoenix_technologies/smd/server.py b/src/phoenix_technologies/smd/server.py index eecde2e..eeae925 100644 --- a/src/phoenix_technologies/smd/server.py +++ b/src/phoenix_technologies/smd/server.py @@ -26,18 +26,47 @@ logger = logging.getLogger(__name__) # Initialize FastMCP server 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: + url = f"https://maas.ai-2.kvant.cloud/engines/{os.getenv('SWISSDOX_SUMMARIZING_MODEL', '')}/chat/completions" + headers = { + "x-litellm-api-key": f"Bearer {os.getenv('SWISSDOX_SUMMARIZING_MODEL_APIKEY', '')}", + "Content-type": "application/json", + } + payload = { + "model": {os.getenv('SWISSDOX_SUMMARIZING_MODEL', '')}, + "messages": [ + { + "role": "text summarizer", + "content": f"You are summarizing the user input to a maximum of {target_word_count}" + }, + { + "role": "user", + "content": f"{str(article)}" + } + ] + } + + async with aiohttp.ClientSession() as session: + async with session.post(url, headers=headers, json=payload) as response: + if response.status == 200: + return await response.json() + else: + return await response.text() + async def smd_detail_article(article_id): url = f"https://api.swissdox.ch/api/documents/{article_id}" headers = { - "authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}", - "content-type": "application/json", + "Authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}", + "Content-type": "application/json", } payload = {"filters": [], "pagination": {"pageSize": 1, "currentPage": 1}} async with aiohttp.ClientSession() as session: async with session.post(url, headers=headers, json=payload) as response: if response.status == 200: - return await response.json() # JSON asynchron lesen + data = await response.json() + summarized_content = await summarize_to_words(data, target_word_count=10000) + return summarized_content else: return { "message": await response.text(),