forked from TabbyML/tabby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(context): add support for Pull Request in GitHub Context (TabbyM…
…L#3429) * WIP: add pr answer mock * WIP: rename diff to patch * WIP: index pulls and answer from them * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * chore: use diff instread of patch * chore: drop PR placeholder in answer engine * [autofix.ci] apply automated fixes * chore: use consistent pull and pullDoc * chore(graphQL): update schema for pr context * chore: minor update for comments * chore: skip diff larger than 10MB --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
565304f
commit 97210ec
Showing
15 changed files
with
312 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::sync::Arc; | ||
|
||
use async_stream::stream; | ||
use async_trait::async_trait; | ||
use futures::stream::BoxStream; | ||
use serde_json::json; | ||
use tabby_common::index::structured_doc::fields; | ||
use tabby_inference::Embedding; | ||
use tokio::task::JoinHandle; | ||
|
||
use super::{build_tokens, BuildStructuredDoc}; | ||
|
||
pub struct PullDocument { | ||
pub link: String, | ||
pub title: String, | ||
pub body: String, | ||
|
||
/// The diff represents the code changes in this PR, | ||
/// including metadata, affected line ranges, and added (+) or removed (-) lines. | ||
/// For more details on the diff format, refer to: | ||
/// https://git-scm.com/docs/diff-format#_combined_diff_format | ||
pub diff: String, | ||
pub merged: bool, | ||
} | ||
|
||
#[async_trait] | ||
impl BuildStructuredDoc for PullDocument { | ||
fn should_skip(&self) -> bool { | ||
false | ||
} | ||
|
||
async fn build_attributes(&self) -> serde_json::Value { | ||
json!({ | ||
fields::pull::LINK: self.link, | ||
fields::pull::TITLE: self.title, | ||
fields::pull::BODY: self.body, | ||
fields::pull::DIFF: self.diff, | ||
fields::pull::MERGED: self.merged, | ||
}) | ||
} | ||
|
||
async fn build_chunk_attributes( | ||
&self, | ||
embedding: Arc<dyn Embedding>, | ||
) -> BoxStream<JoinHandle<(Vec<String>, serde_json::Value)>> { | ||
// currently not indexing the diff | ||
let text = format!("{}\n\n{}", self.title, self.body); | ||
let s = stream! { | ||
yield tokio::spawn(async move { | ||
let tokens = build_tokens(embedding, &text).await; | ||
let chunk_attributes = json!({}); | ||
(tokens, chunk_attributes) | ||
}) | ||
}; | ||
|
||
Box::pin(s) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.