mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-14 15:57:27 +00:00
API: Modify tool calling for wider compat
When revisiting tool calls, the formats have more or less become standard. For greater compatibility with templates, primarily use the message.tools parameter and remove the extra custom metadata that is no longer required. However, unlike other backends, tabbyAPI still uses template metadata to declare what the tool start string is. This allows for template-level customization along with giving more power to the user while the server exists to consume rather than work on a case-by-case basis. Signed-off-by: kingbri <8082010+kingbri1@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import traceback
|
||||
import aiofiles
|
||||
import json
|
||||
import pathlib
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from importlib.metadata import version as package_version
|
||||
from typing import List, Optional
|
||||
from jinja2 import Template, TemplateError
|
||||
@@ -11,7 +13,6 @@ from jinja2.ext import loopcontrols
|
||||
from jinja2.sandbox import ImmutableSandboxedEnvironment
|
||||
from loguru import logger
|
||||
from packaging import version
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from common.utils import unwrap
|
||||
@@ -23,11 +24,12 @@ class TemplateLoadError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass
|
||||
class TemplateMetadata:
|
||||
"""Represents the parsed metadata from a template."""
|
||||
|
||||
stop_strings: List[str] = []
|
||||
tool_starts: List[str] = []
|
||||
stop_strings: List[str] = field(default_factory=list)
|
||||
tool_start: Optional[str] = None
|
||||
|
||||
|
||||
class PromptTemplate:
|
||||
@@ -72,11 +74,7 @@ class PromptTemplate:
|
||||
|
||||
if hasattr(template_module, "tool_start"):
|
||||
if isinstance(template_module.tool_start, str):
|
||||
template_metadata.tool_starts.append(template_module.tool_start)
|
||||
|
||||
if hasattr(template_module, "tool_start_token"):
|
||||
if isinstance(template_module.tool_start_token, int):
|
||||
template_metadata.tool_starts.append(template_module.tool_start_token)
|
||||
template_metadata.tool_start = template_module.tool_start
|
||||
|
||||
self.metadata = template_metadata
|
||||
return template_metadata
|
||||
|
||||
Reference in New Issue
Block a user