MagnivOrg / prompt-layer-library

🍰 PromptLayer - Maintain a log of your prompts and OpenAI API requests. Track, debug, and replay old completions.
https://www.promptlayer.com
Apache License 2.0
475 stars 42 forks source link

API Template Post Error: Unable to extract tag #123

Closed jalkestrup closed 3 months ago

jalkestrup commented 3 months ago

Hi,

Thanks for creating a great prompt management platform. There seem to be an issue running publish to the template API endpoint. If i try to run the below bare minimum post request, I get the following error:

{"message":[{"loc":["prompt_version","prompt_template"],"msg":"Unable to extract tag using discriminator 'type'","type":"union_tag_not_found"}],"success":false}

However, I guess the tag is not required? And even if I try to provide the tag as a list of strings, the error message prevails.

Code to replicate, insert your PL API key and name of existing prompt:

import requests

url = "https://api.promptlayer.com/rest/prompt-templates"

payload = {
    "prompt_template": {"prompt_name": "replace_with_your_existing_prompt_name"},
    "prompt_version": {
        "commit_message": "Test from API docs",
        "metadata": {"model": {
                "name": "gpt-3.5-turbo-0125",
                "provider": "openai"
            }},
        "prompt_template": {"content": [{"text": "New content, removed old!"}]}
    }
}
headers = {
    "X-API-KEY": "replace_with_your_api",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

I am running latest promptlayer==0.5.0

nahuel-borda commented 3 months ago

Hi Jesper, thanks for those kind words about Promptlayer. You might have caught one of our pydantic raw validation exceptions. We will get that sorted out soon.

Anyway the payload you should be using looks like this:

import requests

url = "https://api.promptlayer.com/rest/prompt-templates"

payload = {
    "prompt_template": {
        "prompt_name": "replace_with_your_existing_prompt_name",
        "type": "completion"
    },
    "prompt_version": {
        "commit_message": "Test from API docs",
        "metadata": {
            "model": {
                "name": "gpt-3.5-turbo-0125",
                "provider": "openai"
            }
        },
        "prompt_template": {
            "type": "completion",
            "content": [
                {
                    "text": "New content, removed old!",
                    "type": "text"
                }
            ]
        }
    }
}
headers = {
    "X-API-KEY": "fill-this-up",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)

print(response.text)

If you're using Promptlayer you probably want to be in our Discord server for faster replys. Hope to see you there!

nahuel-borda commented 3 months ago

https://discord.gg/GFYm4UFWFS