Connection
Base URL, credentials and a reachable server.
Check linear_knots.py where an interior query becomes a weighted blend and an outside query becomes an endpoint.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
from math import isfinite
def interpolate(points, query):
def valid(x):
return type(x) in (int, float) and abs(x) <= 10**12 and isfinite(x)
if type(points) is not list or len(points) < 2 or not valid(query):
raise ValueError("knots.input")
if any(type(p) not in (list, tuple) or len(p) != 2 or
not all(valid(v) for v in p) for p in points):
raise ValueError("knots.point")
if any(a[0] >= b[0] for a,b in zip(points, points[1:])):
raise ValueError("knots.order")
if query <= points[0][0]:
return points[0][1]
for (x0,y0),(x1,y1) in zip(points, points[1:]):
if query <= x1:
t = (query-x0)/(x1-x0)
return (1-t)*y0+t*y1
return points[-1][1]