diff --git a/.changes/unreleased/Fixed and Improvements-20250110-203706.yaml b/.changes/unreleased/Fixed and Improvements-20250110-203706.yaml new file mode 100644 index 000000000000..d2c7e5bc723e --- /dev/null +++ b/.changes/unreleased/Fixed and Improvements-20250110-203706.yaml @@ -0,0 +1,3 @@ +kind: Fixed and Improvements +body: Fixed a bug that prevented the client code context in historical messages from being added to the prompt. +time: 2025-01-10T20:37:06.22245-08:00 diff --git a/ee/tabby-schema/src/schema/thread/types.rs b/ee/tabby-schema/src/schema/thread/types.rs index 04f1bad3ecb7..0ae269b45919 100644 --- a/ee/tabby-schema/src/schema/thread/types.rs +++ b/ee/tabby-schema/src/schema/thread/types.rs @@ -9,6 +9,8 @@ use validator::Validate; use crate::{interface::UserValue, juniper::relay::NodeType, Context}; +use super::{MessageAttachmentCodeInput, MessageAttachmentInput}; + #[derive(GraphQLEnum, Serialize, Clone, PartialEq, Eq)] pub enum Role { User, @@ -70,6 +72,16 @@ pub struct MessageAttachmentClientCode { pub content: String, } +impl Into for MessageAttachmentClientCode { + fn into(self) -> MessageAttachmentCodeInput { + MessageAttachmentCodeInput { + filepath: self.filepath, + start_line: self.start_line, + content: self.content, + } + } +} + #[derive(GraphQLObject, Clone)] pub struct MessageAttachmentCode { pub git_url: String, diff --git a/ee/tabby-webserver/src/service/answer.rs b/ee/tabby-webserver/src/service/answer.rs index 4beec7f6fdf4..c110893411c4 100644 --- a/ee/tabby-webserver/src/service/answer.rs +++ b/ee/tabby-webserver/src/service/answer.rs @@ -42,7 +42,8 @@ use tabby_schema::{ repository::{Repository, RepositoryService}, thread::{ self, CodeQueryInput, CodeSearchParamsOverrideInput, DocQueryInput, MessageAttachment, - MessageAttachmentDoc, MessageDocSearchHit, ThreadAssistantMessageAttachmentsCode, + MessageAttachmentCodeInput, MessageAttachmentDoc, MessageAttachmentInput, + MessageDocSearchHit, ThreadAssistantMessageAttachmentsCode, ThreadAssistantMessageAttachmentsDoc, ThreadAssistantMessageContentDelta, ThreadRelevantQuestions, ThreadRunItem, ThreadRunOptionsInput, }, @@ -441,7 +442,11 @@ fn convert_messages_to_chat_completion_request( let y = &messages[i + 1]; - let content = build_user_prompt(&x.content, &y.attachment, None); + let user_attachment_input = + user_attachment_input_from_user_message_attachment(&x.attachment); + + let content = + build_user_prompt(&x.content, &y.attachment, Some(&user_attachment_input)); ChatCompletionRequestMessage::User(ChatCompletionRequestUserMessage { content: ChatCompletionRequestUserMessageContent::Text( helper.rewrite_tag(&content), @@ -634,6 +639,20 @@ fn get_content(doc: &MessageAttachmentDoc) -> &str { } } +fn user_attachment_input_from_user_message_attachment( + attachment: &MessageAttachment, +) -> MessageAttachmentInput { + let user_attachment_code_input: Vec = attachment + .client_code + .iter() + .map(Clone::clone) + .map(Into::into) + .collect(); + MessageAttachmentInput { + code: user_attachment_code_input, + } +} + #[cfg(test)] pub mod testutils;