Generative Actions

In this guide we will go through a practical example of building an Action in Klu. By the end of this tutorial you will have an Action that will help you analyze any content and create a summary.

Creating your first Action

In the previous guide we have covered all the key aspects of Klu and have set you up with a workspace and a model provider. In this guide we will walk you through the process of creating an action that you can use to analyse content.

To get started simply click on new app and you will be presented with the options to create a new app and action together.

From the list of options choose "Complex prompt". This already includes a simple example of how Klu handles variables in the prompt.

Prompt Config

You are now in the action creation modal. First let's take a look at what is on the page:

  • Name - this is the name of your action. Make it short and clear. For instance Content Analyzer.
  • Description - Here you will need to put in the description of what the action does. Aim to explain what the action does in a sentence. If we are to take an example here for our action it will be something like: Analyzes any given piece of text content.
  • Prompt - This is the prompt that we will augment and send to the model. For this tutorial we will use the following prompt below. The way Klu injects text dynamically is through the use of variables such as: {{example}}. This allows us to create a template once and only ask you for the relevant information and we do the rest for you.

Prompt Template

Analyze the following content Provide a summary of the main arguments ======
  • Provider - Choose from the model providers you have added to your Klu account. For this tutorial we are going with OpenAI.
  • Model - Choose the model for your action. For this tutorial we are going with GPT-4.

What this prompt will do is ask you to input a value for the variable content. This will then get injected into the prompt and sent to the model together. Which in turn will perform the task and reply with the analysis.

We are now ready. Click on the create button on the bottom right and you are ready.

Model Config

The action is now ready, however, let's take one more moment to look at the model level configuration. When you create an action in Klu by default we will go and create it with the default model parameters. However should you need to change that here is what the options are:

  • Model temperature: Default 0.7
    This parameter controls the randomness of the model's output. A higher temperature (closer to 1) results in more random outputs, while a lower temperature (closer to 0) makes the outputs more deterministic and focused. If you want the model to produce diverse and creative responses, use a higher temperature. If you want the model to stick to the most likely response, use a lower temperature.
  • Max response length: Default 250 tokens
    This parameter sets the maximum number of tokens (words or characters, depending on the model) in the model's output. This allows you to control how verbose or concise the model's responses are.
  • Stop sequence: Default empty
    This is a special sequence of tokens which, when detected by the model in its output, causes it to stop generating further tokens. This can be useful for controlling where the model ends its responses, particularly in dialogue systems.
  • Top P: Default 1
    Also known as nucleus sampling, this parameter sets a threshold for token probability, and only tokens with a probability higher than this threshold are considered for the next token in the output. This can help control the diversity and quality of the model's output.
  • Presence Penalty: Default 0
    This parameter penalizes or rewards the model for generating tokens that are already present in the conversation. A higher presence penalty encourages the model to generate new and unique tokens, while a lower one allows the model to reuse tokens that are already in the text.
  • Frequency Penalty: Default 0
    This parameter penalizes or rewards the model for generating tokens that are common in the language overall. A higher frequency penalty discourages the model from using common words and phrases, while a lower one allows it to use them freely.

You can change all of those values at any given time by clicking on the "Edit" button when you are in an action and then clicking on the "Model Config" tab. There are no hard and fast rules when it comes to large language models and taste plays a big part when evaluating outputs, so we encourage experimentation to find the settings that work best for you. Having said that here are some tips:

  • For conversational agents that need to choose between different skills a lower temperature (<0.15) is recommended.
  • For more creative content generation higher temperature results in output that do not feel as repetitive.

Deploy your Action

Once you have created your action, deploying it is as simple as clicking on the "Deploy" button in the top right corner.

That will open up a pop-up with the action guid and a few examples of how to connect. We support 4 ways:

  • Shareable Public URL
  • API call (with a cURL example)
  • Python SDK
  • TypeScript SDK

Test your Action

The easiest way to test your action in Klu is to head over to the Prompt page from the edit action screen. There you will be asked to input all the relevant information for the action and you can test it quickly to confirm that it's all working as expected.

Now you are fully set up with Klu with your own action and you can see how quickly you can experiment and also integrate this into production once you are happy.