mirror of
https://github.com/open-webui/open-webui
synced 2025-05-01 11:26:00 +00:00
refac
This commit is contained in:
parent
a07213b5be
commit
f547f1424c
@ -1005,47 +1005,46 @@ AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE = PersistentConfig(
|
|||||||
os.environ.get("AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE", ""),
|
os.environ.get("AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE", ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE = """### Task:
|
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.
|
You are an autocompletion system. Continue the text in `<text>` based on the **completion type** in `<type>` and the given language.
|
||||||
|
|
||||||
Only output a continuation. If you are unsure how to proceed, output nothing.
|
### **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": "" }`.
|
||||||
|
|
||||||
### **Instructions**
|
### **Output Rules**:
|
||||||
1. Analyze the `<text>` to understand its structure, context, and flow.
|
- Respond only in JSON format: `{ "text": "<your_completion>" }`.
|
||||||
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**
|
### **Examples**:
|
||||||
- Respond *only* with the continuation—no preamble or explanation.
|
#### Example 1:
|
||||||
- Ensure the continuation directly connects to the given text and adheres to the context.
|
Input:
|
||||||
- If unsure about completing, provide no output.
|
<type>General</type>
|
||||||
|
<text>The sun was setting over the horizon, painting the sky</text>
|
||||||
|
Output:
|
||||||
|
{ "text": "with vibrant shades of orange and pink." }
|
||||||
|
|
||||||
### **Examples**
|
#### Example 2:
|
||||||
|
Input:
|
||||||
**Example 1**
|
<type>Search Query</type>
|
||||||
<context>General</context>
|
<text>Top-rated restaurants in</text>
|
||||||
<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:
|
||||||
**Output**: A sense of calm spread through the air, and the first stars started to shimmer faintly above.
|
{ "text": "New York City for Italian cuisine." }
|
||||||
|
|
||||||
**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:
|
### Input:
|
||||||
<context>{{CONTEXT}}</context>
|
<type>{{TYPE}}</type>
|
||||||
<text>
|
<text>{{PROMPT}}</text>
|
||||||
{{PROMPT}}
|
#### Output:
|
||||||
</text>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = PersistentConfig(
|
TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE = PersistentConfig(
|
||||||
"TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE",
|
"TOOLS_FUNCTION_CALLING_PROMPT_TEMPLATE",
|
||||||
"task.tools.prompt_template",
|
"task.tools.prompt_template",
|
||||||
|
@ -2020,11 +2020,11 @@ async def generate_autocompletion(form_data: dict, user=Depends(get_verified_use
|
|||||||
else:
|
else:
|
||||||
template = DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE
|
template = DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE
|
||||||
|
|
||||||
context = form_data.get("context")
|
type = form_data.get("type")
|
||||||
prompt = form_data.get("prompt")
|
prompt = form_data.get("prompt")
|
||||||
|
|
||||||
content = autocomplete_generation_template(
|
content = autocomplete_generation_template(
|
||||||
template, prompt, context, {"name": user.name}
|
template, prompt, type, {"name": user.name}
|
||||||
)
|
)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -215,10 +215,10 @@ def emoji_generation_template(
|
|||||||
def autocomplete_generation_template(
|
def autocomplete_generation_template(
|
||||||
template: str,
|
template: str,
|
||||||
prompt: Optional[str] = None,
|
prompt: Optional[str] = None,
|
||||||
context: Optional[str] = None,
|
type: Optional[str] = None,
|
||||||
user: Optional[dict] = None,
|
user: Optional[dict] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
template = template.replace("{{CONTEXT}}", context if context else "")
|
template = template.replace("{{TYPE}}", type if type else "")
|
||||||
template = replace_prompt_variable(template, prompt)
|
template = replace_prompt_variable(template, prompt)
|
||||||
|
|
||||||
template = prompt_template(
|
template = prompt_template(
|
||||||
|
@ -403,7 +403,7 @@ export const generateAutoCompletion = async (
|
|||||||
token: string = '',
|
token: string = '',
|
||||||
model: string,
|
model: string,
|
||||||
prompt: string,
|
prompt: string,
|
||||||
context: string = 'search',
|
type: string = 'search query',
|
||||||
) => {
|
) => {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
let error = null;
|
let error = null;
|
||||||
@ -419,7 +419,7 @@ export const generateAutoCompletion = async (
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: model,
|
model: model,
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
context: context,
|
type: type,
|
||||||
stream: false
|
stream: false
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user