소스 검색

refac: query generation

Timothy Jaeryang Baek 5 달 전
부모
커밋
907cf61da7
2개의 변경된 파일6개의 추가작업 그리고 8개의 파일을 삭제
  1. 3 2
      backend/open_webui/config.py
  2. 3 6
      src/lib/apis/index.ts

+ 3 - 2
backend/open_webui/config.py

@@ -972,7 +972,7 @@ DEFAULT_QUERY_GENERATION_PROMPT_TEMPLATE = """### Task:
 Based on the chat history, determine whether a search is necessary, and if so, generate a 1-3 broad search queries to retrieve comprehensive and updated information. If no search is required, return an empty list.
 
 ### Guidelines:
-- Respond exclusively with a JSON object.
+- Respond **EXCLUSIVELY** with a JSON object. Any form of extra commentary, explanation, or additional text is prohibited.
 - If a search query is needed, return an object like: { "queries": ["query1", "query2"] } where each query is distinct and concise.
 - If no search query is necessary, output should be: { "queries": [] }
 - Default to suggesting a search query to ensure accurate and updated information, unless it is definitively clear no search is required.
@@ -981,7 +981,8 @@ Based on the chat history, determine whether a search is necessary, and if so, g
 - Today's date is: {{CURRENT_DATE}}
 
 ### Output:
-JSON format: {
+Strictly return in JSON format: 
+{
   "queries": ["query1", "query2"]
 }
 

+ 3 - 6
src/lib/apis/index.ts

@@ -391,16 +391,13 @@ export const generateQueries = async (
 		// Step 1: Safely extract the response string
 		const response = res?.choices[0]?.message?.content ?? '';
 
-		// Step 2: Attempt to fix common JSON format issues like single quotes
-		const sanitizedResponse = response.replace(/['‘’`]/g, '"'); // Convert single quotes to double quotes for valid JSON
-
 		// Step 3: Find the relevant JSON block within the response
-		const jsonStartIndex = sanitizedResponse.indexOf('{');
-		const jsonEndIndex = sanitizedResponse.lastIndexOf('}');
+		const jsonStartIndex = response.indexOf('{');
+		const jsonEndIndex = response.lastIndexOf('}');
 
 		// Step 4: Check if we found a valid JSON block (with both `{` and `}`)
 		if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
-			const jsonResponse = sanitizedResponse.substring(jsonStartIndex, jsonEndIndex + 1);
+			const jsonResponse = response.substring(jsonStartIndex, jsonEndIndex + 1);
 
 			// Step 5: Parse the JSON block
 			const parsed = JSON.parse(jsonResponse);