PromptDesk Logo

PromptDesk OS

Models

Add and modify any LLM model using the code editor. Models are defined as API calls and can be used in prompts.

Completion Prompt

Model Definition

Each model is defined as a JSON object with the following main components:

  • API Call
  • Request Mapping
  • Response Mapping
  • Model Parameters

API Call

The API call is the endpoint that will be used to generate the prompt. API keys should be replaced with variables with the following format: {{VARIABLE_NAME}}. Variables can be added in the PromptDesk settings.

OpenAI example

{
  "url": "https://api.openai.com/v1/chat/completions",
  "method": "POST",
  "headers": {
    "Authorization": "Bearer {{OPENAI_API_KEY}}",
    "Content-Type": "application/json"
  }
}

Cohere example

{
    "url": "https://api.cohere.ai/v1/chat",
    "method": "POST",
    "headers": {
        "Authorization": "Bearer {{COHERE_API_KEY}}",
        "Content-Type": "application/json"
    }
}

Anthropic example

{
    "url": "https://api.anthropic.com/v1/messages",
    "method": "POST",
    "headers": {
        "x-api-key": "{{ANTHROPIC_API_KEY}}",
        "anthropic-version": "2023-06-01",
        "anthropic-beta": "messages-2023-12-15",
        "content-type": "application/json"
    }
}

Try this!

Try calling the API in Postman or using the requests library in Python to make sure the API is working as expected. If the API requires an API key, make sure to replace it with a variable. If everything is working as expected, you can add the API key as a variable in the PromptDesk settings.


Request Mapping

PromptDesk uses a mapping specification to map a standard PromptDesk JSON prompt object to almost infinite number of models with different request and response formats.

The request mapping is a list of rules that define how to map the prompt data to the API request body for different models.

PromptDesk currently supports two types of models and request mappings:

PromptDesk Completion Prompt

{
  "prompt": "string",
  "model_parameters": {
    "<parameter name>": "<parameter value>"",
  }
}

PromptDesk Chat Prompt

{
  "context": "string",
  "messages": [
    {
      "role": "<role name>",
      "content": "string"
    }
  ],
  "model_parameters": {
    "<parameter name>": "<parameter value>",
  }
}

The goal of the request mapping is to transform the standard PromptDesk JSON prompt object into a valid API request body for the model.

Check this out!

You can find example request mappings in the PromptDesk GitHub Models repository. You can also get free support by opening an issue in the repository or by contacting us at [email protected].

The request mapping definition can be found below.


Response Mapping

The response mapping is a list of rules that define how to map the API response to a standard PromptDesk JSON response object.

Check this out!

You can find example response mappings in the PromptDesk GitHub Models repository. You can also get free support by opening an issue in the repository or by contacting us at [email protected].

The response mapping definition can be found below.


Model Parameters

Model parameters are additional parameters that can be provided to the API call. These parameters are optional and may take the following types:

  • slider - A slider input
  • text - A text input
  • number - A number input

Parameters that have a type defined will be displayed in the prompt builder. Chat prompts must have a roles parameter defined.

{
  "roles": [
    "user",
    "assistant"
  ],
  "max_tokens": {
    "key": "max_tokens",
    "type": "slider",
    "name": "Max Tokens",
    "default": 2000,
    "step": 50,
    "min": 0,
    "max": 4000
  },
  "temperature": {
    "key": "temperature",
    "type": "slider",
    "name": "Temperature",
    "default": 0.7,
    "step": 0.01,
    "min": 0,
    "max": 1
  }
}

Important to note!

Ensure that the values specified for "roles" and the keys for model parameters precisely align with the format outlined in the third-party API documentation. It is crucial that these parameters directly correspond, on a one-to-one basis, with the details provided by the third-party API to ensure proper functionality and integration.


Mapping Documentation

PromptDesk JSONMapper is a tool that facilitates JSON to a target JSON structure. It supports simple field-to-field mapping, default values, conditional mapping, and nested array mapping.

This allows us to map the standard PromptDesk JSON prompt object to almost infinite number of models with different request and response formats.

Mapping Rules

Each rule in the mapping list is a dictionary that defines how to map a field from the source JSON to the target JSON. The basic structure of a rule is:

{
    "sourceField": "<path to source field>",
    "targetField": "<path to target field>"
}

The <path to source/target field> is a string that specifies the path to the field in the JSON object. It uses dot notation for nested fields and array indices. For example, "field.subfield" refers to the subfield inside field, and "array.1.field" refers to the field inside the second item of array.

Default Values

You can specify a default value to use when the source field is not present in the source JSON:

{
    "sourceField": "<path to source field>",
    "targetField": "<path to target field>",
    "default": "<default value>"
}

Conditional Mapping

You can add conditions to a rule to control when it should be applied. Conditions are specified in a conditions list:

{
    "sourceField": "<path to source field>",
    "targetField": "<path to target field>",
    "conditions": [
        {
            "sourceField": "<path to source field for condition>",
            "check": "<condition type>",
            "value": "<value for condition>"
        }
    ]
}

The <condition type> can be one of the following:

  • "equals": The rule is applied if the source field value equals the specified value.
  • "not-equals": The rule is applied if the source field value does not equal the specified value.
  • "exists": The rule is applied if the source field exists.

Nested Array Mapping

If the source field is an array of dictionaries, you can use subRules to map the fields inside each dictionary:

{
    "sourceField": "<path to source array>",
    "targetField": "<path to target field>",
    "action": "mapArray",
    "subRules": [
        {
            "sourceField": "<path to source field inside array item>",
            "targetField": "<path to target field inside array item>"
        }
    ]
}

Transformation Rules

You can add transformation rules to a rule to modify the source field value before mapping it to the target field:

{
    "sourceField": "<path to source field>",
    "targetField": "<path to target field>",
    "transformation": {
        "text": ["<transformation type>"],
        "conditions": [
            {
                "when": {
                    "field": "value",
                    "equals": "<value>"
                },
                "transformTo": "<new value>"
            }
        ]
    }
}

The <transformation type> can be one of the following:

  • "uppercase": Converts the source field value to uppercase.
  • "lowercase": Converts the source field value to lowercase.
  • "strip": Removes leading and trailing whitespace from the source field value.

The conditions list in the transformation dictionary can be used to specify conditions for the transformation. The transformation is applied when the source field value equals the specified value.

Previous
Variables