mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-06 02:48:04 +00:00
Tighten RAG file context scope handling
This commit is contained in:
parent
3a9b7dfcaa
commit
decc794dac
3 changed files with 10 additions and 4 deletions
|
|
@ -10,7 +10,7 @@ import shutil
|
|||
import uuid
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Callable, Iterator, Optional, Sequence, Union
|
||||
from typing import Callable, Iterator, Literal, Optional, Sequence, Union
|
||||
|
||||
import tiktoken
|
||||
from fastapi import (
|
||||
|
|
@ -653,7 +653,7 @@ class ConfigForm(BaseModel):
|
|||
TOP_K: int | None = None
|
||||
BYPASS_EMBEDDING_AND_RETRIEVAL: bool | None = None
|
||||
RAG_FULL_CONTEXT: bool | None = None
|
||||
RAG_FILE_CONTEXT_SCOPE: str | None = None
|
||||
RAG_FILE_CONTEXT_SCOPE: Literal['conversation', 'message'] | None = None
|
||||
|
||||
# Hybrid search settings
|
||||
ENABLE_RAG_HYBRID_SEARCH: bool | None = None
|
||||
|
|
|
|||
|
|
@ -955,11 +955,17 @@ def get_source_context(sources: list, source_ids: dict = None, include_content:
|
|||
return context_string
|
||||
|
||||
|
||||
FILE_CONTEXT_ITEM_TYPES = {'doc', 'text', 'note', 'chat', 'folder', 'collection'}
|
||||
|
||||
|
||||
def is_file_context_item(item: dict) -> bool:
|
||||
if not isinstance(item, dict):
|
||||
return False
|
||||
|
||||
return item.get('type') != 'image' and not (item.get('content_type') or '').startswith('image/')
|
||||
item_type = item.get('type')
|
||||
return item_type in FILE_CONTEXT_ITEM_TYPES or (
|
||||
item_type == 'file' and not (item.get('content_type') or '').startswith('image/')
|
||||
)
|
||||
|
||||
|
||||
def get_file_context_key(item: dict) -> tuple:
|
||||
|
|
|
|||
|
|
@ -2340,7 +2340,7 @@
|
|||
return {
|
||||
role: message.role,
|
||||
...(message.output ? { output: message.output } : {}),
|
||||
...(messageFiles.length > 0 ? { files: messageFiles } : {}),
|
||||
...(message.role === 'user' && messageFiles.length > 0 ? { files: messageFiles } : {}),
|
||||
...(message.role === 'user' && imageFiles.length > 0
|
||||
? {
|
||||
content: [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue