From 482b485f7a5d0ebc55bf46f534f16ca77a9ec1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sun, 18 May 2025 11:15:51 +0200 Subject: [PATCH] Expose a way to customize the path to the chat completions endpoint --- async-openai/src/chat.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/async-openai/src/chat.rs b/async-openai/src/chat.rs index 28c89f9d..07452e5d 100644 --- a/async-openai/src/chat.rs +++ b/async-openai/src/chat.rs @@ -12,11 +12,21 @@ use crate::{ /// Related guide: [Chat completions](https://platform.openai.com//docs/guides/text-generation) pub struct Chat<'c, C: Config> { client: &'c Client, + path: String, } impl<'c, C: Config> Chat<'c, C> { pub fn new(client: &'c Client) -> Self { - Self { client } + Self { + client, + path: "/chat/completions".to_string(), + } + } + + /// Change the path to the chat completions route. + pub fn with_path(mut self, path: impl Into) -> Self { + self.path = path.into(); + self } /// Creates a model response for the given chat conversation. Learn more in @@ -52,7 +62,7 @@ impl<'c, C: Config> Chat<'c, C> { )); } } - self.client.post("/chat/completions", request).await + self.client.post(&self.path, request).await } /// Creates a completion for the chat message @@ -83,6 +93,6 @@ impl<'c, C: Config> Chat<'c, C> { request.stream = Some(true); } - Ok(self.client.post_stream("/chat/completions", request).await) + Ok(self.client.post_stream(&self.path, request).await) } }