Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using Azure OpenAI API Endpoint #14

Open
BenTheCloudGuy opened this issue Mar 12, 2024 · 5 comments
Open

Add support for using Azure OpenAI API Endpoint #14

BenTheCloudGuy opened this issue Mar 12, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@BenTheCloudGuy
Copy link

I would love to see the option to pass in specific API Endpoints so that we can leverage Azure OpenAI API along with other implementations.

@vizovitin
Copy link
Owner

vizovitin commented Mar 12, 2024

Would you be able and willing to test such implementation? Do you have a summary of important differences from OpenAI API on hand?

along with other implementations

Which ones, for example?

@BenTheCloudGuy
Copy link
Author

More than willing and happy to help. I'm not a developer, but have been going down the path of building out a functional solution for using ChatGPT3.5 with my own data pulled from Azure Blob Storage. As a full disclosure I work for MSFT as an Azure CSA, so that is the reason I'm looking at this solution vs native OpenAI API.

The biggest changes will be the URL API Endpoint which is variable based on the Azure OpenAI deployment along with the following:
"CHATGPT_MODEL":"{{model-deployment-name}}", <-- Pulled from the Azure Portal and a user created string
"OPENAI_API_BASE":"https://{{openai-deployment-name}}.openai.azure.com/", <-- Pulled from the portal and is the name of the Azure OpenAI deployment resource.
"OPENAI_API_VERSION":"2023-03-15-preview",
"OPENAI_API_TYPE": "azure",

I've gotten things working via Python, but I was using the OpenAI Libraries (via import openai):

def chatbot(openAIKey,configDetails,prompt):
    ## Collect values from Config File.
    chatgpt_model_name = configDetails['CHATGPT_MODEL']
    openai.api_type = configDetails['OPENAI_API_TYPE']
    openai.api_key = openAIKey
    openai.api_base = configDetails['OPENAI_API_BASE']
    openai.api_version = configDetails['OPENAI_API_VERSION']

    response = openai.ChatCompletion.create(
                    engine=chatgpt_model_name,
                    messages=[
                        {"role": "system", "content": "You are a helpful assistant."},
                        {"role": "user", "content": prompt}
                    ]
                )

    # Return the response
    return (response['choices'][0]['message']['content'])

I was thinking we could add some additional Game Settings to settings.js:

  1. Allow adding a custom 'customEndpoingUrl' that can be any API Endpoint the user needs.
	game.settings.register(moduleName, 'endpointUrl', {
		name: 'ChatGPT Base URI',
		hint: 'You can either use the default OpenAI EndPoint or Azure OpenAI Endpoint.',
		scope: 'world',
		config: true,
		type: String,
		default: ''
	});
  1. Remove the "selection" option from 'modelVersion' to allow a user entered string. Along with updating the hint with some better instructions.
game.settings.register(moduleName, 'modelVersion', {
		name: 'ChatGPT model version',
		hint: 'Version of the ChatGPT model to use. Free accounts do not have access to GPT-4. If you are using Azure OpenAI, use the Model Name from the API endpoint URL.',
		scope: 'world',
		config: true,
		type: String,
		default: ''
	});

@BenTheCloudGuy
Copy link
Author

Is there a reason you didn't use the built in OpenAI Libraries for javascript?

@vizovitin
Copy link
Owner

@BenTheCloudGuy could you comment (and maybe check) if the implementation like in #15 is sufficient?

Regarding the modelVersion — isn't there an endpoint that lists the available models (presumably, /v1/models)? Could you provide an example string you personally would use for this field (just so I have some idea of the potential differences)?

@vizovitin vizovitin added the enhancement New feature or request label Apr 2, 2024
@BenTheCloudGuy
Copy link
Author

BenTheCloudGuy commented Jul 8, 2024

@BenTheCloudGuy could you comment (and maybe check) if the implementation like in #15 is sufficient?

Regarding the modelVersion — isn't there an endpoint that lists the available models (presumably, /v1/models)? Could you provide an example string you personally would use for this field (just so I have some idea of the potential differences)?

Sorry - work and life got crazy busy as I'm prepping everything for GenCon in about a month and we are end of Fiscal Year at work. I'll get this tested out asap and reply back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants