Skip to content

Commit

Permalink
Merge branch 'main' into blt-tomato
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT authored Jul 9, 2024
2 parents d3a3526 + 290e678 commit 00781c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 111 deletions.
4 changes: 1 addition & 3 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
UserIssueViewSet,
UserProfileViewSet,
)
from website.views import ( # TODO(b) IssueView,; TODO(b): REMOVE like_issue2 etc
from website.views import ( # TODO(b) IssueView,; TODO(b): REMOVE like_issue2 etc; AutoLabel,
AllIssuesView,
AutoLabel,
CompanySettings,
ContributorStatsView,
CreateHunt,
Expand Down Expand Up @@ -514,7 +513,6 @@
path("change_bid_status/", change_bid_status, name="change_bid_status"),
path("fetch-current-bid/", fetch_current_bid, name="fetch_current_bid"),
path("Submitpr/", submit_pr, name="submit_pr"),
path("issue-auto-label/", AutoLabel, name="AutoLabel"),
path("weekly-report/", weekly_report, name="weekly_report"),
re_path(
r"^trademarks/query=(?P<slug>[\w\s]+)",
Expand Down
4 changes: 1 addition & 3 deletions website/templates/includes/md_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ <h1 class="text-gray-700 text-2xl font-semibold">BUG DESCRIPTION</h1>
<textarea id="markdownInput"
name="markdown_description"
class="flex-1 h-[200px] bg-gray-200 text-2xl resize-none border border-gray-300 rounded-md p-5"
placeholder="Enter your markdown here..."
required
maxlength="20">{{ form.markdown_description.value|default:'' }}</textarea>
placeholder="Enter your markdown here...">{{ form.markdown_description.value|default:'' }}</textarea>
<div id="previewContainer"
class="h-[200px] flex-1 bg-white rounded-md p-4 hidden">
<div id="markdownPreview"></div>
Expand Down
70 changes: 10 additions & 60 deletions website/templates/report.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
right: 15px;
}

#generateLabel{
margin-left: 37%;
}
</style>
{% endblock style %}
{% block content %}
Expand Down Expand Up @@ -169,17 +166,17 @@ <h3 class="text-xl font-bold leading-none text-red-500">Latest Issues</h3>
</div>
<div class="sm:col-span-1 w-full min-w-[150px]">
<label for="label"
class="block text-2xl font-semibold leading-6 text-gray-900 hidden">
class="block text-2xl font-semibold leading-6 text-gray-900">
{% trans "BUG TYPE" %}
</label>
<div class="mt-2">
<select name="label"
required
id="labelSelect"
required
data-intro="Categorize the bug."
data-step="3"
class="flex w-full placeholder:text-xl rounded-md border-0 py-4 px-3 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset">
<option value="0"selected>General</option>
<option value="0" selected="selected">General</option>
<option value="1">Number error</option>
<option value="2">Functional</option>
<option value="3">Performance</option>
Expand Down Expand Up @@ -313,14 +310,7 @@ <h3 class="text-xl font-bold leading-none text-red-500">Latest Issues</h3>
</div>
<div id="bug-description-container"
class="w-[100%] flex justify-between md:pr-10 flex-wrap border-b border-gray-900/10 pb-10 my-10">
<div class="w-1/2">
{% include "includes/md_editor.html" %}
<button id="generateLabel"
onclick="Submit(event)"
class="rounded-md bg-red-600 px-11 py-3 text-md font-semibold text-white shadow-sm hover:bg-red-500">
Generate Label
</button>
</div>
<div class="w-1/2">{% include "includes/md_editor.html" %}</div>
<div class="w-1/2 pl-10 mt-5">
<div class="flex w-full items-center justify-between">
<h2 class="text-2xl font-semibold leading-7 text-gray-900">{% trans "ADD TEAM MEMBERS" %}</h2>
Expand Down Expand Up @@ -549,54 +539,14 @@ <h2 class="text-2xl font-semibold leading-7 text-gray-900">{% trans "ADD TEAM ME
email_container.appendChild(email_container_child_html)
}

function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
document.addEventListener("DOMContentLoaded", function() {
// Get the value from the URL parameter
var labelParam = new URLSearchParams(window.location.search).get("label");

function Submit() {
event.preventDefault();
const BugDescription = document.getElementById('markdownInput').value;
const csrftoken = getCookie('csrftoken');
fetch(`/issue-auto-label/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrftoken
},
body: JSON.stringify({ BugDescription: BugDescription }),
})
.then(response => response.json())
.then(data => {
if ('label' in data) {
console.log('Received label:', data.label);

const labelSelect = document.getElementById("labelSelect");
console.log('Current labelSelect value:', labelSelect.value);
labelSelect.selectedIndex = parseInt(data.label);
console.log('Selected label:', labelSelect.options[labelSelect.selectedIndex].text);
console.log('Updated labelSelect value:', labelSelect.selectedIndex);
// Set the selected option based on the parameter
if (labelParam !== null) {
document.getElementById("labelSelect").value = labelParam;
}
else {
console.log('No label found');
}
})
.catch(error => {
console.error('Error:', error);
});
return true;
}

</script>
{% endblock after_js %}
45 changes: 0 additions & 45 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from collections import deque
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from pathlib import Path
from urllib.parse import urlparse, urlsplit, urlunparse

import humanize
Expand Down Expand Up @@ -70,8 +69,6 @@
from django.views.decorators.http import require_GET
from django.views.generic import DetailView, ListView, TemplateView, View
from django.views.generic.edit import CreateView
from dotenv import load_dotenv
from openai import OpenAI
from PIL import Image, ImageDraw, ImageFont
from rest_framework import status
from rest_framework.authtoken.models import Token
Expand Down Expand Up @@ -4630,48 +4627,6 @@ def chatbot_conversation(request):
return Response({"answer": response["answer"]}, status=status.HTTP_200_OK)


def AutoLabel(request):
dotenv_path = Path("blt/.env")
load_dotenv(dotenv_path=dotenv_path)
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
token_Limit = 1000
token_per_prompt = 70
if request.method == "POST":
today = datetime.now(timezone.utc).date()
rate_limit_key = f"global_daily_request_{today}"
total_token_used = cache.get(rate_limit_key, 0)

if total_token_used + token_per_prompt > token_Limit:
return JsonResponse({"error": "Rate limit exceeded."}, status=429)

data = json.loads(request.body)
bug_description = data.get("BugDescription")
template = """
Label: {BugDescription}
Options: 0.General, 1.Number error, 2.Functional, 3.Performance, 4.Security, 5.Type, 6.Design, 7.Server down
Just return the number corresponding to the appropriate option.
"""
prompt = template.format(BugDescription=bug_description)
client = OpenAI(
api_key=OPENAI_API_KEY,
)
response = client.chat.completions.create(
messages=[
{
"role": "user",
"content": prompt,
}
],
model="gpt-3.5-turbo-0125",
max_tokens=1,
)
label = response.choices[0].message.content
cache.set(rate_limit_key, total_token_used + token_per_prompt, timeout=None)
return JsonResponse({"label": label})

return JsonResponse({"error": "Method not allowed"}, status=405)


def weekly_report(request):
domains = Domain.objects.all()
report_data = [
Expand Down

0 comments on commit 00781c6

Please sign in to comment.