Skip to content

Commit 4cdbec4

Browse files
code clean up
1 parent 32f292e commit 4cdbec4

File tree

9 files changed

+27
-33
lines changed

9 files changed

+27
-33
lines changed

backend_service/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ venv/
3636
ENV/
3737
env.bak/
3838
venv.bak/
39+
local.settings.json
3940

4041
# Byte-compiled / optimized / DLL files
4142
__pycache__/

backend_service/AnalyzePrompt/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const axios = require("axios");
22

33
module.exports = async function (context, req) {
4-
// ✅ Log incoming request method
4+
55
context.log("🔹 Received request:", req.method);
66

7-
// ✅ Handle CORS Preflight (OPTIONS Request)
7+
88
if (req.method === "OPTIONS") {
99
context.log("🔹 Handling OPTIONS preflight request.");
1010
context.res = {
11-
status: 204, // No content response
11+
status: 204,
1212
headers: {
1313
"Access-Control-Allow-Origin": "*",
1414
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
@@ -18,15 +18,15 @@ module.exports = async function (context, req) {
1818
return;
1919
}
2020

21-
// ✅ Default CORS Headers for every response
21+
2222
const corsHeaders = {
2323
"Content-Type": "application/json",
2424
"Access-Control-Allow-Origin": "*",
2525
"Access-Control-Allow-Methods": "GET, POST, OPTIONS",
2626
"Access-Control-Allow-Headers": "Content-Type, Authorization"
2727
};
2828

29-
// ✅ Check if the request has a body
29+
3030
if (!req.body) {
3131
context.log("❌ Request body is missing!");
3232
context.res = { status: 400, body: { error: "Request body is missing!" }, headers: corsHeaders };
@@ -44,7 +44,7 @@ module.exports = async function (context, req) {
4444
}
4545

4646
try {
47-
// Step 1: Detect Language Using OpenAI
47+
4848
const languageResponse = await axios.post(
4949
`${process.env.OPENAI_ENDPOINT}/openai/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview`,
5050
{
@@ -61,7 +61,7 @@ module.exports = async function (context, req) {
6161
const detectedLanguage = languageResponse.data.choices[0].message.content.trim();
6262
let translatedPrompt = prompt;
6363

64-
// Step 2: Translate Non-English Text to English
64+
6565
if (detectedLanguage !== "English") {
6666
const translationResponse = await axios.post(
6767
`${process.env.OPENAI_ENDPOINT}/openai/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview`,
@@ -79,7 +79,7 @@ module.exports = async function (context, req) {
7979
translatedPrompt = translationResponse.data.choices[0].message.content.trim();
8080
}
8181

82-
// Step 3: Clarify Ambiguous Prompt
82+
8383
const contextAnalysisResponse = await axios.post(
8484
`${process.env.OPENAI_ENDPOINT}/openai/deployments/gpt-4o/chat/completions?api-version=2024-02-15-preview`,
8585
{
@@ -94,7 +94,7 @@ module.exports = async function (context, req) {
9494
);
9595
const clarifiedPrompt = contextAnalysisResponse.data.choices[0].message.content.trim();
9696

97-
// Step 4: Run Content Safety Check
97+
9898
const moderationResponse = await axios.post(
9999
`${process.env.CONTENT_SAFETY_ENDPOINT}/contentsafety/text:analyze?api-version=2023-10-01`,
100100
{ text: clarifiedPrompt, categories: ["Hate", "Sexual", "Violence", "SelfHarm"] },
@@ -147,7 +147,7 @@ module.exports = async function (context, req) {
147147
};
148148
}
149149

150-
// Step 6: Return Final Processed Prompt
150+
151151
context.res = {
152152
status: 200,
153153
body: jsonResponse,

backend_service/SpeechToText/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const sdk = require('microsoft-cognitiveservices-speech-sdk');
22

33
module.exports = async function (context, req) {
4-
// Handle CORS preflight requests (OPTIONS)
4+
55
if (req.method === 'OPTIONS') {
66
context.res = {
77
status: 200,
@@ -18,7 +18,7 @@ module.exports = async function (context, req) {
1818
const speechKey = process.env.AZURE_SPEECH_KEY;
1919
const speechRegion = process.env.AZURE_SPEECH_REGION;
2020

21-
// Handle missing speech key or region
21+
2222
if (!speechKey || !speechRegion) {
2323
context.res = {
2424
status: 500,

backend_service/test.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ <h1>Speech-to-Text Demo</h1>
4444
);
4545

4646
const transcription = await response.text();
47-
console.log(transcription);
4847
document.getElementById("transcription").innerText =
4948
"Transcription: " + transcription;
5049
};

web/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ node_modules
1111
dist
1212
dist-ssr
1313
*.local
14+
.env
1415

1516
# Editor directories and files
1617
.vscode/*

web/src/content.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ function injectReactScript() {
66
return;
77
}
88

9-
console.log("Injecting React components...");
109

1110
const script = document.createElement("script");
1211
script.id = "better-prompt-script";
@@ -22,7 +21,6 @@ injectReactScript();
2221
function handleInput(event: Event) {
2322
const target = event.target as HTMLInputElement | HTMLTextAreaElement;
2423
if (target && (target.tagName === "INPUT" || target.tagName === "TEXTAREA")) {
25-
console.log("📝 Detected input:", target.value);
2624

2725
chrome.runtime.sendMessage({ type: "TEXT_INPUT", text: target.value }, (response) => {
2826
console.log("📩 Response from background:", response);
@@ -55,7 +53,7 @@ window.addEventListener("message", (event) => {
5553

5654
console.log("Content script received prompt:", event.data.prompt);
5755

58-
// Forward the message to the background script
56+
5957
chrome.runtime.sendMessage(
6058
{ action: "fetchRephrasedPrompts", prompt: event.data.prompt },
6159
(response) => {
@@ -64,7 +62,7 @@ window.addEventListener("message", (event) => {
6462
} else {
6563
console.log("Content script received response:", response);
6664

67-
// Send response back to Sidebar.tsx
65+
6866
window.postMessage({ type: "PROMPT_RESPONSE", data: response }, "*");
6967
}
7068
}

web/src/inject.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function injectUI() {
1111
return;
1212
}
1313

14-
console.log("Before Filter", textAreas);
1514

1615
if (textAreas.length > 1) {
1716
const hasTextarea = textAreas.some((el) => el.tagName.toLowerCase() === "textarea");
@@ -24,8 +23,6 @@ function injectUI() {
2423
}
2524
}
2625

27-
console.log("After Filter", textAreas);
28-
2926
textAreas.forEach((textArea) => {
3027
if (!textArea.parentElement) return;
3128

web/src/sidebar.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import CloseIcon from "@mui/icons-material/Close";
1111
import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
1212
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
1313
import { motion } from "framer-motion";
14-
//import axios from "axios";
1514
import Microphone from "./Microphone";
1615

1716
interface SidebarProps {
@@ -26,9 +25,8 @@ const Sidebar: React.FC<SidebarProps> = ({ open, onClose, text, textArea }) => {
2625
const [loading, setLoading] = useState(false);
2726
const [inputText, setInputText] = useState(text);
2827
const [transcript, setTranscript] = useState<string | null>(null);
29-
const [isFinal, setIsFinal] = useState(false);
30-
//const [inputFinal, setInputFinal] = useState("");
31-
console.log(transcript, isFinal);
28+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
29+
const [_isFinal, setIsFinal] = useState(false);
3230

3331
useEffect(() => {
3432
setInputText(text);
@@ -44,10 +42,10 @@ const Sidebar: React.FC<SidebarProps> = ({ open, onClose, text, textArea }) => {
4442
return;
4543
}
4644

47-
// Communicate with the content script
45+
4846
window.postMessage({ type: "FETCH_PROMPTS", prompt: finalInput }, "*");
4947

50-
// Listen for the response
48+
5149
const handleResponse = (event: MessageEvent) => {
5250
if (event.data.type === "PROMPT_RESPONSE") {
5351
setSuggestions(event.data.data.suggestions || []);

web/vite.config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import react from "@vitejs/plugin-react";
55
export default defineConfig({
66
plugins: [react()],
77
build: {
8-
outDir: "dist", // Output directory for Chrome extension
8+
outDir: "dist",
99
emptyOutDir: true,
1010
rollupOptions: {
1111
input: {
12-
index: "index.html", // React UI (Popup)
13-
background: "src/background.ts", // Background script
12+
index: "index.html",
13+
background: "src/background.ts",
1414
content: "src/content.ts",
15-
inject:"src/inject.tsx" // Content script
15+
inject:"src/inject.tsx"
1616
},
1717
output: {
18-
format: "esm", // Use "esm" for Chrome Extension compatibility
19-
entryFileNames: "[name].js", // Ensures correct file names
20-
chunkFileNames: "[name]-[hash].js", // Avoids Rollup conflicts
18+
format: "esm",
19+
entryFileNames: "[name].js",
20+
chunkFileNames: "[name]-[hash].js",
2121
assetFileNames: "[name].[ext]"
2222
}
2323
}

0 commit comments

Comments
 (0)