From d572cf7d6d498a80f2eb7b5986b6cd2b1301e983 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Wed, 14 Jun 2023 10:49:31 -0700 Subject: [PATCH] api: add user field in completion api --- crates/tabby-common/src/events.rs | 1 + crates/tabby/src/serve/completions.rs | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/tabby-common/src/events.rs b/crates/tabby-common/src/events.rs index b4bb1c1..e239ca6 100644 --- a/crates/tabby-common/src/events.rs +++ b/crates/tabby-common/src/events.rs @@ -49,6 +49,7 @@ pub enum Event<'a> { language: &'a str, prompt: &'a str, choices: Vec>, + user: Option<&'a str>, }, } diff --git a/crates/tabby/src/serve/completions.rs b/crates/tabby/src/serve/completions.rs index fff57d3..fca76e1 100644 --- a/crates/tabby/src/serve/completions.rs +++ b/crates/tabby/src/serve/completions.rs @@ -17,9 +17,15 @@ use crate::fatal; mod languages; #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] +#[schema(example=json!({ + "language": "python", + "segments": { + "prefix": "def fib(n)\n ", + "suffix": "\n return fib(n - 1) + fib(n - 2)" + } +}))] pub struct CompletionRequest { #[schema(example = "def fib(n):")] - #[deprecated] prompt: Option, /// Language identifier, full list is maintained at @@ -29,16 +35,18 @@ pub struct CompletionRequest { /// When segments are set, the `prompt` is ignored during the inference. segments: Option, + + // A unique identifier representing your end-user, which can help Tabby to monitor & generating + // reports. + user: Option, } #[derive(Serialize, Deserialize, ToSchema, Clone, Debug)] pub struct Segments { /// Content that appears before the cursor in the editor window. - #[schema(example = "def fib(n):\n ")] prefix: String, /// Content that appears after the cursor in the editor window. - #[schema(example = "\n return fib(n - 1) + fib(n - 2)")] suffix: Option, } @@ -107,6 +115,7 @@ pub async fn completion( index: 0, text: &text, }], + user: request.user.as_deref(), } .log();