summaryrefslogtreecommitdiffstats
path: root/src/client/common.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/common.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/common.rs')
-rw-r--r--src/client/common.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/client/common.rs b/src/client/common.rs
index cf5ba9b..2716d87 100644
--- a/src/client/common.rs
+++ b/src/client/common.rs
@@ -1,7 +1,7 @@
use super::{openai::OpenAIConfig, ClientConfig, Message};
use crate::{
- config::GlobalConfig,
+ config::{GlobalConfig, Input},
render::ReplyHandler,
utils::{
init_tokio_runtime, prompt_input_integer, prompt_input_string, tokenize, AbortSignal,
@@ -50,7 +50,7 @@ macro_rules! register_client {
}
impl $client {
- pub const NAME: &str = $name;
+ pub const NAME: &'static str = $name;
pub fn init(global_config: &$crate::config::GlobalConfig) -> Option<Box<dyn Client>> {
let model = global_config.read().model.clone();
@@ -186,22 +186,22 @@ pub trait Client {
Ok(client)
}
- fn send_message(&self, content: &str) -> Result<String> {
+ fn send_message(&self, input: Input) -> Result<String> {
init_tokio_runtime()?.block_on(async {
let global_config = self.config().0;
if global_config.read().dry_run {
- let content = global_config.read().echo_messages(content);
+ let content = global_config.read().echo_messages(&input);
return Ok(content);
}
let client = self.build_client()?;
- let data = global_config.read().prepare_send_data(content, false)?;
+ let data = global_config.read().prepare_send_data(&input, false)?;
self.send_message_inner(&client, data)
.await
.with_context(|| "Failed to get answer")
})
}
- fn send_message_streaming(&self, content: &str, handler: &mut ReplyHandler) -> Result<()> {
+ fn send_message_streaming(&self, input: &Input, handler: &mut ReplyHandler) -> Result<()> {
async fn watch_abort(abort: AbortSignal) {
loop {
if abort.aborted() {
@@ -211,12 +211,13 @@ pub trait Client {
}
}
let abort = handler.get_abort();
- init_tokio_runtime()?.block_on(async {
+ let input = input.clone();
+ init_tokio_runtime()?.block_on(async move {
tokio::select! {
ret = async {
let global_config = self.config().0;
if global_config.read().dry_run {
- let content = global_config.read().echo_messages(content);
+ let content = global_config.read().echo_messages(&input);
let tokens = tokenize(&content);
for token in tokens {
tokio::time::sleep(Duration::from_millis(10)).await;
@@ -225,7 +226,7 @@ pub trait Client {
return Ok(());
}
let client = self.build_client()?;
- let data = global_config.read().prepare_send_data(content, true)?;
+ let data = global_config.read().prepare_send_data(&input, true)?;
self.send_message_streaming_inner(&client, handler, data).await
} => {
handler.done()?;