From aa516655f4294db2c747370cf3133e86ba58a6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Hauge=20Bj=C3=B8rnskov?= <19725+henrikbjorn@users.noreply.github.com> Date: Fri, 11 Aug 2023 10:01:55 +0200 Subject: [PATCH] Support multiple deployment_ids for azure --- README.md | 14 +++++++++++++- lib/openai/http.rb | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24a2ac65..4867d84d 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,19 @@ To use the [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/cognit end ``` -where `AZURE_OPENAI_URI` is e.g. `https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo` +where `AZURE_OPENAI_URI` is e.g. `https://custom-domain.openai.azure.com` + +Then add the `deployment_id` to the api calls. e.g: + +``` ruby +client.embeddings( + deployment_id: 'gpt-35-turbo', + parameters: { + model: 'text-embedding-ada-002', + input: + } +) +``` ### Models diff --git a/lib/openai/http.rb b/lib/openai/http.rb index 89b1a6db..50c823e0 100644 --- a/lib/openai/http.rb +++ b/lib/openai/http.rb @@ -6,7 +6,9 @@ def get(path:) end&.body) end - def json_post(path:, parameters:) + def json_post(path:, parameters:, deployment_id: nil) + path = "/openai/deployments/#{deployment_id}/#{path}" if deployment_id + to_json(conn.post(uri(path: path)) do |req| if parameters[:stream].respond_to?(:call) req.options.on_data = to_json_stream(user_proc: parameters[:stream])