import requestsurl = "https://api.keywordsai.co/api/prompts/<prompt_id>/versions/"api_key = "YOUR_KEYWORDS_AI_API_KEY" # Replace with your actual Keywords AI API keydata = {"description": "A description of the prompt version", "messages": [ {"role": "system", "content": "You are a helpful {{role}}."}, {"role": "user", "content": "Hello, how are you?"} ], "model": "gpt-3.5-turbo", "stream": false, "temperature": 0.7, "max_tokens": 256, "top_p": 1.0, "frequency_penalty": 0.0, "presence_penalty": 0.0, "variables": {}, "fallback_models": ["gpt-3.5-turbo-16k", "gpt-4"], "load_balance_models": [ {"model": "gpt-3.5-turbo", "weight": 0.7}, {"model": "gpt-4", "weight": 0.3} ],}headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}response = requests.post(url, headers=headers, json=data)print(response.json())
You can update a prompt version by sending a PATCH request to the prompt version endpoint. The request should include the name of the prompt version, and the list of fallback models, load balance models, tools, and whether to deploy this version as the live version.
The list of messages for the prompt version. If you want to add a variable, you can use the following format: {{variable_name}}.
Example
Copy
{"messages": [ {"role": "system", "content": "You are a helpful {{role}}."}, // role could be assistant, teacher, etc. {"role": "user", "content": "Hello, how are you?"} ],}
Specify how much to penalize new tokens based on their existing frequency in the text so far. Decreases the model’s likelihood of repeating the same line verbatim
The list of tools to use for the prompt version. Check out tools for more information.
Example
Copy
{"tools": [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather in a given location", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" } }, "required": ["location"] } } } ],}