Skip to main content
Version: Beta 🚧

Functions

prompt​

Decorator for creating a prompt.

Parameters

  • func (Optional[Callable[~P, ~T]]) - The function to decorate. Default: None

  • name (Optional[str]) - The name of the prompt. Default: None

  • sources (Optional[List[FeatureView]]) - The sources of the prompt. Default: None

  • rtfv_kwargs (Any) -

Returns

Callable[~P, ~T]

Example

# The simplest form without a feature dependency
from tecton_gen_ai.fco import prompt
@prompt()
def simple_prompt() -> str:
return "Hello, world!"
# With parameters but not a feature
from tecton_gen_ai.utils.tecton import make_request_source
params = make_request_source(zip=str)
@prompt(sources=[params])
def prompt_with_params(params) -> str:
return "Hello, you zip code " + params["zip"]
# With a feature dependency
from tecton_gen_ai.testing import make_local_batch_feature_view
my_bfv = make_local_batch_feature_view(
"my_bfv",
{"user_id":"u1", "name":"Bob"},
["user_id"],
description="User information",
)
@prompt(sources=[params, my_bfv])
def sys_prompt(params, my_bfv) -> str:
return "Hello, " + my_bfv["name"] + " with zip code " + params["zip"]
# Serve the prompt
from tecton_gen_ai.fco import AgentService
service = AgentService(
"my_service",
prompts=[sys_prompt],
)
# Test locally
from tecton_gen_ai.fco import AgentClient
client = AgentClient.from_local(service)
with client.set_context({"zip": "10065", "user_id": "u1"}):
res = client.invoke_prompt("sys_prompt")

tool​

Decorator for creating a tool. The tool can be used by different LLMs and frameworks such as Langchain and LlamaIndex.

Parameters

  • func (Optional[Callable[~P, ~T]]) - The function to decorate. Default: None

  • name (Optional[str]) - The name of the tool. Default: None

  • sources (Optional[List[FeatureView]]) - The sources of the tool. Default: None

  • descripton (Optional[str]) - The description of the tool. Default: None

  • subtype (str) - The subtype of the tool. Default: tool

  • rtfv_kwargs (Any) -

Returns

Callable[~P, ~T]

Example

# The simplest form without a feature dependency
from tecton_gen_ai.fco import tool
@tool()
def get_months_in_a_year() -> int:
'''The total number months of a year'''
return 12
# With parameters but not a feature
@tool()
def add(a: int, b: int) -> int:
'''Add two numbers
Args:
a (int): The first number
b (int): The second number
Returns:
int: The sum of the two numbers
'''
return a + b
# With a feature dependency
from tecton_gen_ai.testing import make_local_batch_feature_view
my_bfv = make_local_batch_feature_view(
"my_bfv",
{"user_id":"u1", "name":"Bob"},
["user_id"],
description="User information",
)
@tool(sources=[my_bfv])
def get_name(prefix:str, user_id:str, my_bfv) -> str:
'''Get the name of a user with a prefix
Args:
prefix (str): The prefix of the name
user_id (str): The user ID
Returns:
str: The name of the user with the prefix
'''
return prefix + " " + my_bfv["name"]
# Serve the tool
from tecton_gen_ai.fco import AgentService
service = AgentService(
"my_service",
tools=[get_name],
)
# Test locally
from tecton_gen_ai.fco import AgentClient
client = AgentClient.from_local(service)
with client.set_context({"user_id": "u1", "prefix": "Hello"}):
res = client.invoke_tool("get_name")

Was this page helpful?

🧠 Hi! Ask me anything about Tecton!

Floating button icon