Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "worker",
"mode": "public",
"endpoint": true,
"endpoint_url": "0.0.0.0",
"endpoint_url": "127.0.0.1",
"endpoint_port": 64747,
"priority_nodes": [],
"logging": "WARNING"
Expand Down
7 changes: 7 additions & 0 deletions tensorlink/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class GenerationRequest(BaseModel):
output_format: Literal["raw", "openai"] = "raw"
is_chat_completion: bool = False

# Agentic tools. Handled entirely by the API process (tools/agents.py); the
# ML process never reads it.
web_search: Literal["off", "auto", "always"] = "off"


class ChatMessage(BaseModel):
role: str
Expand All @@ -73,6 +77,8 @@ class ChatCompletionRequest(BaseModel):
# Newer OpenAI SDKs send this instead of max_tokens; it wins when both are set.
max_completion_tokens: Optional[int] = Field(default=None, ge=1)
reasoning: Optional[bool] = False
# "off" | "auto" (model decides) | "always"; true is the same as "always"
web_search: Optional[Union[Literal["off", "auto", "always"], bool]] = None

presence_penalty: Optional[float] = 0.0
frequency_penalty: Optional[float] = 0.0
Expand Down Expand Up @@ -107,6 +113,7 @@ class TextResponseRequest(_BaseResponseRequest):
max_completion_tokens: Optional[int] = Field(default=None, ge=1)
stop: Optional[Union[str, List[str]]] = None
reasoning: Optional[bool] = False
web_search: Optional[Union[Literal["off", "auto", "always"], bool]] = None


class ImageResponseRequest(_BaseResponseRequest):
Expand Down
23 changes: 18 additions & 5 deletions tensorlink/api/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
ModelDistributionEntry,
EmbeddingCreateRequest,
)
from tensorlink.api.functions import build_hf_job_data, build_text_request
from tensorlink.api.utils import build_hf_job_data, build_text_request
from tensorlink.ml.utils.model_types import ModelType
from tensorlink.api.generation import GenerationMixin
from tensorlink.api.embeddings import EmbeddingMixin
from tensorlink.api.tools.generation import GenerationMixin
from tensorlink.api.tools.embeddings import EmbeddingMixin
from tensorlink.api.tools.agents import AgentMixin
from fastapi.middleware.cors import CORSMiddleware
from fastapi import FastAPI, HTTPException, APIRouter, Request, Query
from threading import Thread
import traceback
Expand All @@ -20,22 +22,33 @@
import asyncio


class TensorlinkAPI(GenerationMixin, EmbeddingMixin):
DEFAULT_CORS_ORIGINS = ["https://tensorlink.io"]


class TensorlinkAPI(GenerationMixin, EmbeddingMixin, AgentMixin):
"""
Supports API requests to request and interact with models, along with
probing node & job information.
"""

def __init__(self, smart_node, host="0.0.0.0", port=64747):
def __init__(self, smart_node, host="127.0.0.1", port=64747):
self.smart_node = smart_node
self.host = host
self.port = port
self.app = FastAPI()
self.app.add_middleware(
CORSMiddleware,
allow_origins=DEFAULT_CORS_ORIGINS,
allow_origin_regex=r"https?://(localhost|127\.0\.0\.1)(:\d+)?", # local dev servers
allow_methods=["*"],
allow_headers=["*"],
)
self.router = APIRouter()
self.server_loop = None

self._init_generation_state()
self._init_embedding_state()
self._init_agent_state()
self._define_routes()
self._start_server()

Expand Down
Empty file removed tensorlink/api/prompts.py
Empty file.
Loading
Loading