The function TTMSMCPCloudAI.BuildPostData()
dont create the history correct. The content shoud liste the history of the Chat like:
history = [ { "role": "user", "parts": [{"text": "Hello, who ist there?"}] }, { "role": "model", "parts": [{"text": "Here is the KI first answer..."}] }, { "role": "user", "parts": [{"text": "My second question"}] }, { "role": "model", "parts": [{"text": "here the answer to the second question"}] },
and:
Sequence: The roles must always alternate: user -> model -> user -> model. Two user messages sent consecutively without a response in between often lead to API errors.
Cant find that logic
AMessages := AMessages + string.Format('{"role":"user","content":"%s"}', [AContext]);