Does the API support prefixes for LLM output?

Exactly what the header says. I use generation prefixes for the LLMs output all the time, so that it has an easier time responding with exactly what I want. for example, if i want it to generate code, I might put '''python\n as a prefix.

I know that groq, ollama and mistral all support this feature… but i have noticed that this API doesn’t seem to work that way. (I’m using the REST api, not some OpenAI library)

1 Like

@marty.friedrich

Which model was giving you the markdown without the language tag 405B instruct provided it

curl -H "Authorization: Bearer xxxxxxxxxxxxxxx" \
     -H "Content-Type: application/json" \
     -d '{
        "stream": false,
        "model": "Meta-Llama-3.1-405B-Instruct",
        "messages": [
                {
                        "role": "user",
                        "content": [
                                {
                                        "type": "text",
                                        "text": "Write a Python program to create a binary search tree."
                                }
                        ]
                }
        ]
        }' \
     -X POST https://api.sambanova.ai/v1/chat/completions
{"choices":[{"finish_reason":"stop","index":0,"logprobs":null,"message":{"content":"**Binary Search Tree Implementation in Python**\n=====================================================\n\nBelow is a Python implementation of a binary search tree. This implementation includes methods for inserting nodes, traversing the tree (inorder, preorder, and postorder), and searching for a specific value.\n\n```python\nclass Node:\n    \"\"\"\n    Represents a node in the binary search tree.\n    \n    Attributes:\n    value (int): The value stored in the node.\n    left (Node): The left child of the node.\n    right (Node): The right child of the node.\n    \"\"\"\n    def __init__(self, value):\n        self.value = value\n        self.left = None\n        self.right = None\n\nclass BinarySearchTree:\n    \"\"\"\n    Represents a binary search tree.\n    \n    Attributes:\n    root (Node): The root node of the tree.\n    \"\"\"\n    def __init__(self):\n        self.root = None\n\n    def insert(self, value):\n        \"\"\"\n        Inserts a new node with the given value into the tree.\n        \n        Args:\n        value (int): The value to be inserted.\n        \"\"\"\n        if self.root is None:\n            self.root = Node(value)\n        else:\n            self._insert_recursive(self.root, value)\n\n    def _insert_recursive(self, current_node, value):\n        \"\"\"\n        Recursively inserts a new node into the tree.\n        \n        Args:\n        current_node (Node): The current node being processed.\n        value (int): The value to be inserted.\n        \"\"\"\n        if value \u003c current_node.value:\n            if current_node.left is None:\n                current_node.left = Node(value)\n            else:\n                self._insert_recursive(current_node.left, value)\n        else:\n            if current_node.right is None:\n                current_node.right = Node(value)\n            else:\n                self._insert_recursive(current_node.right, value)\n\n    def inorder_traversal(self):\n        \"\"\"\n        Performs an inorder traversal of the tree and returns the values in ascending order.\n        \n        Returns:\n        list: A list of values in ascending order.\n        \"\"\"\n        result = []\n        self._inorder_traversal_recursive(self.root, result)\n        return result\n\n    def _inorder_traversal_recursive(self, current_node, result):\n        \"\"\"\n        Recursively performs an inorder traversal of the tree.\n        \n        Args:\n        current_node (Node): The current node being processed.\n        result (list): The list of values.\n        \"\"\"\n        if current_node:\n            self._inorder_traversal_recursive(current_node.left, result)\n            result.append(current_node.value)\n            self._inorder_traversal_recursive(current_node.right, result)\n\n    def preorder_traversal(self):\n        \"\"\"\n        Performs a preorder traversal of the tree and returns the values.\n        \n        Returns:\n        list: A list of values.\n        \"\"\"\n        result = []\n        self._preorder_traversal_recursive(self.root, result)\n        return result\n\n    def _preorder_traversal_recursive(self, current_node, result):\n        \"\"\"\n        Recursively performs a preorder traversal of the tree.\n        \n        Args:\n        current_node (Node): The current node being processed.\n        result (list): The list of values.\n        \"\"\"\n        if current_node:\n            result.append(current_node.value)\n            self._preorder_traversal_recursive(current_node.left, result)\n            self._preorder_traversal_recursive(current_node.right, result)\n\n    def postorder_traversal(self):\n        \"\"\"\n        Performs a postorder traversal of the tree and returns the values.\n        \n        Returns:\n        list: A list of values.\n        \"\"\"\n        result = []\n        self._postorder_traversal_recursive(self.root, result)\n        return result\n\n    def _postorder_traversal_recursive(self, current_node, result):\n        \"\"\"\n        Recursively performs a postorder traversal of the tree.\n        \n        Args:\n        current_node (Node): The current node being processed.\n        result (list): The list of values.\n        \"\"\"\n        if current_node:\n            self._postorder_traversal_recursive(current_node.left, result)\n            self._postorder_traversal_recursive(current_node.right, result)\n            result.append(current_node.value)\n\n    def search(self, value):\n        \"\"\"\n        Searches for a node with the given value in the tree.\n        \n        Args:\n        value (int): The value to be searched.\n        \n        Returns:\n        bool: True if the value is found, False otherwise.\n        \"\"\"\n        return self._search_recursive(self.root, value)\n\n    def _search_recursive(self, current_node, value):\n        \"\"\"\n        Recursively searches for a node with the given value in the tree.\n        \n        Args:\n        current_node (Node): The current node being processed.\n        value (int): The value to be searched.\n        \n        Returns:\n        bool: True if the value is found, False otherwise.\n        \"\"\"\n        if current_node is None:\n            return False\n        if value == current_node.value:\n            return True\n        elif value \u003c current_node.value:\n            return self._search_recursive(current_node.left, value)\n        else:\n            return self._search_recursive(current_node.right, value)\n\n\n# Example usage\nif __name__ == \"__main__\":\n    bst = BinarySearchTree()\n    bst.insert(8)\n    bst.insert(3)\n    bst.insert(10)\n    bst.insert(1)\n    bst.insert(6)\n    bst.insert(14)\n    bst.insert(4)\n    bst.insert(7)\n    bst.insert(13)\n\n    print(\"Inorder traversal:\", bst.inorder_traversal())\n    print(\"Preorder traversal:\", bst.preorder_traversal())\n    print(\"Postorder traversal:\", bst.postorder_traversal())\n\n    print(\"Search for 10:\", bst.search(10))\n    print(\"Search for 15:\", bst.search(15))\n```\n\nThis implementation provides a basic binary search tree with methods for inserting nodes, traversing the tree, and searching for a specific value. The example usage demonstrates how to create a binary search tree, insert nodes, and perform traversals and searches.","role":"assistant"}}],"created":1739048084,"id":"f113c005-eb6f-4538-b93d-9ca7f78c7f6f","model":"Meta-Llama-3.1-405B-Instruct","object":"chat.completion","system_fingerprint":"fastcoe","usage":{"acceptance_rate":11.054054260253906,"completion_tokens":1228,"completion_tokens_after_first_per_sec":241.58457662468612,"completion_tokens_after_first_per_sec_first_ten":241.8372175509608,"completion_tokens_per_sec":234.29322621196064,"end_time":1739048084.484114,"is_last_response":true,"prompt_tokens":58,"start_time":1739048079.2416477,"stop_reason":"stop","time_to_first_token":0.1634995937347412,"total_latency":5.241295362457691,"total_tokens":1286,"total_tokens_per_sec":245.35919292229755}}

specifically you can see it here

... and searching for a specific value.\n\npython\nclass Node:\n """\n Represents …


-Coby