From e64b3da7af034de2a8fd40386dce78d1eb2f0433 Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Tue, 2 Jul 2024 00:07:56 +0530 Subject: [PATCH 1/4] commented out auto labellling functionality --- blt/urls.py | 4 +- website/templates/includes/md_editor.html | 4 +- website/templates/report.html | 113 +++++++++++----------- website/views.py | 82 ++++++++-------- 4 files changed, 101 insertions(+), 102 deletions(-) diff --git a/blt/urls.py b/blt/urls.py index 93d101312..0d79f108b 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -34,7 +34,7 @@ ) from website.views import ( # TODO(b) IssueView,; TODO(b): REMOVE like_issue2 etc AllIssuesView, - AutoLabel, + # AutoLabel, CompanySettings, ContributorStatsView, CreateHunt, @@ -508,7 +508,7 @@ 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("issue-auto-label/", AutoLabel, name="AutoLabel"), re_path( r"^trademarks/query=(?P[\w\s]+)", website.views.trademark_detailview, diff --git a/website/templates/includes/md_editor.html b/website/templates/includes/md_editor.html index d57712fc6..9480041da 100644 --- a/website/templates/includes/md_editor.html +++ b/website/templates/includes/md_editor.html @@ -40,9 +40,7 @@

BUG DESCRIPTION

+ placeholder="Enter your markdown here...">{{ form.markdown_description.value|default:'' }}
@@ -315,11 +312,11 @@

Latest Issues

class="w-[100%] flex justify-between md:pr-10 flex-wrap border-b border-gray-900/10 pb-10 my-10">
{% include "includes/md_editor.html" %} - + -->
@@ -549,54 +546,62 @@

{% 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; - } - - 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); - } - else { - console.log('No label found'); - } - }) - .catch(error => { - console.error('Error:', error); - }); - return true; -} + document.addEventListener("DOMContentLoaded", function() { + // Get the value from the URL parameter + var labelParam = new URLSearchParams(window.location.search).get("label"); + + // Set the selected option based on the parameter + if (labelParam !== null) { + document.getElementById("labelSelect").value = labelParam; + + // 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; + // } + + // 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); + // } + // else { + // console.log('No label found'); + // } + // }) + // .catch(error => { + // console.error('Error:', error); + // }); + // return true; + // } {% endblock after_js %} diff --git a/website/views.py b/website/views.py index 931ab1faa..c18349bc6 100644 --- a/website/views.py +++ b/website/views.py @@ -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 @@ -38,7 +37,6 @@ from django.contrib.auth.models import User from django.contrib.sites.shortcuts import get_current_site from django.core import serializers -from django.core.cache import cache from django.core.exceptions import ValidationError from django.core.files import File from django.core.files.base import ContentFile @@ -69,8 +67,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 @@ -4581,43 +4577,43 @@ 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}) +# 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) +# return JsonResponse({"error": "Method not allowed"}, status=405) From 2f68b251e87705902133c268b1cd0afcb8d4727e Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Wed, 3 Jul 2024 23:23:10 +0530 Subject: [PATCH 2/4] pre-commit --- blt/urls.py | 3 +-- website/templates/report.html | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/blt/urls.py b/blt/urls.py index 0d79f108b..51c0dd5a5 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -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, diff --git a/website/templates/report.html b/website/templates/report.html index fc2faf814..320d91791 100644 --- a/website/templates/report.html +++ b/website/templates/report.html @@ -312,9 +312,7 @@

Latest Issues

class="w-[100%] flex justify-between md:pr-10 flex-wrap border-b border-gray-900/10 pb-10 my-10">
{% include "includes/md_editor.html" %} -
From bfc4d537c9f7468d3988a2d3165aa72b087e9e50 Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Sat, 6 Jul 2024 19:49:45 +0530 Subject: [PATCH 3/4] removed comments --- blt/urls.py | 1 - website/templates/report.html | 63 +++-------------------------------- website/views.py | 43 +----------------------- 3 files changed, 6 insertions(+), 101 deletions(-) diff --git a/blt/urls.py b/blt/urls.py index 51c0dd5a5..2a7c350e3 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -507,7 +507,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"), re_path( r"^trademarks/query=(?P[\w\s]+)", website.views.trademark_detailview, diff --git a/website/templates/report.html b/website/templates/report.html index 320d91791..7afd063c9 100644 --- a/website/templates/report.html +++ b/website/templates/report.html @@ -171,12 +171,12 @@

Latest Issues