summaryrefslogtreecommitdiffstats
path: root/src/client/cohere.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-25 10:15:54 +0800
committerGitHub <noreply@github.com>2024-04-25 10:15:54 +0800
commit4db9b309803796bc5f996d0b3713344eb44207ec (patch)
treea0ba8f3a2da32e5392e22272c641e3939de49be6 /src/client/cohere.rs
parent8dacea4deb0fe67c0cdbe15bd47e6e50c1dd12a1 (diff)
downloadaichat-4db9b309803796bc5f996d0b3713344eb44207ec.tar.gz
refactor: rewrite list models of all clients (#436)
Diffstat (limited to 'src/client/cohere.rs')
-rw-r--r--src/client/cohere.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/client/cohere.rs b/src/client/cohere.rs
index cfab0fa..828b799 100644
--- a/src/client/cohere.rs
+++ b/src/client/cohere.rs
@@ -13,12 +13,6 @@ use serde_json::{json, Value};
const API_URL: &str = "https://api.cohere.ai/v1/chat";
-const MODELS: [(&str, usize, &str); 2] = [
- // https://docs.cohere.com/docs/command-r
- ("command-r", 128000, "text"),
- ("command-r-plus", 128000, "text"),
-];
-
#[derive(Debug, Clone, Deserialize, Default)]
pub struct CohereConfig {
pub name: Option<String>,
@@ -49,7 +43,14 @@ impl Client for CohereClient {
}
impl CohereClient {
- list_models_fn!(CohereConfig, &MODELS);
+ list_models_fn!(
+ CohereConfig,
+ [
+ // https://docs.cohere.com/docs/command-r
+ ("command-r", "text", 128000),
+ ("command-r-plus", "text", 128000),
+ ]
+ );
config_get_fn!(api_key, get_api_key);
pub const PROMPTS: [PromptType<'static>; 1] =
@@ -159,23 +160,22 @@ fn build_body(data: SendData, model: &Model) -> Result<Value> {
"message": message,
});
- if let Some(preamble) = system_message {
- body["preamble"] = preamble.into();
- }
-
- if let Some(max_tokens) = model.max_output_tokens {
- body["max_tokens"] = max_tokens.into();
+ if let Some(v) = system_message {
+ body["preamble"] = v.into();
}
if !messages.is_empty() {
body["chat_history"] = messages.into();
}
- if let Some(temperature) = temperature {
- body["temperature"] = temperature.into();
+ if let Some(v) = model.max_output_tokens {
+ body["max_tokens"] = v.into();
+ }
+ if let Some(v) = temperature {
+ body["temperature"] = v.into();
}
- if let Some(top_p) = top_p {
- body["p"] = top_p.into();
+ if let Some(v) = top_p {
+ body["p"] = v.into();
}
if stream {
body["stream"] = true.into();