Added code to trim gemini response of any markdown/whitespace

This commit is contained in:
Waleed Latif
2025-02-12 13:37:51 -08:00
parent c203fbf1d2
commit 2818cd91a9
+8 -1
View File
@@ -182,8 +182,15 @@ export const googleProvider: ProviderConfig = {
},
transformResponse: (response: any) => {
let content = response.candidates?.[0]?.content?.parts?.[0]?.text || ''
if (content) {
content = content.replace(/```json\n?|\n?```/g, '')
content = content.trim()
}
return {
content: response.candidates?.[0]?.content?.parts?.[0]?.text || '',
content,
tokens: response.usageMetadata && {
prompt: response.usageMetadata.promptTokenCount,
completion: response.usageMetadata.candidatesTokenCount,