Skip to content

Commit

Permalink
Revert "update text to content"
Browse files Browse the repository at this point in the history
This reverts commit 1aa1358.
  • Loading branch information
julialeex committed Jan 31, 2025
1 parent 3f96bd5 commit d620418
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions lib/shared/src/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class ChatClient {

// We only want to send up the speaker and prompt text, regardless of whatever other fields
// might be on the messages objects (`file`, `displayText`, `contextFiles`, etc.).
const messagesToSend = augmentedMessages.map(({ speaker, content, cache_enabled }) => ({
content,
const messagesToSend = augmentedMessages.map(({ speaker, text, cache_enabled }) => ({
text,
speaker,
cache_enabled,
}))
Expand Down Expand Up @@ -90,26 +90,26 @@ export class ChatClient {
export function sanitizeMessages(messages: Message[]): Message[] {
let sanitizedMessages = messages

// 1. If the last message is from an `assistant` with no or empty `content`, omit it
// 1. If the last message is from an `assistant` with no or empty `text`, omit it
let lastMessage = messages.at(-1)
const truncateLastMessage =
lastMessage && lastMessage.speaker === 'assistant' && !messages.at(-1)!.content?.length
lastMessage && lastMessage.speaker === 'assistant' && !messages.at(-1)!.text?.length
sanitizedMessages = truncateLastMessage ? messages.slice(0, -1) : messages

// 2. If there is any assistant message in the middle of the messages without a `content`, omit
// 2. If there is any assistant message in the middle of the messages without a `text`, omit
// both the empty assistant message as well as the unanswered question from the `user`
sanitizedMessages = sanitizedMessages.filter((message, index) => {
// If the message is the last message, it is not a middle message
if (index >= sanitizedMessages.length - 1) {
return true
}

// If the next message is an assistant message with no or empty `content`, omit the current and
// If the next message is an assistant message with no or empty `text`, omit the current and
// the next one
const nextMessage = sanitizedMessages[index + 1]
if (
(nextMessage.speaker === 'assistant' && !nextMessage.content?.length) ||
(message.speaker === 'assistant' && !message.content?.length)
(nextMessage.speaker === 'assistant' && !nextMessage.text?.length) ||
(message.speaker === 'assistant' && !message.text?.length)
) {
return false
}
Expand All @@ -118,9 +118,9 @@ export function sanitizeMessages(messages: Message[]): Message[] {

// 3. Final assistant content cannot end with trailing whitespace
lastMessage = sanitizedMessages.at(-1)
if (lastMessage?.speaker === 'assistant' && lastMessage.content?.length) {
const lastMessageText = lastMessage.content.trimEnd()
lastMessage.content = lastMessageText
if (lastMessage?.speaker === 'assistant' && lastMessage.text?.length) {
const lastMessageText = lastMessage.text.trimEnd()
lastMessage.text = lastMessageText
}

return sanitizedMessages
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/src/sourcegraph-api/completions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface Message {
// content used to be text, but starting from api-version 7, we require Cody clients to
// stop using text and send content to instead to respect the official API contract and
// mirrors what OpenAI and Anthropic expect
content?: PromptString
text?: PromptString
cache_enabled?: boolean | null
}

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/src/sourcegraph-api/completions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function serializePrompts(

return Promise.all(
messages.map(async m => {
const text = await m.content?.toFilteredString(contextFiltersProvider)
const text = await m.text?.toFilteredString(contextFiltersProvider)
if (serverSupportsPromptCaching() && m.cache_enabled) {
return {
speaker: m.speaker,
Expand Down
10 changes: 5 additions & 5 deletions vscode/src/edit/prompt/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const getContextFromIntent = async ({
return [
{
speaker: 'human',
content: populateCodeGenerationContextTemplate(
text: populateCodeGenerationContextTemplate(
ps`<${PROMPT_TOPICS.PRECEDING}>${truncatedPrecedingText}</${PROMPT_TOPICS.PRECEDING}>`,
ps`<${PROMPT_TOPICS.FOLLOWING}>${truncatedFollowingText}</${PROMPT_TOPICS.FOLLOWING}>`,
uri,
Expand Down Expand Up @@ -95,15 +95,15 @@ const getContextFromIntent = async ({
if (truncatedPrecedingText.trim().length > 0) {
contextMessages.push({
speaker: 'human',
content: populateCodeContextTemplate(truncatedPrecedingText, uri, undefined, 'edit'),
text: populateCodeContextTemplate(truncatedPrecedingText, uri, undefined, 'edit'),
cache_enabled: false,
file: { type: 'file', uri, source: ContextItemSource.Editor, range: prefix.range },
})
}
if (truncatedFollowingText.trim().length > 0) {
contextMessages.push({
speaker: 'human',
content: populateCodeContextTemplate(truncatedFollowingText, uri, undefined, 'edit'),
text: populateCodeContextTemplate(truncatedFollowingText, uri, undefined, 'edit'),
cache_enabled: false,
file: { type: 'file', uri, source: ContextItemSource.Editor, range: suffix.range },
})
Expand All @@ -126,7 +126,7 @@ const getContextFromIntent = async ({
diagnostic =>
({
speaker: 'human' as const,
content: populateCurrentEditorDiagnosticsTemplate(diagnostic, uri),
text: populateCurrentEditorDiagnosticsTemplate(diagnostic, uri),
cache_enabled: false,
file: { type: 'file', uri, source: ContextItemSource.Editor },
}) satisfies ContextMessage
Expand All @@ -137,7 +137,7 @@ const getContextFromIntent = async ({
text =>
({
speaker: 'human' as const,
content: populateCodeContextTemplate(text, uri, undefined, 'edit'),
text: populateCodeContextTemplate(text, uri, undefined, 'edit'),
cache_enabled: false,
file: { type: 'file', uri, source: ContextItemSource.Editor },
}) satisfies ContextMessage
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/prompt-builder/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function renderContextItem(contextItem: ContextItem): ContextMessage | nu
}
}

return { speaker: 'human', content: messageText, file: contextItem, cache_enabled: true }
return { speaker: 'human', text: messageText, file: contextItem, cache_enabled: true }
}

export function getContextItemTokenUsageType(item: ContextItem): ContextTokenUsageType {
Expand Down

0 comments on commit d620418

Please sign in to comment.