Log requests and responses to Open AI #450
Replies: 1 comment
-
I was looking to do this too, and did a little digging. RestClient uses a default RestClient.Builder bean, but you can override it with your own. Here I took the default implementation and added a requestInterceptor() to the builder. The code is in Groovy, so you will need to add some semi-colons and stuff.
Then your interceptor would look like this. This is just some working test code right now, so it just prints to the console.
Because you can only read the body of the response once, you need to wrap the response in a wrapper class that buffers the body. If you are using Java, you can use the link in the comment for the wrapper class to get the Java-ish source. |
Beta Was this translation helpful? Give feedback.
-
Has anyone managed to find a way to log the requests and responses to/from Open AI using Spring AI.
I have tried various logging settings in the application.properties but no luck.
With Langchain4J, there is a specific property for logging the requests and responses to/from the AI models, but couldn't find anything similar with Spring AI.
Beta Was this translation helpful? Give feedback.
All reactions