refactor: update llm.call to async await for improved performance
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...

This commit is contained in:
Steven Tischer
2026-07-23 14:19:42 +02:00
parent b6095188ac
commit daf71a6dae
4 changed files with 9 additions and 9 deletions
+6 -6
View File
@@ -1,9 +1,9 @@
from openai import OpenAI, APIConnectionError
from openai import APIConnectionError
from openai import AsyncOpenAI
from .. import config
from typing import Optional, Dict, Any
import asyncio
def call(
async def call(
system_prompt: str,
user_prompt: str,
model: str = None,
@@ -16,18 +16,18 @@ def call(
if model is None:
model = config.settings.llm_model
response_format = None
if json_schema is not None:
response_format = _get_response_format(schema = json_schema,schema_name=schema_name)
client = OpenAI(
client = AsyncOpenAI(
base_url=config.settings.llm_api_url,
api_key=config.settings.llm_api_key,
timeout=timeout,
)
try:
response = client.chat.completions.create(
response = await client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": system_prompt},
+1 -1
View File
@@ -82,7 +82,7 @@ async def extract_keywords(query: str, mode: str, limit: int) -> ExtractedKeywor
user_prompt += f"""Input:{text}"""
keywords = llm.call(
keywords = await llm.call(
system_prompt=system_prompt,
user_prompt=user_prompt,
json_schema = ExtractedKeywordsLLM.model_json_schema(),
+1 -1
View File
@@ -292,7 +292,7 @@ async def _get_article_keywords(
if not text:
return []
raw = llm.call(
raw = await llm.call(
system_prompt=KEYWORD_SYSTEM_PROMPT,
user_prompt=f"Artikel:\n{text}",
temperature=0.3,
+1 -1
View File
@@ -444,7 +444,7 @@ async def generate_person_bio(
user_prompt = f"Daten zur Person:\n{person_json}"
bio = llm.call(
bio = await llm.call(
system_prompt=system_prompt,
user_prompt=user_prompt,
temperature=0.8,