irudnyts / openai

An R package-wrapper around OpenAI API
https://irudnyts.github.io/openai/
Other
164 stars 28 forks source link

Is there any plan to support Azure OpenAI Service? #39

Open swsoyee opened 1 year ago

swsoyee commented 1 year ago

It seems that just need to change the base_url to a function parameter that can be passed in. https://github.com/search?q=repo%3Airudnyts%2Fopenai%20https%3A%2F%2Fapi.openai.com%2Fv1&type=code

Reference: https://learn.microsoft.com/en-us/azure/cognitive-services/openai/chatgpt-quickstart?tabs=powershell&pivots=rest-api

irudnyts commented 1 year ago

@swsoyee, what I am thinking right now is to create a new package with much higher flexibility.

trangdata commented 1 year ago

Hi @irudnyts any updates on the new package? 📦 🙏🏽

irudnyts commented 1 year ago

Hi @trangdata! Not yet 😔 Is there any particular feature you are looking forward to? Or is it just base_url for Azure?

trangdata commented 1 year ago

@irudnyts Really just the base_url for Azure.

irudnyts commented 9 months ago

@trangdata @swsoyee I'm very sorry for the long wait. Here is a new dev version, and you can do it here:

remotes::install_github("irudnyts/openai", ref = "r6")

library(openai)
client <- OpenAI(base_url = "your_azure_url")
completion <- client$chat$completions$create(
    model = "gpt-4-1106-preview",
    messages = list(list("role" = "user", "content" = "What's up?"))
)

completion$choices[[1]]$message$content
JB0207 commented 4 months ago

@trangdata Did you get it to work? I am always getting a 404 error using the following base_url:

"https://[...]/openai.azure.com/openai/deployments/gpt-35-turbo/chat/completions?api-version=2024-02-01"

irudnyts commented 4 months ago

@JB0207 Can you please specify how exactly your URL should look like? When you specify base_url in OpenAI() and then use, for example, client$chat$completions$create(), the endpoint URL will look like your_azure_url/chat/completions.

JB0207 commented 4 months ago

@irudnyts Thank you for your fast response! Ah, I understand... According to the documentation of Azure OpenAI Service the endpoint url should look like this: https://{your-resource-name}.openai.azure.com/openai/deployments/{deployment-id}/chat/completions?api-version={api-version}.

trangdata commented 1 month ago

@trangdata Did you get it to work? I am always getting a 404 error using the following base_url:

No... I couldn't get the example code snippet to work. Error in httr2::req_perform(): ! HTTP 401 Unauthorized.