summaryrefslogtreecommitdiffstats
path: root/src/client/openai.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-04-24 16:12:38 +0800
committerGitHub <noreply@github.com>2024-04-24 16:12:38 +0800
commita17f349daa0609402c51205929b9f2b32f6fb1bb (patch)
tree380dd9c158f8d9278355634a8d474df3a90f8d25 /src/client/openai.rs
parent040c48b9b392e3329d3f1de8eeb1b8773129773c (diff)
downloadaichat-a17f349daa0609402c51205929b9f2b32f6fb1bb.tar.gz
feat: support customizing `top_p` parameter (#434)
Diffstat (limited to 'src/client/openai.rs')
-rw-r--r--src/client/openai.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/client/openai.rs b/src/client/openai.rs
index f35c6ab..2c5d99b 100644
--- a/src/client/openai.rs
+++ b/src/client/openai.rs
@@ -130,6 +130,7 @@ pub fn openai_build_body(data: SendData, model: &Model) -> Value {
let SendData {
messages,
temperature,
+ top_p,
stream,
} = data;
@@ -139,13 +140,16 @@ pub fn openai_build_body(data: SendData, model: &Model) -> Value {
});
if let Some(max_tokens) = model.max_output_tokens {
- body["max_tokens"] = json!(max_tokens);
+ body["max_tokens"] = max_tokens.into();
} else if model.name == "gpt-4-vision-preview" {
// The default max_tokens of gpt-4-vision-preview is only 16, we need to make it larger
- body["max_tokens"] = json!(4096);
+ body["max_tokens"] = 4096.into();
}
- if let Some(v) = temperature {
- body["temperature"] = v.into();
+ if let Some(temperature) = temperature {
+ body["temperature"] = temperature.into();
+ }
+ if let Some(top_p) = top_p {
+ body["top_p"] = top_p.into();
}
if stream {
body["stream"] = true.into();