Code Interpreter Auto-Prepare feature filesystem functionality

This commit is contained in:
karl
2025-06-01 05:39:10 +08:00
parent 92ce2fe004
commit f0b734fd7c
6 changed files with 947 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ from open_webui.utils.filter import (
get_sorted_filter_ids,
process_filter_functions,
)
from open_webui.utils.code_interpreter import execute_code_jupyter
from open_webui.utils.code_interpreter import execute_code_jupyter, generate_dynamic_code_interpreter_prompt
from open_webui.tasks import create_task
@@ -844,12 +844,25 @@ async def process_chat_payload(request, form_data, user, metadata, model):
)
if "code_interpreter" in features and features["code_interpreter"]:
# Generate dynamic prompt that includes file information
base_prompt = (
request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE
if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != ""
else DEFAULT_CODE_INTERPRETER_PROMPT
)
# Get attached files from metadata
attached_files = metadata.get("files", [])
# Generate enhanced prompt with file information
enhanced_prompt = generate_dynamic_code_interpreter_prompt(
base_prompt=base_prompt,
attached_files=attached_files,
chat_id=metadata.get("chat_id", "")
)
form_data["messages"] = add_or_update_user_message(
(
request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE
if request.app.state.config.CODE_INTERPRETER_PROMPT_TEMPLATE != ""
else DEFAULT_CODE_INTERPRETER_PROMPT
),
enhanced_prompt,
form_data["messages"],
)
@@ -2200,6 +2213,8 @@ async def process_chat_response(
else None
),
request.app.state.config.CODE_INTERPRETER_JUPYTER_TIMEOUT,
chat_id=metadata.get("chat_id", ""),
data_dir="data"
)
else:
output = {