@@ -68,23 +68,22 @@ async function main() {
6868 { example_type : 'provider_observability_demo' } ,
6969 ) ;
7070
71- if ( ! aiConfig . enabled || ! aiConfig . tracker ) {
71+ if ( ! aiConfig . enabled ) {
7272 console . log ( '*** AI configuration is not enabled' ) ;
7373 ldClient . close ( ) ;
7474 process . exit ( 0 ) ;
7575 }
7676
7777 try {
7878 // ── 4. Call OpenAI and track metrics with the provider's extractor ──
79- const completion = await aiConfig . tracker . trackMetricsOf (
80- OpenAIProvider . getAIMetricsFromResponse ,
81- ( ) =>
82- openai . chat . completions . create ( {
83- messages : aiConfig . messages || [ ] ,
84- model : aiConfig . model ?. name || 'gpt-4' ,
85- temperature : ( aiConfig . model ?. parameters ?. temperature as number ) ?? 0.5 ,
86- max_tokens : ( aiConfig . model ?. parameters ?. maxTokens as number ) ?? 4096 ,
87- } ) ,
79+ const tracker = aiConfig . createTracker ! ( ) ;
80+ const completion = await tracker . trackMetricsOf ( OpenAIProvider . getAIMetricsFromResponse , ( ) =>
81+ openai . chat . completions . create ( {
82+ messages : aiConfig . messages || [ ] ,
83+ model : aiConfig . model ?. name || 'gpt-4' ,
84+ temperature : ( aiConfig . model ?. parameters ?. temperature as number ) ?? 0.5 ,
85+ max_tokens : ( aiConfig . model ?. parameters ?. maxTokens as number ) ?? 4096 ,
86+ } ) ,
8887 ) ;
8988
9089 console . log ( 'AI Response:' , completion . choices [ 0 ] ?. message . content ) ;
0 commit comments