Path: blob/main/extensions/copilot/src/platform/inlineEdits/common/utils/stringifyChatMessages.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Raw } from '@vscode/prompt-tsx';67export function stringifyChatMessages(messages: Raw.ChatMessage[]) {8return messages.map(stringifyMessage).join('\n');9}1011function stringifyMessage({ role, content }: Raw.ChatMessage) {12if (role !== Raw.ChatRole.User && role !== Raw.ChatRole.System) {13return 'omitted because of non-user and non-system role'; // should be impossible14}1516const roleStr = role === Raw.ChatRole.User ? 'User' : 'System';1718const textContentPart = content.at(0);19if (textContentPart?.type !== Raw.ChatCompletionContentPartKind.Text) {20return 'omitted because of non-text content'; // should be impossible21}2223return (24`${roleStr}25------26${textContentPart.text}27==================`);28}293031