Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,34 @@ To run the backend, you need to:
```

2. Install the dependencies using `pip install -r requirements.txt`
3. Setup the parameters in api.py (do not forget to setup Azure OpenAI parameters at the beginign of the file)
3. Setup the parameters in api.py (do not forget to setup Azure OpenAI parameters at the beginning of the file)
4. Run the backend using `python api.py` or using `F5` in Visual Studio Code

## Setting the Azure OpenAI Deployment Name

To dynamically update the model deployment name for Azure OpenAI, set the `AZURE_OPENAI_DEPLOYMENT_NAME` environment variable. This allows the backend to fetch the deployment name at runtime.

For example, on Windows, you can set the environment variable like this:

```bash
set AZURE_OPENAI_DEPLOYMENT_NAME=your_model_deployment_name
```

And on Linux or macOS:

```bash
export AZURE_OPENAI_DEPLOYMENT_NAME=your_model_deployment_name
```

## Model Deployment Name Endpoints

The backend provides two REST endpoints to get and set the model deployment name dynamically:

- `GET /model-deployment-name`: Returns the current model deployment name.
- `POST /model-deployment-name`: Accepts a JSON payload with the `model_deployment_name` field to update the model deployment name. Example payload:

```json
{
"model_deployment_name": "new_model_deployment_name"
}
```
21 changes: 18 additions & 3 deletions backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
# Set the number of results to be returned by the retriever
retriever_k = 20

# Set the name of the GPT model to be used for the chatbot
gpt_model_name = ''
# Fetch the model deployment name dynamically from environment variable
gpt_model_name = os.getenv('AZURE_OPENAI_DEPLOYMENT_NAME', '')

# Set the name of the embeddings model to be used for the retriever
embeddings_model_name = 'text-embedding-ada-002'
Expand Down Expand Up @@ -105,5 +105,20 @@ def ask():
error = 'Invalid request'
return make_response(error, 400)

@app.route('/model-deployment-name', methods=['GET', 'POST'])
@cross_origin()
def model_deployment_name():
global gpt_model_name
if request.method == 'POST':
data = request.json
if 'model_deployment_name' in data:
gpt_model_name = data['model_deployment_name']
os.environ['AZURE_OPENAI_DEPLOYMENT_NAME'] = gpt_model_name
return make_response({'message': 'Model deployment name updated successfully.'}, 200)
else:
return make_response({'error': 'Model deployment name not provided.'}, 400)
elif request.method == 'GET':
return make_response({'model_deployment_name': gpt_model_name}, 200)

if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5000)