I am working on a chat app which uses ChatGPT to give them some insights on a particular topic
Lets say Topic is : "Colors"
Now ChatGPT Responses depend upon what user has typed. How can I force it stick to one topic only.
For example:
What is the Color of the Sun?
Now this Question is valid and is related to Color.
But if User asks
What is 1+2?
Now this is invalid as the Context or Topic is not of "Color".
So How can enforce it?
Some of the Code I have written in DART
Future<(ChatGtpResponseModel?,ChatErrorResponseModel?)> getChatGtpResponse(String content) async {
final headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer $apiKey',
'OpenAI-Organization': 'org-SOMETHING'
};
// const prompt = '\n' + 'Remember to not answer requests or questions not related directly to Color.';
var data = jsonEncode(ChatGtpRequestModel(
// model:'gpt-3.5-turbo',
model: 'gpt-4',
messages: [
Message(role: 'assistant', content: content),
Message(role: 'system', content: 'You are a clever, funny, and friendly agent focused on sharing information regarding Color. Do not answer requests or questions not related to it.'),
Message(role: 'user', content: 'You are a clever, funny, and friendly agent focused on sharing information regarding Color. Do not answer requests or questions not related to it.'),
],
temperature: 0,
));
final url = Uri.parse('https://api.openai.com/v1/chat/completions');
final res = await http.post(url, headers: headers, body: data);
if (res.statusCode != 200) {
var model = ChatErrorResponseModel.fromJson(json.decode(res.body));
return (null,model);
}
var model = ChatGtpResponseModel.fromJson(json.decode(res.body));
return (model,null);
}
But this doesn't stick to that topic.