Changing the system prompt for an assistant using ...
# support
n
Is there a way to change the prompt for an assistant using the api? I'm doing this:
Copy code
JSON.parse update_assistant(
                 assistant_id: assistant_id,
                 assistant_hash: assistant)
with:
Copy code
assistant = {
                "name" => "Mary",
               "voice" => {
         "voiceId" => "melissa",
        "provider" => "playht"
    },
               "model" => {
              "model" => "gpt-4",
           "messages" => [
            [0] {
                   "role" => "system",
                "content" => "say hi to the user"
            }
        ],
           "provider" => "openai",
          "maxTokens" => 250,
        "temperature" => 1
    },
    "recordingEnabled" => true,
        "firstMessage" => "Hello, this is Breezy from 'Mandia & Sons Construction'. How are you doing? ",
    "voicemailMessage" => "You've reached Mary's Dental voicemail. Please leave a message after the beep, and we'll get back to you as soon as possible.",
      "endCallMessage" => "Thank you for contacting Mary's Dental. Have a great day!",
         "transcriber" => {
           "model" => "nova-2",
        "language" => "en",
        "provider" => "deepgram"
    },
      "clientMessages" => [
        [0] "transcript",
        [1] "hang",
        [2] "function-call",
        [3] "speech-update",
        [4] "metadata",
        [5] "conversation-update"
    ],
      "serverMessages" => [
        [0] "end-of-call-report",
        [1] "status-update",
        [2] "hang",
        [3] "function-call"
    ],
      "endCallPhrases" => [
        [0] "goodbye",
        [1] "talk to you soon"
    ]
}
And getting this error:
{"message"=>["model.temperature must not be greater than 2", "recordingEnabled must be a boolean value"], "error"=>"Bad Request", "statusCode"=>400}
Am I overthinking this? My goal is to change the prompt before an incoming call is coming in.
v
message has been deleted
@noj It looks like you're on the right track, but there are a couple of issues in your JSON payload that need to be addressed: 1. The
temperature
value in the
model
object must not exceed 2. You have it set to 1, which is within the valid range, so that part of the error message seems to be a mistake unless there's a different part of your code where the temperature is set incorrectly. 2. The
recordingEnabled
field must be a boolean value. In your JSON, it is set to
true
, which is a valid boolean value. If you're still getting an error for this field, ensure that the value is not being altered elsewhere in your code. To change the prompt dynamically before an incoming call, you can use templates with double curly braces
{{variableName}}
in the
firstMessage
field. For example:
Copy code
json
"firstMessage": "Hello, this is {{assistantName}} from '{{companyName}}'. How are you doing?"
Then, when starting a call, you can provide the values for
{{assistantName}}
and
{{companyName}}
to customize the prompt for that specific call. If you're still encountering issues after making these adjustments, please ensure that the rest of your JSON structure conforms to the API's schema and that all values are correctly typed. If the problem persists, please ask support for more info on this.
You can continue this conversation by mentioning me in the message.
n
A lot of what you said doesn't make sense. e.g, the temprature i set was not higher than 2, the recordingEnabled is a boolean ('true' is a boolean). How do i set values for the double curly braces for an incoming call?
Anyways, this (blow) has been working for me in the sense that it seems to affect the vapi db and not return an error code.
Copy code
def diff_update_assistant(assistant_id:, new_prompt:)
    assistant = get_assistant(assistant_id: assistant_id)
    assistant['model']['messages'][0]['content'] = new_prompt
    assistant['model'] = assistant['model'].except('temperature', 'maxTokens')

    assistant = assistant.except(
      'id',
      'orgId',
      'createdAt',
      'updatedAt',
      'isServerUrlSecretSet',
      'recordingEnabled',
    )

    ap assistant
    JSON.parse update_assistant(
                 assistant_id: assistant_id,
                 assistant_hash: assistant)
  end

  def update_assistant(assistant_id:, assistant_hash:)
    HTTParty.patch(
      "https://api.vapi.ai/assistant/#{assistant_id}",
      headers:,
      body: assistant_hash
    ).body
  end
Unfortuantly, I don't think it had any effect on the dashboard.
c
Yes you can have the sytem prompt updated from the API.
n
@Chowderr how do i do that?
h
@noj i might be dumb but like u dont have to set anything for incoming? just set ur phone number to assistant id and do everything in the dashboard
unless u have a usecase im not thinking abt
so for outbound u can have a transient and then for inbound just make it in vapi dashboard and have that handle incoming
s
You will need to use the transient assistant and then you need to change all the data. Also, read the error message you are providing the wrong values.
n
@howwy I want to dynamically change the prompt depending on who is calling the number and when they are calling. @Sahil Look at the parameters that i'm passing, they are clearly inconsistent with the error message (the parameters comply with the error message)
Read this documentation once
n
@Sahil the dynamic variable stuff only works for outbound calls. My questions is about inbound calls.
@Chowderr Do you have any documentation of changing the system prompt from the api? I don't understand how to do it reliably.
s
It works for inbound as well
c
When you update the assistant you can specify the assistant prompt and update it. I do it from my GPT.
j
What is an example API call showing the key to patch the system prompt?
/assistant/{id} PATCH model/messages/role: system, content: prompt text?
s
can you create a new support ticket? @jims
j
Yes but why? Isn't my suggestion the correct answer to my question and this original ticket both?
12 Views