- Experiment with different prompt configurations while maintaining version control
- Test your chatbot’s responses in real-time with an interactive playground
- Portkey’s robust versioning system ensures that you can experiment freely with your prompts, allowing for easy rollback.
- Experiment with different models and configurations to find the best fit for your use case
Setting Up Your Chatbot
Go to Portkey’s Prompts dashboard. Click on the Create button. You are now on Prompt Playground.Step 1: Define Your System Prompt
Start by defining your system prompt. This sets the initial context and behavior for your chatbot. You can set this up in your Portkey’s Prompt Library using the JSON View
Step 2: Create a Variable for Conversation History
In the Portkey UI, create a variable for the conversation. Look for two icons next to the variable name: “T” and ”{..}”. Click the ”{…}” icon to switch to JSON mode if you need to set a default. Variable name must match your code: Usechat_history as the variable name so it matches the placeholder {{chat_history}} in your prompt (Step 1). In your application code, you will pass chat_history as a plain-text string (e.g. "Assistant: Hello...\n\nUser: Hi\n\n"), not as a raw JSON array. Formatting the history as text avoids JSON embedding issues and keeps the API request valid.
As your chatbot interacts with users, append each turn to the conversation in memory, then format the full history as a single string and pass it in
variables.chat_history on each request. The model will see the full thread and respond in context.
Step 3: Implementing the Chatbot
Use Portkey’s API to generate responses based on your prompt template. Pass the variablechat_history (not variable) so it matches the placeholder in your prompt. Format the conversation as a plain-text string before sending to avoid JSON parsing errors when the value is embedded in the request.
- Python SDK
- NodeJS SDK
Step 4: Append the Response
After generating a response, append it to your conversation history:- Python SDK
- NodeJS SDK
Step 5: Take User Input to Continue the Conversation
Implement a loop to continuously take user input and generate responses:- Python SDK
- NodeJS SDK
Complete Example
Here’s a complete example that puts all these steps together. Use the variablechat_history, format the conversation as plain text, and pass it in variables.chat_history so the model sees the full thread and responds in context. For the Node.js SDK use promptID (capital “ID”); see the Prompt API reference.
- Python SDK
- NodeJS SDK
- Python: Use
prompt_idandvariables={"chat_history": chat_history_str}. - Node.js: Use
promptID(capital “ID”) andvariables: { chat_history: chatHistoryStr }. Pass a string forchat_historyin both.
Conclusion
Voilà! You’ve successfully set up your chatbot using Portkey’s prompt templates. Portkey enables you to experiment with various LLM providers. It acts as a definitive source of truth for your team, and it versions each snapshot of model parameters, allowing for easy rollback. Here’s a snapshot of the Prompt Management UI. To learn more about Prompt Management click here.

