Add execution time logging to smd_detail_article function
Introduced performance tracking in the smd_detail_article function by adding execution time logging. This helps in monitoring and optimizing the function’s runtime during API requests and processing.
This commit is contained in:
parent
bbec6df3fd
commit
e5a6c59f7a
1 changed files with 5 additions and 0 deletions
|
@ -10,6 +10,7 @@ import logging
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
import requests
|
import requests
|
||||||
|
import time
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
|
|
||||||
|
@ -55,6 +56,8 @@ async def summarize_to_words(text: str, title: str, target_word_count: int = 100
|
||||||
return await response.text()
|
return await response.text()
|
||||||
|
|
||||||
async def smd_detail_article(article_id):
|
async def smd_detail_article(article_id):
|
||||||
|
logger.info("Starting smd_detail_article function.")
|
||||||
|
start_time = time.perf_counter()
|
||||||
url = f"https://api.swissdox.ch/api/documents/{article_id}"
|
url = f"https://api.swissdox.ch/api/documents/{article_id}"
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}",
|
"Authorization": f"Bearer {os.getenv('SWISSDOX_BEARER_TOKEN', '')}",
|
||||||
|
@ -67,6 +70,8 @@ async def smd_detail_article(article_id):
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
data = await response.json()
|
data = await response.json()
|
||||||
summarized_content = await summarize_to_words(title=data.get("title"), text=data.get("text"), target_word_count=10000)
|
summarized_content = await summarize_to_words(title=data.get("title"), text=data.get("text"), target_word_count=10000)
|
||||||
|
execution_time = time.perf_counter() - start_time
|
||||||
|
logger.info(f"smd_detail_article executed in {execution_time:.2f} seconds.")
|
||||||
return {
|
return {
|
||||||
"message": summarized_content,
|
"message": summarized_content,
|
||||||
"article_id": article_id
|
"article_id": article_id
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue