TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.78k stars 1.21k forks source link

Feature Request: Is it possible to support Microsoft Azure GPT endpoint> #254

Open wang2nd opened 1 year ago

wang2nd commented 1 year ago

The python SDK support it so I assume not only the kernel, model, but also the interfaces are same.

cryptoapebot commented 1 year ago

Should be supported in 0.12.0. Just use the other constructor.

https://github.com/TheoKanning/openai-java/blob/93a556eb4fb68133c0920c69612a9d7ced0b15cb/client/src/main/java/com/theokanning/openai/OpenAiService.java

wang2nd commented 1 year ago

Thanks!

wang2nd commented 1 year ago

Should be supported in 0.12.0. Just use the other constructor.

https://github.com/TheoKanning/openai-java/blob/93a556eb4fb68133c0920c69612a9d7ced0b15cb/client/src/main/java/com/theokanning/openai/OpenAiService.java

I figured it out, the OpenAIService class you referenced here is a deprecated version, and as its comment "/**

I will switch to the Client library or just customize service library version through the OpenAIApi constructor as showed in readme. to see whether it works, but at the same time, please update the service library accordingly, below is a screenshot to prove service library is out of date

Screen Shot 2023-04-18 at 2 19 38 PM

I m using the OpenAIService.java in the Service library and its source codes clearly still the old version,

Thanks,

wang2nd commented 1 year ago

I can change the base url by customizing, but don't think it will work without other changes for Azure, due to its actual deployment path

e.g. https://myorganization-openai-test-1.openai.azure.com/openai/deployments/myorganizationDeployement/chat/completions?api-version=2023-03-15-preview

here is the python version to support it

import os
import openai
openai.api_type = "azure"
openai.api_base = "https://myorganization-openai-test-1.openai.azure.com/"
openai.api_version = "2023-03-15-preview"
openai.api_key = os.getenv("OPENAI_API_KEY")

response = openai.ChatCompletion.create(
  engine="myorganizationDeployement",
  messages = [],
  temperature=0.7,
  max_tokens=800,
  top_p=0.95,
  frequency_penalty=0,
  presence_penalty=0,
 stop=None)
cryptoapebot commented 1 year ago

Yeah, prob need to create a new service constructor w/ a flag as the paths are diff enough.