You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error: "Failed to initialize AI model for text enhancement",
143
+
code: "MODEL_INIT_ERROR",
144
+
provider: defaultModel.providerId,
145
+
requestId,
146
+
},
147
+
{status: 500}
148
+
)
149
+
}
150
+
151
+
// Generate enhanced text using streamObject for compatibility
152
+
try{
153
+
console.log(`[Enhance Text API ${requestId}] Generating enhanced text`)
154
+
155
+
constresult=awaitstreamObject({
156
+
model: modelClient,
157
+
schema: enhanceResponseSchema,
158
+
system: `You are an expert writing assistant that enhances text to be more clear, engaging, and effective while preserving the original intent and tone.
159
+
160
+
Your task is to improve the given text by:
161
+
- Making it more clear and concise
162
+
- Improving grammar and sentence structure
163
+
- Enhancing readability and flow
164
+
- Maintaining the original meaning and intent
165
+
- Keeping the same approximate length and tone
166
+
- Making it more engaging without being overly formal
167
+
168
+
Always preserve the core message while making it sound more professional and polished.`,
169
+
messages: [
170
+
{
171
+
role: "user",
172
+
content: `Please enhance this text while preserving its original intent and tone:
173
+
174
+
"${textToEnhance}"
175
+
176
+
Make it more clear, engaging, and well-structured while keeping the same general meaning and length.`
177
+
}
178
+
],
179
+
maxRetries: 2,
180
+
temperature: 0.7,
181
+
})
182
+
183
+
// Wait for the complete object
184
+
constfinalResult=awaitresult.object
185
+
186
+
console.log(`[Enhance Text API ${requestId}] Enhancement completed successfully`)
0 commit comments