diff --git a/servers/fastapi/models/presentation_outline_model.py b/servers/fastapi/models/presentation_outline_model.py index 4f3bd377..ed06485b 100644 --- a/servers/fastapi/models/presentation_outline_model.py +++ b/servers/fastapi/models/presentation_outline_model.py @@ -15,7 +15,7 @@ class PresentationOutlineModel(BaseModel): title: str = Field( description="Title of the presentation in about 3 to 8 words", ) - notes: Optional[List[str]] = Field(description="Notes for the presentation") + notes: Optional[List[str]] = Field(default=None, description="Notes for the presentation") slides: List[SlideOutlineModel] = Field(description="List of slides") def to_string(self): diff --git a/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py b/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py index 90be3f9e..b7ba983e 100644 --- a/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py +++ b/servers/fastapi/utils/llm_calls/generate_presentation_outlines.py @@ -1,5 +1,4 @@ from typing import Optional -from openai.lib.streaming.chat._events import ContentDeltaEvent from google.genai.types import GenerateContentConfig from utils.async_iterator import iterator_to_async @@ -11,7 +10,7 @@ from utils.llm_provider import ( get_nano_model, is_google_selected, ) - +from pydantic import BaseModel system_prompt = """ You are an expert presentation creator. Generate structured presentations based on user requirements and format them according to the specified JSON schema with markdown content. @@ -75,7 +74,14 @@ def get_prompt_template(prompt: str, n_slides: int, language: str, content: str) }, ] - +def get_response_format(response_model: BaseModel): + return { + "type": "json_schema", + "json_schema": { + "name": "PresentationOutlineModel", + "schema": response_model.model_json_schema(), + }, + } async def generate_ppt_outline( prompt: Optional[str], n_slides: int, @@ -83,7 +89,9 @@ async def generate_ppt_outline( content: Optional[str] = None, ): model = get_large_model() + print(f"Using model: {model}") response_model = get_presentation_outline_model_with_n_slides(n_slides) + print(response_model.model_json_schema()) if not is_google_selected(): client = get_llm_client() @@ -91,9 +99,16 @@ async def generate_ppt_outline( model=model, messages=get_prompt_template(prompt, n_slides, language, content), stream=True, - response_format=response_model, + response_format = get_response_format(response_model) ): - yield response.choices[0].delta + delta = response.choices[0].delta + content = None + if isinstance(delta, dict): + content = delta.get("content") + else: + content = getattr(delta, "content", None) + if content: + yield content else: client = get_google_llm_client()