Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

chore: Update gpt 3.5 model and improve reliability (#3541)

Oleg Isonen0cf24fbcd5f1
diff --git a/apps/builder/app/routes/rest.ai._index.ts b/apps/builder/app/routes/rest.ai._index.ts
index d5c587427f..a018db5c5b 100644
--- a/apps/builder/app/routes/rest.ai._index.ts
+++ b/apps/builder/app/routes/rest.ai._index.ts
@@ -175,7 +175,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
apiKey: env.OPENAI_KEY,
organization: env.OPENAI_ORG,
temperature: 0,
- model: "gpt-3.5-turbo-16k",
+ model: "gpt-3.5-turbo",
});
const chain = operations.createChain<GptModelMessageFormat>();
diff --git a/packages/ai/src/chains/operations/__generated__/operations.system.prompt.ts b/packages/ai/src/chains/operations/__generated__/operations.system.prompt.ts
index bf273162f1..23235ca461 100644
--- a/packages/ai/src/chains/operations/__generated__/operations.system.prompt.ts
+++ b/packages/ai/src/chains/operations/__generated__/operations.system.prompt.ts
@@ -11,4 +11,6 @@ All the required schema properties must have values.
Properties value contain descriptions with instructions on how to fill them out. When they do please keep those in mind when generating a completion.
Respond with an array of operations as JSON and no other text. Start with [{"operation":
+
+Do not start your response with \`\`\`json
`;
diff --git a/packages/ai/src/chains/operations/chain.server.ts b/packages/ai/src/chains/operations/chain.server.ts
index 7e806df29a..0517a5bb2d 100644
--- a/packages/ai/src/chains/operations/chain.server.ts
+++ b/packages/ai/src/chains/operations/chain.server.ts
@@ -109,9 +109,26 @@ export const createChain = <ModelMessageFormat>(): Chain<
const completionText = completion.data.choices[0];
llmMessages.push(["assistant", completionText]);
- const parsedCompletion = AiOperationsSchema.safeParse(
- JSON.parse(completionText)
- );
+ let parsedCompletion;
+
+ try {
+ parsedCompletion = AiOperationsSchema.safeParse(
+ JSON.parse(completionText)
+ );
+ } catch (error) {
+ return {
+ id: name,
+ ...createErrorResponse({
+ status: 500,
+ error: "ai.parseError",
+ message: `Failed to parse completion JSON ${error}`,
+ debug: `Failed to parse completion JSON ${error}`,
+ }),
+ tokens: completion.tokens,
+ llmMessages,
+ } as const;
+ }
+
if (parsedCompletion.success === false) {
return {
id: name,
diff --git a/packages/ai/src/chains/operations/operations.system.prompt.md b/packages/ai/src/chains/operations/operations.system.prompt.md
index b4f82a9558..b6e429154b 100644
--- a/packages/ai/src/chains/operations/operations.system.prompt.md
+++ b/packages/ai/src/chains/operations/operations.system.prompt.md
@@ -11,3 +11,5 @@ All the required schema properties must have values.
Properties value contain descriptions with instructions on how to fill them out. When they do please keep those in mind when generating a completion.
Respond with an array of operations as JSON and no other text. Start with [{"operation":
+
+Do not start your response with ```json