INNER CODE UNIT · Python
generate_title
cognitivetech/ollama-ebook-summary · sum.py:143
def generate_title(api_base: str, model: str, clean_text: str, title_prompt: str, config: Config) -> Optional[str]:
"""Generate a unique title using the specified API and return only the first line."""
payload = {
"model": model,
"prompt": f"```{clean_text}```\n\n{title_prompt}",
"stream": False
}
result = make_api_request(api_base, "generate", payload)
if result:
# Split response by newlines and return only first line, stripped of whitespace
return result.get("response", "").strip().split('\n')[0]
return None
def get_unique_title(original_title: str, clean_text: str, previous_original_title: str, api_base: str, title_prompt: str, config: Config) -> Tuple[str, bool]:
"""Ensure the title is unique, generate a new one if necessary."""
if original_title and original_title != previous_original_title:
return original_title, False