-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Importing a schema object in script() lead to a 400 error #922
Comments
{
"feedback": "The issue appears to be due to how the `script()` function is handling the `responseSchema`. The current implementation seems to be converting the schema into a string rather than keeping it as an object. To resolve this, you may need to adjust the part of the code that parses and converts the prompt script metadata to ensure that the `responseSchema` is preserved as an object instead of a string. This will allow OpenAI to correctly interpret the schema when generating the response."
}
|
Ha yes, this is a hack to speed up parsing of the script to extract the metadata to avoid loading and executing the script. I will bring back running the script as a bailout scenario. |
For now you have to inline it |
Actually since it parsed it correctly, we should try to test the properties are a string (unresolved variables) and remove them. We don't need the schema at this point. I'll get a fix later. |
Yes I inlined it like this import { dialog } from "./zod-magnolia.mts";
import { zodResponseFormat } from "openai/helpers/zod";
const schema = zodResponseFormat(dialog, "dialog").json_schema
.schema as unknown as JSONSchemaObject;
const result = await runPrompt(
(_) => {
_.defSchema("DIALOG_SCHEMA", schema, { format: "json" });
_.$`Generate a dialog for Magnolia CMS respecting DIALOG_SCHEMA. This dialog allows to add an article`;
},
{
model: "openai:gpt-4o",
responseType: "json_schema",
responseSchema: schema,
}
); By the way, what do you think about a small helper around zod -> schema ? |
Yes that would be great. Could be added to the already existing schema validation helpers. |
The following GenAIScript configuration leads to a
400 Error
when making a request to OpenAI:The OpenAI API returns the following error:
The reason is that
responseSchema
is equal to the string value"dialog"
instead of the imported js objectThis is due to
parsePromptScriptMeta
turning the code inside script({...}) into JSONDo you have a lead to fix that ?
The text was updated successfully, but these errors were encountered: