@@ -5,6 +5,7 @@ import { Readable } from 'node:stream';
55import { type FastifyPluginAsync } from 'fastify' ;
66import { type JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts' ;
77import { type SchemaTypes } from '../plugins/schemas.js' ;
8+ import { type ApproachContext } from '../lib/index.js' ;
89
910const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
1011
@@ -74,21 +75,26 @@ const root: FastifyPluginAsync = async (_fastify, _options): Promise<void> => {
7475 }
7576
7677 const { messages, context, stream } = request . body ;
78+ let approachContext : ApproachContext = ( context as any ) ?? { } ;
79+ if ( this . config . azureSearchSemanticRanker !== 'enabled' ) {
80+ approachContext = { ...approachContext , semantic_ranker : false } ;
81+ }
82+
7783 try {
7884 if ( stream ) {
7985 const buffer = new Readable ( ) ;
8086 // Dummy implementation needed
8187 buffer . _read = ( ) => { } ;
8288 reply . type ( 'application/x-ndjson' ) . send ( buffer ) ;
8389
84- const chunks = await chatApproach . runWithStreaming ( messages , ( context as any ) ?? { } ) ;
90+ const chunks = await chatApproach . runWithStreaming ( messages , approachContext ) ;
8591 for await ( const chunk of chunks ) {
8692 buffer . push ( JSON . stringify ( chunk ) + '\n' ) ;
8793 }
8894 // eslint-disable-next-line unicorn/no-null
8995 buffer . push ( null ) ;
9096 } else {
91- return await chatApproach . run ( messages , ( context as any ) ?? { } ) ;
97+ return await chatApproach . run ( messages , approachContext ) ;
9298 }
9399 } catch ( _error : unknown ) {
94100 const error = _error as Error & { error ?: any ; status ?: number } ;
@@ -121,21 +127,26 @@ const root: FastifyPluginAsync = async (_fastify, _options): Promise<void> => {
121127 }
122128
123129 const { messages, context, stream } = request . body ;
130+ let approachContext : ApproachContext = ( context as any ) ?? { } ;
131+ if ( this . config . azureSearchSemanticRanker !== 'enabled' ) {
132+ approachContext = { ...approachContext , semantic_ranker : false } ;
133+ }
134+
124135 try {
125136 if ( stream ) {
126137 const buffer = new Readable ( ) ;
127138 // Dummy implementation needed
128139 buffer . _read = ( ) => { } ;
129140 reply . type ( 'application/x-ndjson' ) . send ( buffer ) ;
130141
131- const chunks = await askApproach . runWithStreaming ( messages [ 0 ] . content , ( context as any ) ?? { } ) ;
142+ const chunks = await askApproach . runWithStreaming ( messages [ 0 ] . content , approachContext ) ;
132143 for await ( const chunk of chunks ) {
133144 buffer . push ( JSON . stringify ( chunk ) + '\n' ) ;
134145 }
135146 // eslint-disable-next-line unicorn/no-null
136147 buffer . push ( null ) ;
137148 } else {
138- return await askApproach . run ( messages [ 0 ] . content , ( context as any ) ?? { } ) ;
149+ return await askApproach . run ( messages [ 0 ] . content , approachContext ) ;
139150 }
140151 } catch ( _error : unknown ) {
141152 const error = _error as Error & { error ?: any ; status ?: number } ;
0 commit comments