summaryrefslogtreecommitdiffstats
path: root/src/client/openai.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-11-27 14:04:50 +0800
committerGitHub <noreply@github.com>2023-11-27 14:04:50 +0800
commit35c75506e2fd94e2285d8a3cb66208d518d5f992 (patch)
tree97fb643bb5e231022442c1cc617f2daeaa152a66 /src/client/openai.rs
parent5bfe95d31110e75e84626598f033805b0ae4326c (diff)
downloadaichat-35c75506e2fd94e2285d8a3cb66208d518d5f992.tar.gz
feat: support vision (#249)
* feat: support vision * clippy * implement vision * resolve data url to local file * add model openai:gpt-4-vision-preview * use newline to concate embeded text files * set max_tokens for gpt-4-vision-preview
Diffstat (limited to 'src/client/openai.rs')
-rw-r--r--src/client/openai.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs
index dbe2661..928c6b3 100644
--- a/src/client/openai.rs
+++ b/src/client/openai.rs
@@ -19,13 +19,14 @@ use std::env;
const API_BASE: &str = "https://api.openai.com/v1";
-const MODELS: [(&str, usize); 6] = [
+const MODELS: [(&str, usize); 7] = [
("gpt-3.5-turbo", 4096),
("gpt-3.5-turbo-16k", 16385),
("gpt-3.5-turbo-1106", 16385),
+ ("gpt-4-1106-preview", 128000),
+ ("gpt-4-vision-preview", 128000),
("gpt-4", 8192),
("gpt-4-32k", 32768),
- ("gpt-4-1106-preview", 128000),
];
pub const OPENAI_TOKENS_COUNT_FACTORS: TokensCountFactors = (5, 2);
@@ -145,6 +146,12 @@ pub fn openai_build_body(data: SendData, model: String) -> Value {
"model": model,
"messages": messages,
});
+
+ // The default max_tokens of gpt-4-vision-preview is only 16, we need to make it larger
+ if model == "gpt-4-vision-preview" {
+ body["max_tokens"] = json!(4096);
+ }
+
if let Some(v) = temperature {
body["temperature"] = v.into();
}