Timothy Jaeryang Baek 5 月之前
父節點
當前提交
f547f1424c
共有 4 個文件被更改,包括 43 次插入44 次删除
  1. 37 38
      backend/open_webui/config.py
  2. 2 2
      backend/open_webui/main.py
  3. 2 2
      backend/open_webui/utils/task.py
  4. 2 2
      src/lib/apis/index.ts

+ 37 - 38
backend/open_webui/config.py

@@ -1005,47 +1005,46 @@ AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE = PersistentConfig(
     os.environ.get("AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE", ""),
 )
 
+
 DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE = """### Task:
-You are an **autocompletion system**. Your sole task is to generate concise, logical continuations for text provided within the `<text>` tag. Additional guidance on the purpose, tone, or format will be included in a `<context>` tag. 
-
-Only output a continuation. If you are unsure how to proceed, output nothing.
-
-### **Instructions**
-1. Analyze the `<text>` to understand its structure, context, and flow.
-2. Refer to the `<context>` for any specific purpose or format (e.g., search queries, general, etc.).
-3. Complete the text concisely and meaningfully without repeating or altering the original.
-4. Do not introduce unrelated ideas or elaborate unnecessarily.
-
-### **Output Rules**
-- Respond *only* with the continuation—no preamble or explanation.
-- Ensure the continuation directly connects to the given text and adheres to the context.
-- If unsure about completing, provide no output.
-
-### **Examples**
-
-**Example 1**  
-<context>General</context>
-<text>The sun was dipping below the horizon, painting the sky in shades of pink and orange as the cool breeze began to set in.</text>
-**Output**: A sense of calm spread through the air, and the first stars started to shimmer faintly above.
-
-**Example 2**  
-<context>Search</context>
-<text>How to prepare for a job interview</text>
-**Output**: effectively, including researching the company and practicing common questions.
-
-**Example 3**  
-<context>Search</context>
-<text>Best destinations for hiking in</text> 
-**Output**: Europe, such as the Alps or the Scottish Highlands.
-
-### Input:
-<context>{{CONTEXT}}</context>
-<text>
-{{PROMPT}}
-</text>
+You are an autocompletion system. Continue the text in `<text>` based on the **completion type** in `<type>` and the given language.  
+
+### **Instructions**:
+1. Analyze `<text>` for context and meaning.  
+2. Use `<type>` to guide your output:  
+   - **General**: Provide a natural, concise continuation.  
+   - **Search Query**: Complete as if generating a realistic search query.  
+3. Start as if you are directly continuing `<text>`. Do **not** repeat, paraphrase, or respond as a model. Simply complete the text.  
+4. Ensure the continuation:
+   - Flows naturally from `<text>`.  
+   - Avoids repetition, overexplaining, or unrelated ideas.  
+5. If unsure, return: `{ "text": "" }`.  
+
+### **Output Rules**:
+- Respond only in JSON format: `{ "text": "<your_completion>" }`.
+
+### **Examples**:
+#### Example 1:  
+Input:  
+<type>General</type>  
+<text>The sun was setting over the horizon, painting the sky</text>  
+Output:  
+{ "text": "with vibrant shades of orange and pink." }
+
+#### Example 2:  
+Input:  
+<type>Search Query</type>  
+<text>Top-rated restaurants in</text>  
+Output:  
+{ "text": "New York City for Italian cuisine." }  
+
+---
+### Input:  
+<type>{{TYPE}}</type>  
+<text>{{PROMPT}}</text>  
+#### Output:
 """
 
-
 TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = PersistentConfig(
     "TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE",
     "task.tools.prompt_template",

+ 2 - 2
backend/open_webui/main.py

@@ -2020,11 +2020,11 @@ async def generate_autocompletion(form_data: dict, user=Depends(get_verified_use
     else:
         template = DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE
 
-    context = form_data.get("context")
+    type = form_data.get("type")
     prompt = form_data.get("prompt")
 
     content = autocomplete_generation_template(
-        template, prompt, context, {"name": user.name}
+        template, prompt, type, {"name": user.name}
     )
 
     payload = {

+ 2 - 2
backend/open_webui/utils/task.py

@@ -215,10 +215,10 @@ def emoji_generation_template(
 def autocomplete_generation_template(
     template: str,
     prompt: Optional[str] = None,
-    context: Optional[str] = None,
+    type: Optional[str] = None,
     user: Optional[dict] = None,
 ) -> str:
-    template = template.replace("{{CONTEXT}}", context if context else "")
+    template = template.replace("{{TYPE}}", type if type else "")
     template = replace_prompt_variable(template, prompt)
 
     template = prompt_template(

+ 2 - 2
src/lib/apis/index.ts

@@ -403,7 +403,7 @@ export const generateAutoCompletion = async (
 	token: string = '',
 	model: string,
 	prompt: string,
-	context: string = 'search',
+	type: string = 'search query',
 ) => {
 	const controller = new AbortController();
 	let error = null;
@@ -419,7 +419,7 @@ export const generateAutoCompletion = async (
 		body: JSON.stringify({
 			model: model,
 			prompt: prompt,
-			context: context,
+			type: type,
 			stream: false
 		})
 	})