From f547f1424c24556e26c0d0d21e97800ec884cb15 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 29 Nov 2024 01:02:32 -0800 Subject: [PATCH] refac --- backend/open_webui/config.py | 65 ++++++++++++++++---------------- backend/open_webui/main.py | 4 +- backend/open_webui/utils/task.py | 4 +- src/lib/apis/index.ts | 4 +- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 72b16797c..70f8b0287 100644 --- a/backend/open_webui/config.py +++ b/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 `` tag. Additional guidance on the purpose, tone, or format will be included in a `` tag. +You are an autocompletion system. Continue the text in `` based on the **completion type** in `` and the given language. -Only output a continuation. If you are unsure how to proceed, output nothing. +### **Instructions**: +1. Analyze `` for context and meaning. +2. Use `` 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 ``. Do **not** repeat, paraphrase, or respond as a model. Simply complete the text. +4. Ensure the continuation: + - Flows naturally from ``. + - Avoids repetition, overexplaining, or unrelated ideas. +5. If unsure, return: `{ "text": "" }`. -### **Instructions** -1. Analyze the `` to understand its structure, context, and flow. -2. Refer to the `` 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 in JSON format: `{ "text": "" }`. -### **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: +Input: +General +The sun was setting over the horizon, painting the sky +Output: +{ "text": "with vibrant shades of orange and pink." } -### **Examples** +#### Example 2: +Input: +Search Query +Top-rated restaurants in +Output: +{ "text": "New York City for Italian cuisine." } -**Example 1** -General -The sun was dipping below the horizon, painting the sky in shades of pink and orange as the cool breeze began to set in. -**Output**: A sense of calm spread through the air, and the first stars started to shimmer faintly above. - -**Example 2** -Search -How to prepare for a job interview -**Output**: effectively, including researching the company and practicing common questions. - -**Example 3** -Search -Best destinations for hiking in -**Output**: Europe, such as the Alps or the Scottish Highlands. - -### Input: -{{CONTEXT}} - -{{PROMPT}} - +--- +### Input: +{{TYPE}} +{{PROMPT}} +#### Output: """ - TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = PersistentConfig( "TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE", "task.tools.prompt_template", diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 69dd84d8b..292c4d62c 100644 --- a/backend/open_webui/main.py +++ b/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 = { diff --git a/backend/open_webui/utils/task.py b/backend/open_webui/utils/task.py index 401d546d0..ea5027e4c 100644 --- a/backend/open_webui/utils/task.py +++ b/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( diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index 6f72685ca..f3d21cdab 100644 --- a/src/lib/apis/index.ts +++ b/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 }) })