Videos de spring ai advisors
Videos etiquetados con "spring ai advisors"
spring ai advisors 1 videos
Spring AI 2.0: Custom Advisors for Tool & Token Logging
Ever wondered which tools your LLM is actually using and how many tokens each call is consuming? Spring AI Advisors give you AOP-like superpowers for your AI interactions, letting you intercept, log, and monitor every call to your language model. In this video, we explore Spring AI's Advisor API by building two custom advisors from scratch. The first is an AvailableToolsLoggingAdvisor that shows which tools are visible to the model before a call and which ones were actually invoked after. The second is a TokenCounterAdvisor that tracks prompt tokens, completion tokens, and total tokens with running totals across multiple calls. Along the way, you'll learn how advisors work as before/after interceptors for LLM calls, how to use the ChatResponse metadata, and how to wire tools into your Spring AI chat client. - Understand what Spring AI Advisors are and how they act as AOP for LLM calls - Build an AvailableToolsLoggingAdvisor to log which tools are loaded and which are invoked - Build a TokenCounterAdvisor to track prompt, completion, and total token usage per call - Learn how to use ChatResponse metadata for usage statistics - Wire up custom tools (like a DateTime tool) and see them in action with advisors 0:00 - Intro - Why I needed custom advisors 1:10 - What are Spring AI Advisors? 2:30 - Spring AI Reference Docs & Built-in Advisors 3:30 - Project setup on start.spring.io 4:30 - Configuring API key and model 5:15 - Creating the ChatController and ChatResponse 6:45 - Understanding token usage from ChatResponse 8:00 - Adding a DateTime tool for LLM calls 10:00 - Building the AvailableToolsLoggingAdvisor (before) 13:30 - Adding the after method to log invoked tools 16:30 - Testing the AvailableToolsLoggingAdvisor 17:45 - Building the TokenCounterAdvisor 20:30 - Testing the TokenCounterAdvisor 21:30 - Wrap up & what's next (Tool Searching) 🔗Resources & Links mentioned in this video: Spring AI Reference Documentation - Advisors: https://docs.spring.io/spring-ai/reference/api/advisors.html Spring Initializr: https://start.spring.io Dan Vega's Spring AI Workshop (GitHub): https://github.com/danvega/spring-ai-workshop 👋🏻Connect with me: Website: https://www.danvega.dev Twitter: https://twitter.com/therealdanvega Github: https://github.com/danvega LinkedIn: https://www.linkedin.com/in/danvega Newsletter: https://www.danvega.dev/newsletter SUBSCRIBE TO MY CHANNEL: http://bit.ly/2re4GH0 ❤️