@@ -123,16 +123,12 @@ async def main():
123123 )
124124
125125 if model:
126- # Simple conversation flow - metrics are automatically tracked by invoke ()
127- response1 = await model.invoke (' I need help with my order' )
128- print (response1.message. content)
126+ # Simple conversation flow - metrics are automatically tracked by run ()
127+ response1 = await model.run (' I need help with my order' )
128+ print (response1.content)
129129
130- response2 = await model.invoke(" What's the status?" )
131- print (response2.message.content)
132-
133- # Access conversation history
134- messages = model.get_messages()
135- print (f ' Conversation has { len (messages)} messages ' )
130+ response2 = await model.run(" What's the status?" )
131+ print (response2.content)
136132
137133asyncio.run(main())
138134```
@@ -146,21 +142,20 @@ For more control, you can use the configuration directly with AI providers. We r
146142``` python
147143import asyncio
148144from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
149- from ldai.providers.types import LDAIMetrics, TokenUsage
150145
151- from ldai_langchain import LangChainProvider
146+ from ldai_langchain import create_langchain_model, get_ai_metrics_from_response
152147
153148async def main ():
154149 ai_config = ai_client.completion_config(ai_config_key, context, default)
155150
156151 # Create LangChain model from configuration
157- llm = await LangChainProvider. create_langchain_model(ai_config)
152+ llm = create_langchain_model(ai_config)
158153
159154 # Use with tracking (sync invoke). Mint a tracker once per AI run.
160155 tracker = ai_config.create_tracker()
161156 response = tracker.track_metrics_of(
157+ get_ai_metrics_from_response,
162158 lambda : llm.invoke(messages),
163- lambda result : LangChainProvider.get_ai_metrics_from_response(result)
164159 )
165160
166161 print (' AI Response:' , response.content)
@@ -173,7 +168,8 @@ asyncio.run(main())
173168``` python
174169import asyncio
175170from ldai import LDAIClient, AICompletionConfigDefault, ModelConfig
176- from ldai.providers.types import LDAIMetrics, TokenUsage
171+ from ldai.providers import LDAIMetrics
172+ from ldai.tracker import TokenUsage
177173
178174async def main ():
179175 ai_config = ai_client.completion_config(ai_config_key, context, default)
@@ -200,8 +196,8 @@ async def main():
200196 # Mint a tracker once per AI run.
201197 tracker = ai_config.create_tracker()
202198 result = await tracker.track_metrics_of_async(
199+ map_custom_provider_metrics,
203200 call_custom_provider,
204- map_custom_provider_metrics
205201 )
206202
207203 print (' AI Response:' , result.content)
0 commit comments