Commit 3eb6567e authored by Kantz's avatar Kantz
Browse files

vermeidung doppeltere Context_sheets

parent 0d77c8d6
......@@ -3,7 +3,7 @@ from __future__ import annotations
import time
from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Callable, List, TypeVar
from typing import Any, Callable, List, TypeVar
import app.config as config
from app.deterministic_services import (
......@@ -176,7 +176,11 @@ def bootstrap_retrieval(sheet: dict, query_text: str, tool_log: list[dict]) -> N
# Chat Status
# --
def init_chat_state(messages: list[dict], draft: str | None = None) -> ChatState:
def init_chat_state(
messages: list[dict],
draft: str | None = None,
init_sheet_fn: Callable[[str, list[dict]], dict[str, Any]] | None = None,
) -> ChatState:
if not messages:
raise ValueError("messages required")
......@@ -188,8 +192,9 @@ def init_chat_state(messages: list[dict], draft: str | None = None) -> ChatState
chat_id = context_store.get_chat_id(messages, draft=draft)
new_chat = is_new_chat(messages)
sheet = context_store.load_sheet(chat_id)
if new_chat or not sheet:
sheet = context_store.init_sheet(chat_id, messages)
if not sheet:
create_sheet = init_sheet_fn or context_store.init_sheet
sheet = create_sheet(chat_id, messages)
context_store.update_history(sheet, messages)
return ChatState(
......@@ -236,9 +241,10 @@ def run_chat_common(
on_bootstrap: Callable[[ChatState, str], None],
on_turn_logic: Callable[[ChatState], None],
on_build_reply: Callable[[ChatState], str | None],
init_sheet_fn: Callable[[str, list[dict]], dict[str, Any]] | None = None,
) -> dict:
init_started_at, init_started_perf = _start_timing()
state = init_chat_state(messages, draft)
state = init_chat_state(messages, draft, init_sheet_fn=init_sheet_fn)
init_finished_at, init_duration_ms = _finish_timing(init_started_perf)
append_tool_log(
state.tool_log,
......
......@@ -148,4 +148,5 @@ def run_chat(
on_bootstrap=on_bootstrap,
on_turn_logic=on_turn_logic,
on_build_reply=_on_build_reply,
init_sheet_fn=context_store.context_store_new.init_sheet,
)
......@@ -151,4 +151,5 @@ def run_chat(
on_bootstrap=on_bootstrap,
on_turn_logic=on_turn_logic,
on_build_reply=_on_build_reply,
init_sheet_fn=context_store.context_store_new.init_sheet,
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment