Function call

Function call allows you to call a function from your code.

You can develop any function locally in any IDE or text editor, install any package you want, and add it to your pipeline.

During development, your pipeline will be connected to your local code through websockets.

When you deploy both your code and pipeline to an endpoint, the pipeline will call your function hosted on Laminar. As a result, your pipeline, together with your functions’ code, will be fully hosted on Laminar.

Start off by defining the function signature in the node. Give node a name and parameter names.

When you implement a function in your code, function name and its parameters’ names must match those defined in the graph. The function must return a string or a list of chat messages. If the function returns a more complex structure, such as a JSON dictionary, please stringify it.

Every parameter in the signature will add an input handle to the function call node.

For now, only Python code is supported.

Writing code and connecting it to pipeline

Check out our tutorial to learn how to simply call your local code by running lmnr dev and how to deploy using lmnr deploy.

It also shows how to structure code in your repository/directory to be able to use it with Laminar pipelines.

Implementation details

When you deploy your code and pipeline to an endpoint, Laminar spins up a container with your functions written in Python, which interfaces with our Rust engine through gRPC. Then, when you call your code through an endpoint, when engine executes this node, it will call the container through gRPC to execute your function.

Laminar remote debugger.

This is another way to call your functions instead of doing lmnr dev.

If you want to test a flow that includes a function call, you can use Laminar remote debugger in NodeJS or in Python.

The overall flow must be the following:

  1. Create a pipeline that includes function call nodes.
    1. Don’t forget to name function nodes after your local functions that you would like to call and define their signatures.
  2. Run the LaminarRemoteDebugger in your NodeJS or Python code with references to your local functions. This will return and print your unique session ID.
    1. Find specific instructions on how to do that in the SDK docs (README in each package)
  3. Copy the session ID and paste it as an environment variable DEBUGGER_SESSION_ID in lmnr.ai workshop in your browser.
  4. Run the pipeline from your browser

Calling endpoints through SDK

SDK in NodeJS or in Python support calling Laminar endpoints.

Example code snippets:

Python:

from lmnr import Laminar, NodeInput

def my_function(arg1: str, arg2: str) -> NodeInput:
    return f'{arg1}{arg2}'

l = Laminar('<YOUR_PROJECT_API_KEY>')
result = l.run(
    endpoint='my_endpoint_name',
    inputs={'input_node_name': [{'role': 'user', 'content': 'hello'}]},
    tools=[my_function]
)

JS:

import { Laminar, NodeInput } from '@lmnr-ai/lmnr';

const myFunction = ({arg1, arg2}: {arg1: string, arg2: number}): NodeInput => {
  // this tool teaches LLMs the beauty of JavaScript!
  return arg1 + arg2;
}

const l = new Laminar('<YOUR_PROJECT_API_KEY>');
const result = await l.run({
    endpoint: 'my_endpoint_name',
    inputs: {'input_node_name': [{'role': 'user', 'content': 'hello'}]},
    tools: [myFunction],
});

Read more on how to use our SDK in each package’s readme.