Skip to content

Commit

Permalink
feat: Added azure openai settings to dash
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan committed Sep 7, 2024
1 parent b31cec5 commit 62e2421
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def endpoint():
""" """


result = kot_db.get("azureopenai_modelname")
result = kot_db.get("azureopenai_version")

return jsonify(
{
Expand Down
67 changes: 67 additions & 0 deletions upsonic_on_prem/dash/app/pages/azureopenai_settings/page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Page Informations
from app.pages.utils import get_current_directory_name

name = "Azure OpenAI Settings"
location = get_current_directory_name()
#


from django.urls import path
from dash.logs import logger
from django.shortcuts import render
from app.api_integration import API_Integration
from django.contrib.auth.decorators import login_required


@login_required
def view(request):
logger.debug("Hi")
result = None

if request.method == "POST":
azureopenai_baseurl_ = request.POST.get("azureopenai_baseurl")
azureopenai_key_ = request.POST.get("azureopenai_key")
azureopenai_modelname_ = request.POST.get("azureopenai_modelname")
azureopenai_version_ = request.POST.get("azureopenai_version")

if azureopenai_baseurl_:
API_Integration(request.user.access_key).change_azureopenai_baseurl(azureopenai_baseurl_)
result = "Azure OpenAI Base URL Updated"

if azureopenai_key_:
API_Integration(request.user.access_key).change_azureopenai_key(azureopenai_key_)
result = "Azure OpenAI Key Updated"

if azureopenai_modelname_:
API_Integration(request.user.access_key).change_azureopenai_modelname(azureopenai_modelname_)
result = "Azure OpenAI Model Name Updated"

if azureopenai_version_:
logger.info("verison")
logger.info(azureopenai_version_)
API_Integration(request.user.access_key).change_azureopenai_version(azureopenai_version_)
result = "Azure OpenAI Version Updated"

azureopenai = API_Integration(request.user.access_key).view_azureopenai()
azureopenai_baseurl = API_Integration(request.user.access_key).view_azureopenai_baseurl()
azureopenai_key = API_Integration(request.user.access_key).view_azureopenai_key()
azureopenai_modelname = API_Integration(request.user.access_key).view_azureopenai_modelname()
azureopenai_version = API_Integration(request.user.access_key).view_azureopenai_version()

if azureopenai_key:
the_length = len(azureopenai_key)
azureopenai_key = "*" * the_length

data = {
"page_title": name,
"azureopenai": azureopenai,
"azureopenai_baseurl": azureopenai_baseurl,
"azureopenai_key": azureopenai_key,
"azureopenai_modelname": azureopenai_modelname,
"azureopenai_version": azureopenai_version,
"result": result,
}
return render(request, f"pages/{location}/template.html", data)


url = path(location, view, name=name)
157 changes: 157 additions & 0 deletions upsonic_on_prem/dash/app/pages/azureopenai_settings/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{% extends "base.html" %}

{% load tags %}

{% block content %}


<div class="uk-container uk-width-expand uk-margin-medium-top scrollable_side" style="height: 100vh;">
<div uk-grid class="uk-margin-medium-bottom">
<div class="uk-width-expand">
{% if result != None %}
{% if result != False %}
<div class="uk-margin-medium-bottom uk-alert uk-alert-success" uk-alert>{{result}}</div>
{% else %}
<div class="uk-margin-medium-bottom uk-alert uk-alert-danger">{{result}}</div>
{% endif %}
{% endif %}
<h1 class="uk-h2 uk-margin text-foreground">
{{page_title}}</h1>

</div>

</div>
<div class="uk-margin-small-bottom" style="margin-top: 1.5rem;">

<div class="uk-navbar-right ">
<ul class="uk-navbar-nav uk-margin-medium-right" style="gap: 0.5rem;">

</ul>
</div>

</div>


<div class="uk-width-expand uk-margin-medium-top">



<div class="scrollable_side" uk-height-viewport="offset-top: true">


<div class=" uk-grid-small uk-grid-match" uk-grid>


<div class="uk-width-auto">
<div class="uk-card uk-card-body uk-card-default">
<h3 class="uk-card-title uk-margin-bottom">Active</h3>




<ul class="uk-subnav uk-subnav-primary" >
<li {% if not azureopenai %}class="uk-active"{% endif %}><a href="{% url 'Change AzureOpenAI Status' status='false' %}">Off</a></li>
<li {% if azureopenai %}class="uk-active"{% endif %} ><a href="{% url 'Change AzureOpenAI Status' status='true' %}">On</a></li>

</ul>



</div>
</div>




<div class="uk-width-1-6">
<div class="uk-card uk-card-body uk-card-default">
<h3 class="uk-card-title uk-margin-bottom">Base URL</h3>




<li style="width: 100%;" id="header_search_div">
<form action="{% url 'Azure OpenAI Settings' %}" method="post" autocomplete="off">
<div class="uk-margin-small-top ">
<div class="uk-inline" style="width: 100%;">

<input class="uk-input" style="width: 200%;" type="text" placeholder="{{azureopenai_baseurl}}" aria-label="Search" name="azureopenai_baseurl" value="{{azureopenai_baseurl}}" required/>
</div>
</div>


</form></li>




</div>
</div>


<div class="uk-width-1-6">
<div class="uk-card uk-card-body uk-card-default">
<h3 class="uk-card-title uk-margin-bottom">Key</h3>




<li style="width: 100%;" id="header_search_div">
<form action="{% url 'Azure OpenAI Settings' %}" method="post" autocomplete="off">
<div class="uk-margin-small-top ">
<div class="uk-inline" style="width: 100%;">

<input class="uk-input" style="width: 200%;" type="text" placeholder="{{azureopenai_key}}" aria-label="Search" name="azureopenai_key" value="{{azureopenai_key}}" required/>
</div>
</div>


</form></li>




</div>
</div>


<div class="uk-width-1-6">
<div class="uk-card uk-card-body uk-card-default">
<h3 class="uk-card-title uk-margin-bottom">Version</h3>




<li style="width: 100%;" id="header_search_div">
<form action="{% url 'Azure OpenAI Settings' %}" method="post" autocomplete="off">
<div class="uk-margin-small-top ">
<div class="uk-inline" style="width: 100%;">

<input class="uk-input" style="width: 200%;" type="text" placeholder="{{azureopenai_version}}" aria-label="Search" name="azureopenai_version" value="{{azureopenai_version}}" required/>
</div>
</div>


</form></li>




</div>
</div>



</div>





</div>

</div>

</div>

{% endblock content %}
35 changes: 35 additions & 0 deletions upsonic_on_prem/dash/app/pages/set_status_of_azureopenai/page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Page Informations
from app.pages.utils import get_current_directory_name

name = "Change AzureOpenAI Status"
location = get_current_directory_name()
hiden = True
#


from django.urls import path
from django.shortcuts import render
from django.shortcuts import redirect
from app import models
from app.api_integration import API_Integration
from django.contrib.auth.decorators import login_required
import traceback


@login_required
def view(request, status):
result = None

status = status.lower()

print("Changing Azure OpenAI status to", status)

result = API_Integration(request.user.access_key).change_azureopenai(
status
)


return redirect(to="Azure OpenAI Settings")


url = path(location + "/<status>", view, name=name)

0 comments on commit 62e2421

Please sign in to comment.