1+ import { env } from '@/lib/env'
12import { createLogger } from '@/lib/logs/console/logger'
23import { executeProviderRequest } from '@/providers'
34import { getApiKey , getProviderFromModel } from '@/providers/utils'
@@ -40,7 +41,7 @@ async function queryKnowledgeBase(
4041 } )
4142
4243 // Call the knowledge base search API directly
43- const searchUrl = `${ process . env . NEXT_PUBLIC_APP_URL || 'http://localhost:3000' } /api/knowledge/search`
44+ const searchUrl = `${ env . NEXT_PUBLIC_APP_URL || 'http://localhost:3000' } /api/knowledge/search`
4445
4546 const response = await fetch ( searchUrl , {
4647 method : 'POST' ,
@@ -65,7 +66,6 @@ async function queryKnowledgeBase(
6566 const result = await response . json ( )
6667 const results = result . data ?. results || [ ]
6768
68- // Extract content from search results
6969 const chunks = results . map ( ( r : any ) => r . content || '' ) . filter ( ( c : string ) => c . length > 0 )
7070
7171 logger . info ( `[${ requestId } ] Retrieved ${ chunks . length } chunks from knowledge base` )
@@ -140,18 +140,15 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`
140140 apiKey,
141141 } )
142142
143- // Handle streaming response (shouldn't happen with our request, but just in case)
144143 if ( response instanceof ReadableStream || ( 'stream' in response && 'execution' in response ) ) {
145144 throw new Error ( 'Unexpected streaming response from LLM' )
146145 }
147146
148147 const content = response . content . trim ( )
149148 logger . debug ( `[${ requestId } ] LLM response:` , { content } )
150149
151- // Try to parse JSON from the response
152150 let jsonContent = content
153151
154- // Remove markdown code blocks if present
155152 if ( content . includes ( '```' ) ) {
156153 const jsonMatch = content . match ( / ` ` ` (?: j s o n ) ? \s * ( \{ [ \s \S ] * ?\} ) \s * ` ` ` / )
157154 if ( jsonMatch ) {
@@ -191,7 +188,6 @@ export async function validateHallucination(
191188 input
192189
193190 try {
194- // Validate inputs
195191 if ( ! userInput || userInput . trim ( ) . length === 0 ) {
196192 return {
197193 passed : false ,
@@ -206,7 +202,6 @@ export async function validateHallucination(
206202 }
207203 }
208204
209- // Get API key for the model
210205 let finalApiKey : string
211206 try {
212207 const providerId = getProviderFromModel ( model )
@@ -248,8 +243,7 @@ export async function validateHallucination(
248243 threshold,
249244 } )
250245
251- // Step 3: Check against threshold
252- // Lower scores = less confidence = fail validation
246+ // Step 3: Check against threshold. Lower scores = less confidence = fail validation
253247 const passed = score >= threshold
254248
255249 return {
0 commit comments