Prompts

Prompts

QvikChat uses Dotprompt (opens in a new tab) to define system and chat prompts. These prompts ensure safety, accuracy, and reliability. They are designed to mitigate LLM hallucination and deter prompt injection attacks.

  • System prompts are used for setting up the behavior of the chat agent
  • Chat prompts are used for continued user queries which are part of an ongoing conversation. These chat prompts may include chat history, additional context information, etc.

System Prompts

You can provide a system prompt when setting up a chat endpoint. If no system prompt is provided, QvikChat uses a default system prompt based on the provided agent type.

Be careful when defining system prompts. They should be clear, concise, and unambiguous. They should also be designed to mitigate LLM hallucination and implement safety guardrails to safegaurd the user and block usage of the service for unintended purposes. If in doubt, avoid defining a custom system prompt and use the default system prompt provided by QvikChat.

import { defineDotprompt } from "@genkit-ai/dotprompt";
import { defineChatEndpoint } from "@oconva/qvikchat/endpoints";
 
// Define a custom system prompt
const customSystemPrompt = defineDotprompt(
  {
    name: "customSystemPrompt",
    model: "googleai/gemini-1.5-flash-latest",
    input: {
      schema: z.object({
        query: z.string().optional(),
      }),
    },
    output: {
      format: "text",
    },
  },
  `{{role "system"}}
		Answer user query with humor. If no query is provided, greet the user with a funny message.
		
		{{#if query}}
		{{role "user"}}
		User query
		{{query}}
		{{/if}}`
);
 
// Define a chat endpoint with a custom system prompt
defineChatEndpoint({
  endpoint: "chat",
  chatAgentConfig: {
    systemPrompt: customSystemPrompt,
  },
});

Chat Prompts

Chat prompts are used for continued user queries which are part of an ongoing conversation. These chat prompts may include chat history, additional context information, etc.

When defining chat prompts, you can use the defineDotprompt function to create a chat prompt. The chat prompt can be used to provide additional context information to the user, ask follow-up questions, or provide chat history.

import { defineDotprompt } from "@genkit-ai/dotprompt";
import { defineChatEndpoint } from "@oconva/qvikchat/endpoints";
 
// Define a custom chat prompt
const customChatPrompt = defineDotprompt(
  {
    name: "customChatPrompt",
    model: "googleai/gemini-1.5-flash-latest",
    input: {
      schema: z.object({
        query: z.string().optional(),
      }),
    },
    output: {
      format: "text",
    },
  },
  `{{role "system"}}
Start the message with "Sure, here is..." and provide the user with the requested information.
 
    {{#if query}}
    {{role "user"}}
    User query
    {{query}}
    {{/if}}`
);
 
// Chat endpoint with a custom chat prompt
defineChatEndpoint({
  endpoint: "chat",
  chatAgentConfig: {
    chatPrompt: customChatPrompt,
  },
});

When defining chat prompts, be sure to provide clear, concise, and unambiguous prompts. These prompts should be designed to guide the model through the conversation and provide additional context information when needed. If in doubt, avoid defining a custom chat prompt and use the default chat prompt provided by QvikChat.