Issue with OpenAI Python Library and Azure OpenAI Python SDK

I have the following Flask app code called ‘’:

from flask import Flask, Blueprint, request, jsonify, make_response,current_app, render_template, redirect,url_for, Response,stream_with_context,send_from_directory,session, flash, g
from flask_socketio import SocketIO
from app1 import app1 as 1_blueprint, handle_prompt
from app2 import app2 as app2_blueprint, socketio as app2_socketio
from app3 import app3 as app3_blueprint

app = Flask(__name__)
app.config['SECRET_KEY'] = 'supersecretkey'
app.config['SECURITY_PASSWORD_SALT'] = 'somesalt'

app.register_blueprint(app1_blueprint, url_prefix='/app1')
app.register_blueprint(app2_blueprint, url_prefix='/app2')
app.register_blueprint(app3_blueprint, url_prefix='/app3')


socketio = SocketIO(app)

def on_send_prompt(data):
    handle_prompt(socketio, data)
def default_error_handler(e):
    print('An error occurred: ' + str(e))

# SocketIO event to handle client connection
def on_connect():
    print('Client connected:', request.sid)

if __name__ == '__main__':, debug=True)

It’s current objective is to be the handler of three submodules:, and app1 and app2 utilize the Azure OpenAI Python SDK with the bring your own data (BYOD) adapter and uses the regular OpenAI API library with the gpt4 model to complete its tasks. The function generating the output in the 2 Azure cases is this:

and the function used to generate output in the regular openAI case is this:

As 3 separate apps, i.e when being ran as their own individual modules rather than submodules in a Blueprint schema, the code works perfectly. However, now that I’ve consolidated them into one code base, I get the following error when trying to generate an Azure completion: “Request failed with exception: Unrecognized request argument supplied: dataSources” and the following error when running the regular OpenAI GPT4 completion: “Error extracting information: Must provide an ‘engine’ or ‘deployment_id’ parameter to create a <class ‘openai.api_resources.chat_completion.ChatCompletion’>”

The parameters both messages refer to are set correctly in the code, I know this because like I said they worked fine before copying everything to one codebase.

In the Azure OpenAI SDK cases, I noticed that the error only came after the second app was run (i.e: if I fired up then went to the subroute for and ran it, it worked fine. And if I followed this up by trying to run, I would get the error. But, if I started with and then ran, I would be able to use but not

So, my theory is that the cause of the errors is because of having multiple API sessions open simultaneously, is this something anyone knows anything about or can anyone provide advice or support on how to proceed? Thanks in advance for any help:)