@@ -190,7 +190,13 @@ impl AiTransform {
190190 AiTransformBuilder :: new ( )
191191 }
192192
193- /// Render the prompt by replacing `{input}` with `input`.
193+ /// Render the prompt by replacing every `{input}` occurrence with `input`.
194+ ///
195+ /// This is a simple string replacement; `{input}` in the AI-generated
196+ /// output is never affected because only the _template_ is processed here,
197+ /// not the model's response. If the document content itself contains the
198+ /// literal text `{input}` it will be substituted too, which is a known
199+ /// limitation of this approach.
194200 fn render_prompt ( & self , input : & str ) -> String {
195201 self . prompt_template . replace ( "{input}" , input)
196202 }
@@ -224,14 +230,24 @@ impl AiTransform {
224230 . send_json ( body)
225231 . with_context ( || format ! ( "Failed to POST to Ollama endpoint '{}'" , url) ) ?;
226232
227- let json: serde_json:: Value = response
228- . into_json ( )
229- . context ( "Failed to parse Ollama JSON response" ) ?;
233+ let body_str = response
234+ . into_string ( )
235+ . context ( "Failed to read Ollama response body" ) ?;
236+
237+ let json: serde_json:: Value =
238+ serde_json:: from_str ( & body_str) . with_context ( || {
239+ format ! ( "Failed to parse Ollama JSON response; body was: {}" , body_str)
240+ } ) ?;
230241
231242 json[ "response" ]
232243 . as_str ( )
233244 . map ( |s| s. to_string ( ) )
234- . ok_or_else ( || anyhow:: anyhow!( "Ollama response missing 'response' field" ) )
245+ . ok_or_else ( || {
246+ anyhow:: anyhow!(
247+ "Ollama response missing 'response' field; received: {}" ,
248+ body_str
249+ )
250+ } )
235251 }
236252
237253 /// Call an OpenAI-compatible `/v1/chat/completions` endpoint.
@@ -251,15 +267,26 @@ impl AiTransform {
251267 . send_json ( body)
252268 . with_context ( || format ! ( "Failed to POST to OpenAI-compatible endpoint '{}'" , url) ) ?;
253269
254- let json: serde_json:: Value = response
255- . into_json ( )
256- . context ( "Failed to parse OpenAI JSON response" ) ?;
270+ let body_str = response
271+ . into_string ( )
272+ . context ( "Failed to read OpenAI response body" ) ?;
273+
274+ let json: serde_json:: Value =
275+ serde_json:: from_str ( & body_str) . with_context ( || {
276+ format ! (
277+ "Failed to parse OpenAI JSON response; body was: {}" ,
278+ body_str
279+ )
280+ } ) ?;
257281
258282 json[ "choices" ] [ 0 ] [ "message" ] [ "content" ]
259283 . as_str ( )
260284 . map ( |s| s. to_string ( ) )
261285 . ok_or_else ( || {
262- anyhow:: anyhow!( "OpenAI response missing 'choices[0].message.content' field" )
286+ anyhow:: anyhow!(
287+ "OpenAI response missing 'choices[0].message.content' field; received: {}" ,
288+ body_str
289+ )
263290 } )
264291 }
265292}
0 commit comments