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.
refactor(webserver): switch to openai chat interface (TabbyML#2564)
* refactor(webserver): switch to openai chat interface * fix query get content * update utoipa path * fix test * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4ce404e
commit 64cc7f4
Showing
22 changed files
with
199 additions
and
602 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,13 @@ | ||
mod openai_chat; | ||
|
||
use std::sync::Arc; | ||
|
||
use openai_chat::OpenAIChatEngine; | ||
use async_openai::config::OpenAIConfig; | ||
use tabby_common::config::HttpModelConfig; | ||
use tabby_inference::ChatCompletionStream; | ||
|
||
pub async fn create(model: &HttpModelConfig) -> Arc<dyn ChatCompletionStream> { | ||
match model.kind.as_str() { | ||
"openai/chat" => Arc::new(OpenAIChatEngine::create( | ||
&model.api_endpoint, | ||
model.model_name.as_deref().unwrap_or_default(), | ||
model.api_key.clone(), | ||
)), | ||
"ollama/chat" => ollama_api_bindings::create_chat(model).await, | ||
let config = OpenAIConfig::default() | ||
.with_api_base(model.api_endpoint.clone()) | ||
.with_api_key(model.api_key.clone().unwrap_or_default()); | ||
|
||
unsupported_kind => panic!("Unsupported kind for http chat: {}", unsupported_kind), | ||
} | ||
Arc::new(async_openai::Client::with_config(config)) | ||
} |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,29 +1,11 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use derive_builder::Builder; | ||
use futures::stream::BoxStream; | ||
use tabby_common::api::chat::Message; | ||
use async_openai::config::OpenAIConfig; | ||
|
||
#[derive(Builder, Debug)] | ||
pub struct ChatCompletionOptions { | ||
#[builder(default = "0.1")] | ||
pub sampling_temperature: f32, | ||
|
||
#[builder(default = "crate::default_seed()")] | ||
pub seed: u64, | ||
|
||
#[builder(default = "1920")] | ||
pub max_decoding_tokens: i32, | ||
|
||
#[builder(default = "0.0")] | ||
pub presence_penalty: f32, | ||
pub trait ChatCompletionStream: Sync + Send { | ||
fn get(&self) -> async_openai::Chat<'_, OpenAIConfig>; | ||
} | ||
|
||
#[async_trait] | ||
pub trait ChatCompletionStream: Sync + Send { | ||
async fn chat_completion( | ||
&self, | ||
messages: &[Message], | ||
options: ChatCompletionOptions, | ||
) -> Result<BoxStream<String>>; | ||
impl ChatCompletionStream for async_openai::Client<OpenAIConfig> { | ||
fn get(&self) -> async_openai::Chat<'_, OpenAIConfig> { | ||
self.chat() | ||
} | ||
} |
Oops, something went wrong.