C
C#17mo ago
Schenk

❔ Property can only bet set a new list and now variable??

So this works just fine:
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, new ChatCompletionsOptions
{
Messages = { new ChatMessage(role, prompt) } // DOES NOT WORK WITH messages
});
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, new ChatCompletionsOptions
{
Messages = { new ChatMessage(role, prompt) } // DOES NOT WORK WITH messages
});
But this does not:
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, new ChatCompletionsOptions
{
Messages = messages // DOES NOT WORK WITH messages
});
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, new ChatCompletionsOptions
{
Messages = messages // DOES NOT WORK WITH messages
});
error: "Property or indexer 'property' cannot be assigned to -- it is read only" How do I fix this?
3 Replies
Angius
Angius17mo ago
Could try
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var options = new ChatCompletionsOptions();
options.Messages.AddAll(messages);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, options);
List<ChatMessage> messages = new List<ChatMessage>();
messages.Add(newMessage);

var options = new ChatCompletionsOptions();
options.Messages.AddAll(messages);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, options);
Or even better, just skip the intermediate step
var options = new ChatCompletionsOptions();
options.Messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, options);
var options = new ChatCompletionsOptions();
options.Messages.Add(newMessage);

var openAiResponse = await openAiClient.GetChatCompletionsAsync(openAIModel, options);
Schenk
SchenkOP17mo ago
Yes, The issue is that the Messages get cleared every time, but the first should work thanks a lot
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server