feat(backend): add time measurement to llm generation
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -18,6 +18,7 @@ from fastapi import HTTPException
|
||||
import logging
|
||||
import httpx
|
||||
import json
|
||||
import time
|
||||
from elasticsearch import Elasticsearch, helpers, NotFoundError, ApiError
|
||||
from . import schema
|
||||
from . import model
|
||||
@@ -288,6 +289,8 @@ def search_persons(author_id: Optional[str] = None, query: Optional[str] = None,
|
||||
return model.PersonSearchResult(persons=persons)
|
||||
|
||||
def generate_person_bio(author_id: str) -> str:
|
||||
start_time = time.time()
|
||||
|
||||
search_result = search_persons(author_id=author_id)
|
||||
if not search_result.persons:
|
||||
return "No person found."
|
||||
@@ -297,7 +300,7 @@ def generate_person_bio(author_id: str) -> str:
|
||||
person = search_result.persons[0]
|
||||
person_json = json.dumps(person.model_dump())
|
||||
|
||||
system_prompt = "Erstelle eine Beschreibung der Person in 3-5 Sätzen. Gebe nur die Beschreibung zurück, ohne Einleitung oder Schluss."
|
||||
system_prompt = "Erstelle eine Beschreibung der Person in 3 Sätzen. Gebe nur die Beschreibung zurück, ohne Einleitung oder Schluss."
|
||||
user_prompt = f"Daten zur Person:\n{person_json}"
|
||||
|
||||
headers = {
|
||||
@@ -314,7 +317,12 @@ def generate_person_bio(author_id: str) -> str:
|
||||
response = client.post(config.settings.llm_api_url, json=payload, headers=headers)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
return data.get("response", "")
|
||||
bio = data.get("response", "")
|
||||
|
||||
elapsed_time = time.time() - start_time
|
||||
logger.info(f"Bio generation for author {author_id} took {elapsed_time:.2f} seconds")
|
||||
|
||||
return bio
|
||||
|
||||
|
||||
def get_person_by_id(author_id: str) -> model.Person:
|
||||
|
||||
Reference in New Issue
Block a user