Skip to content

Commit

Permalink
fix(answer): add historical client code context in prompt construction
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys committed Jan 11, 2025
1 parent e93e28f commit 3021dd0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions ee/tabby-schema/src/schema/thread/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -70,6 +72,16 @@ pub struct MessageAttachmentClientCode {
pub content: String,
}

impl Into<MessageAttachmentCodeInput> for MessageAttachmentClientCode {
fn into(self) -> MessageAttachmentCodeInput {
MessageAttachmentCodeInput {
filepath: self.filepath,
start_line: self.start_line,
content: self.content,
}
}

Check warning on line 82 in ee/tabby-schema/src/schema/thread/types.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-schema/src/schema/thread/types.rs#L76-L82

Added lines #L76 - L82 were not covered by tests
}

#[derive(GraphQLObject, Clone)]
pub struct MessageAttachmentCode {
pub git_url: String,
Expand Down
23 changes: 21 additions & 2 deletions ee/tabby-webserver/src/service/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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<MessageAttachmentCodeInput> = attachment
.client_code
.iter()
.map(Clone::clone)
.map(Into::into)
.collect();
MessageAttachmentInput {
code: user_attachment_code_input,
}
}

#[cfg(test)]
pub mod testutils;

Expand Down

0 comments on commit 3021dd0

Please sign in to comment.