How can I add a prompt to instruct the model not to deviate and answer unrelated questions for my use case?
API Docs give example only for default use
https://platform.openai.com/docs/api-reference/chat/create
however I use Image Input and per testing it seems to follow instruction, but if I ask it not to answer about specific topic in question or image, it fails to follow instruction. It looks like it does not have access to the question or image,
this is my function:
// New utility function to handle user question with multiple images
async function answerUserQuestionWithImages(imageUrls: string[], userQuestion: string, roomId: string) {
const io = getIO();
try {
const content: ChatCompletionContentPart[] = [
{ type: "text", text: userQuestion },
...imageUrls.map(url => ({
type: "image_url",
image_url: { url: url, detail: "auto" }
} as ChatCompletionContentPart))
];
const messages: ChatCompletionMessageParam[] = [
{
role: "system",
content: "You are a multilingual helpful and friendly assistant. Don't answer question that are not related to football!"
},
{
role: "user",
content: content,
}
];
const response = await openAIClient.chat.completions.create({
model: "gpt-4o",
messages: messages,
max_tokens: 300,
stream: true, // Enable streaming
});
let answer = '';
for await (const token of response) {
if (token.choices[0]?.delta?.content) {
answer += token.choices[0].delta.content;
io.to(roomId).emit("newToken", token.choices[0].delta.content);
}
}
when I give it an image of a panda and ask something like explain what this panda do in the image, it will answer. However, if the prompt is “Answer each question with OK” it will answer each question with OK.