#How to pass role to a new message
1 messages · Page 1 of 1 (latest)
Hi @gilded cove. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the error message you're seeing, it seems like the ChatCompletionMessage type is expecting the role to be "assistant", but you're trying to assign it as "system". This is likely due to the type definition of ChatCompletionMessage in your current context.
In the extracts provided, there are different types of ChatCompletionMessageParam depending on the role of the message. For example, in the Node.js library, there are ChatCompletionSystemMessageParam, ChatCompletionUserMessageParam, and ChatCompletionFunctionMessageParam types, each corresponding to a different role (source (https://github.com/openai/openai-node/issues/639)).
If you're using TypeScript with the OpenAI Node.js library, you should use the appropriate type for the role of the message. For a system message, you would use ChatCompletionSystemMessageParam. Here's an example:
import { ChatCompletionSystemMessageParam } from "openai";
const systemMessage: ChatCompletionSystemMessageParam = {
role: "system",
content: "abc"
};
Please note that the exact import statement might vary depending on the version and structure of the library you're using. If you're not using the Node.js library or if the issue persists, please refer to the documentation of the library you're using for the correct usage and type definitions.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@gilded cove kapa.ai is still learning and improving, please let us know how it did by reacting below
@turbid meadow
export const systemMessageForTeachingResponses: ChatCompletionSystemMessageParam = (currentTopic:string,rKsFromLesson:IrK[]) =>({
role: 'system',
content: `abc`
})
I'm getting the error Type '(currentTopic: string, rKsFromLesson: IrK[]) => { role: string; content: string; }' is not assignable to type 'ChatCompletionSystemMessageParam'.ts(2322)
const systemMessageForTeachingResponses: ChatCompletionSystemMessageParam
Let me check the knowledge base for you. One moment! :books:
The error message you're seeing is because you're trying to assign a function to a variable that is expected to be of type ChatCompletionSystemMessageParam. The ChatCompletionSystemMessageParam type is an object type, not a function type.
If you want to create a function that returns a ChatCompletionSystemMessageParam, you should define the function without specifying the ChatCompletionSystemMessageParam type for the function itself. Here's how you can do it:
export const systemMessageForTeachingResponses = (currentTopic: string, rKsFromLesson: IrK[]): ChatCompletionSystemMessageParam => ({
role: 'system',
content: `abc`
});
In this code, systemMessageForTeachingResponses is a function that takes two parameters (currentTopic and rKsFromLesson) and returns an object of type ChatCompletionSystemMessageParam.