fix: set default value for notes in PresentationOutlineModel and improve response format handling in generate_ppt_outline and fixed OpenAI Streaming Response handling
This commit is contained in:
parent
25e11dc9ef
commit
a450afc3a2
2 changed files with 21 additions and 6 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue