mirror of
https://github.com/vegu-ai/talemate.git
synced 2025-12-16 11:47:48 +01:00
add reason_prefill to force model to start with thinking block
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -176,6 +176,14 @@
|
||||
<v-text-field v-model="client.reason_response_pattern" label="Pattern to strip from the response if the model is reasoning" hint="This is a regular expression that will be used to strip out the thinking tokens from the response." placeholder=".*?</think>"></v-text-field>
|
||||
</v-col>
|
||||
</v-row>
|
||||
<v-row v-if="client.reason_enabled">
|
||||
<v-col cols="12">
|
||||
<v-text-field v-model="client.reason_prefill" label="Reason Prefill"></v-text-field>
|
||||
<v-alert color="muted" variant="text" class="text-caption">
|
||||
This is mostly for base models that don't have reasoning built in, but were fine-tuned for reasoning. For example add <code class="text-primary"><think></code> here to force the model to reason. Assuming <code class="text-primary"><think></code> is the actual start of the thinking process, this may vary depending on the model.
|
||||
</v-alert>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-window-item>
|
||||
<!-- SYSTEM PROMPTS -->
|
||||
<v-window-item value="system_prompts">
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user