mirror of
https://github.com/lfnovo/open-notebook.git
synced 2026-10-14 03:43:45 +00:00
fix: inject notebook name and description into chat system prompt (#719)
Some checks are pending
Development Build / extract-version (push) Waiting to run
Development Build / build-regular (push) Blocked by required conditions
Development Build / build-single (push) Blocked by required conditions
Development Build / summary (push) Blocked by required conditions
Tests / Backend Tests (push) Waiting to run
Tests / Frontend Tests (push) Waiting to run
Some checks are pending
Development Build / extract-version (push) Waiting to run
Development Build / build-regular (push) Blocked by required conditions
Development Build / build-single (push) Blocked by required conditions
Development Build / summary (push) Blocked by required conditions
Tests / Backend Tests (push) Waiting to run
Tests / Frontend Tests (push) Waiting to run
The chat system prompt template had a conditional block for notebook metadata but the /chat/execute endpoint never populated it. Fetch the notebook linked to the session via the refers_to relationship and pass it to the graph state so the LLM receives the notebook's name and description as project context. Closes #685
This commit is contained in:
parent
8e74e492d3
commit
000f46a30a
2 changed files with 12 additions and 1 deletions
|
|
@ -342,6 +342,15 @@ async def execute_chat(request: ExecuteChatRequest):
|
|||
if not session:
|
||||
raise HTTPException(status_code=404, detail="Session not found")
|
||||
|
||||
# Fetch notebook linked to this session
|
||||
notebook_query = await repo_query(
|
||||
"SELECT out FROM refers_to WHERE in = $session_id",
|
||||
{"session_id": ensure_record_id(full_session_id)},
|
||||
)
|
||||
notebook = None
|
||||
if notebook_query:
|
||||
notebook = await Notebook.get(notebook_query[0]["out"])
|
||||
|
||||
# Determine model override (per-request override takes precedence over session-level)
|
||||
model_override = (
|
||||
request.model_override
|
||||
|
|
@ -360,6 +369,7 @@ async def execute_chat(request: ExecuteChatRequest):
|
|||
state_values = current_state.values if current_state else {}
|
||||
state_values["messages"] = state_values.get("messages", [])
|
||||
state_values["context"] = request.context
|
||||
state_values["notebook"] = notebook
|
||||
state_values["model_override"] = model_override
|
||||
|
||||
# Add user message to state
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ Whenever a user asks you a question, you need to identify the query context and
|
|||
{% if notebook %}
|
||||
# PROJECT INFORMATION
|
||||
|
||||
{{notebook}}
|
||||
**Name:** {{notebook.name}}
|
||||
**Description:** {{notebook.description}}
|
||||
{% endif %}
|
||||
|
||||
{% if context %}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue