Welcome to Portkey Forum

Updated 8 months ago

Apply Fallback mechanism to the prompts

What is the right way to apply Fallback mechanism to the prompts that are created?

Plain Text
const portkey = new Portkey({
  apiKey: PORTKEY_API_KEY,
  config: {
    strategy: {
      mode: 'fallback'
    },
    targets: [
      {
        promptID: 'pp-test-811461'
      },
      {
        promptID: 'pp-l-i-ef463c'
      }
    ]
  }
});

Also, What is the following the correct way to invoke prompt completions?
Plain Text
const response = await portkey.prompts.completions.create({
  variables: {
    city: 'Hyderabad',
    name: 'Nobita'
  }
});

console.log(response.choices);
S
V
C
8 comments
I've tried different ways to create configs form the UI, change promptID to prompt_id. I often come across the following errror:
Plain Text
BadRequestError: Following prompt_id are not valid: undefined
Hey @Saif prompt_id in the Config builder should work. The prompts.completions.create method you've shared is also correct! Is it failing for you?
Let's take to DM 🧐
Sample working code snippet for prompts.completions.create


const result = await portkey.prompts.completions.create({ promptID:"<your_prompt_id>", variables:{ <variable_1>: "<value_1>" }, })
Oh yeah correct! Thanks for pointing this out @chandypaaji !

@Saif even if you pass the prompt templates with Config, you’ll need to pass a dummy prompt id in the completions.create method
I learned something new, but I am not sure if this is expected behaviour. I will just put it down here:

  • The Gateway Configs are respected only when valid PromptID is passed with valid argument. For example, just mentioning dummy_prompt_id or null do throw BadRequestError.
  • The PromptID , when valid is passed, the gateway configs take precedence even if original PromptID is not part of the gateway configs.
cc @chandypaaji who can check this behaviour. Thanks for pointing this out, @Saif!
Add a reply
Sign up and join the conversation on Discord