diff --git a/src/talemate/client/base.py b/src/talemate/client/base.py index 06f72460..e967b7f1 100644 --- a/src/talemate/client/base.py +++ b/src/talemate/client/base.py @@ -96,6 +96,7 @@ class CommonDefaults(pydantic.BaseModel): reason_enabled: bool = False reason_tokens: int = 0 reason_response_pattern: str | None = None + reason_prefill: str | None = None class Defaults(CommonDefaults, pydantic.BaseModel): @@ -322,6 +323,10 @@ class ClientBase: @property def reason_response_pattern(self) -> str: return self.client_config.reason_response_pattern or DEFAULT_REASONING_PATTERN + + @property + def reason_prefill(self) -> str: + return self.client_config.reason_prefill or "" @property def lock_template(self) -> bool: @@ -509,6 +514,14 @@ class ClientBase: double_coercion = f"{double_coercion}\n\n" else: double_coercion = None + + if self.reason_enabled and self.reason_prefill: + # if reasoning is enabled and a reason prefill is set, prepend it to the double coercion + # its important that it comes first. + if not double_coercion: + double_coercion = self.reason_prefill + else: + double_coercion = f"{self.reason_prefill}{double_coercion}" spec = PromptSpec() @@ -769,6 +782,7 @@ class ClientBase: "reason_tokens": self.reason_tokens, "min_reason_tokens": self.min_reason_tokens, "reason_response_pattern": self.reason_response_pattern, + "reason_prefill": self.reason_prefill, "requires_reasoning_pattern": self.requires_reasoning_pattern, "request_information": self.request_information.model_dump() if self.request_information diff --git a/src/talemate/config/schema.py b/src/talemate/config/schema.py index e6e1c1ec..42f2aef7 100644 --- a/src/talemate/config/schema.py +++ b/src/talemate/config/schema.py @@ -60,6 +60,10 @@ class Client(pydantic.BaseModel): # regex to strip from the response if the model is reasoning reason_response_pattern: Union[str, None] = None + + # reason prefill - will be prepended to the prompt if the model is reasoning + # this is mostly for base models that don't hhave reas + reason_prefill: str | None = None system_prompts: SystemPrompts = SystemPrompts() diff --git a/talemate_frontend/src/components/AIClient.vue b/talemate_frontend/src/components/AIClient.vue index 28bdd853..465fda9a 100644 --- a/talemate_frontend/src/components/AIClient.vue +++ b/talemate_frontend/src/components/AIClient.vue @@ -465,6 +465,7 @@ export default { client.reason_tokens = data.data.reason_tokens; client.min_reason_tokens = data.data.min_reason_tokens; client.reason_response_pattern = data.data.reason_response_pattern; + client.reason_prefill = data.data.reason_prefill; client.reason_enabled = data.data.reason_enabled; client.requires_reasoning_pattern = data.data.requires_reasoning_pattern; client.lock_template = data.data.lock_template; @@ -517,6 +518,7 @@ export default { reason_tokens: data.data.reason_tokens, min_reason_tokens: data.data.min_reason_tokens, reason_response_pattern: data.data.reason_response_pattern, + reason_prefill: data.data.reason_prefill, reason_enabled: data.data.reason_enabled, requires_reasoning_pattern: data.data.requires_reasoning_pattern, dedicated_default_template: data.data.dedicated_default_template, diff --git a/talemate_frontend/src/components/ClientModal.vue b/talemate_frontend/src/components/ClientModal.vue index dfd84213..5400815c 100644 --- a/talemate_frontend/src/components/ClientModal.vue +++ b/talemate_frontend/src/components/ClientModal.vue @@ -176,6 +176,14 @@ + + + + + This is mostly for base models that don't have reasoning built in, but were fine-tuned for reasoning. For example add <think> here to force the model to reason. Assuming <think> is the actual start of the thinking process, this may vary depending on the model. + + + @@ -406,6 +414,7 @@ export default { this.client.reason_tokens = defaults.reason_tokens || 0; this.client.min_reason_tokens = defaults.min_reason_tokens || 0; this.client.reason_response_pattern = defaults.reason_response_pattern || null; + this.client.reason_prefill = defaults.reason_prefill || null; this.client.requires_reasoning_pattern = defaults.requires_reasoning_pattern || false; this.client.lock_template = defaults.lock_template || false; this.client.template_file = defaults.template_file || null;