@@ -5,6 +5,7 @@ import { Readable } from 'node:stream';
5
5
import { type FastifyPluginAsync } from 'fastify' ;
6
6
import { type JsonSchemaToTsProvider } from '@fastify/type-provider-json-schema-to-ts' ;
7
7
import { type SchemaTypes } from '../plugins/schemas.js' ;
8
+ import { type ApproachContext } from '../lib/index.js' ;
8
9
9
10
const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
10
11
@@ -74,21 +75,26 @@ const root: FastifyPluginAsync = async (_fastify, _options): Promise<void> => {
74
75
}
75
76
76
77
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
+
77
83
try {
78
84
if ( stream ) {
79
85
const buffer = new Readable ( ) ;
80
86
// Dummy implementation needed
81
87
buffer . _read = ( ) => { } ;
82
88
reply . type ( 'application/x-ndjson' ) . send ( buffer ) ;
83
89
84
- const chunks = await chatApproach . runWithStreaming ( messages , ( context as any ) ?? { } ) ;
90
+ const chunks = await chatApproach . runWithStreaming ( messages , approachContext ) ;
85
91
for await ( const chunk of chunks ) {
86
92
buffer . push ( JSON . stringify ( chunk ) + '\n' ) ;
87
93
}
88
94
// eslint-disable-next-line unicorn/no-null
89
95
buffer . push ( null ) ;
90
96
} else {
91
- return await chatApproach . run ( messages , ( context as any ) ?? { } ) ;
97
+ return await chatApproach . run ( messages , approachContext ) ;
92
98
}
93
99
} catch ( _error : unknown ) {
94
100
const error = _error as Error & { error ?: any ; status ?: number } ;
@@ -121,21 +127,26 @@ const root: FastifyPluginAsync = async (_fastify, _options): Promise<void> => {
121
127
}
122
128
123
129
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
+
124
135
try {
125
136
if ( stream ) {
126
137
const buffer = new Readable ( ) ;
127
138
// Dummy implementation needed
128
139
buffer . _read = ( ) => { } ;
129
140
reply . type ( 'application/x-ndjson' ) . send ( buffer ) ;
130
141
131
- const chunks = await askApproach . runWithStreaming ( messages [ 0 ] . content , ( context as any ) ?? { } ) ;
142
+ const chunks = await askApproach . runWithStreaming ( messages [ 0 ] . content , approachContext ) ;
132
143
for await ( const chunk of chunks ) {
133
144
buffer . push ( JSON . stringify ( chunk ) + '\n' ) ;
134
145
}
135
146
// eslint-disable-next-line unicorn/no-null
136
147
buffer . push ( null ) ;
137
148
} else {
138
- return await askApproach . run ( messages [ 0 ] . content , ( context as any ) ?? { } ) ;
149
+ return await askApproach . run ( messages [ 0 ] . content , approachContext ) ;
139
150
}
140
151
} catch ( _error : unknown ) {
141
152
const error = _error as Error & { error ?: any ; status ?: number } ;
0 commit comments