Code a compute graph
Code
# new file: test.py
import tinychain as tc
# this is the local TinyChain host you just started with "docker run..."
HOST = tc.host.Host("http://127.0.0.1:8702")
# this endpoint will attempt to run whatever program you send it
# without committing any write operations
ENDPOINT = "/transact/hypothetical"
# define a GET Op
# the type annotations are important!
# without them, TinyChain doesn't know what type to expect the arguments to be
@tc.get_op
def hello(name: tc.String) -> tc.String:
return tc.String("Hello, {{name}}").render(name=name)
if __name__ == "__main__":
cxt = tc.Context() # construct a new execution context
cxt.hello = hello # include our function definition in the context
cxt.result = cxt.hello("Name") # call the function
print(HOST.post(ENDPOINT, cxt)) # evaluate the context on the host
Test
Understand
Last updated
Was this helpful?