Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: leakage of API key in the browser console #31

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
15 changes: 8 additions & 7 deletions components/APIKeyInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ interface Props {

export const APIKeyInput: React.FC<Props> = ({ apiKey, onChange }) => {
return (
<input
className="mt-1 h-[24px] w-[280px] rounded-md border border-gray-300 px-3 py-2 text-black shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm"
type="password"
placeholder="OpenAI API Key"
value={apiKey}
onChange={(e) => onChange(e.target.value)}
/>
<form>
<input
className="mt-1 h-[24px] w-[280px] rounded-md border border-gray-300 px-3 py-2 text-black shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-indigo-500 sm:text-sm"
type="password"
placeholder="OpenAI API Key"
onChange={(e) => onChange(e.target.value)}
/>
</form>
);
};
50 changes: 49 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"endent": "^2.1.0",
"eventsource-parser": "^1.0.0",
"next": "13.2.4",
"react": "18.2.0",
"react": "^18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
Expand All @@ -25,6 +25,7 @@
"autoprefixer": "^10.4.14",
"eslint": "8.37.0",
"eslint-config-next": "13.2.4",
"grunt-env": "^1.0.1",
"postcss": "^8.4.21",
"prettier-plugin-tailwindcss": "^0.2.6",
"tailwindcss": "^3.3.1",
Expand Down
2 changes: 1 addition & 1 deletion pages/api/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ const handler = async (req: Request): Promise<Response> => {
}
};

export default handler;
export default handler;
29 changes: 1 addition & 28 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ const createPrompt = (
return endent`
You are an expert programmer in all programming languages. Translate the natural language to "${outputLanguage}" code. Do not include \`\`\`.

Example translating from natural language to JavaScript:

Natural language:
Print the numbers 0 to 9.

JavaScript code:
for (let i = 0; i < 10; i++) {
console.log(i);
}

Natural language:
${inputCode}
Expand All @@ -32,16 +23,8 @@ const createPrompt = (
} else if (outputLanguage === 'Natural Language') {
return endent`
You are an expert programmer in all programming languages. Translate the "${inputLanguage}" code to natural language in plain English that the average adult could understand. Respond as bullet points starting with -.

Example translating from JavaScript to natural language:

JavaScript code:
for (let i = 0; i < 10; i++) {
console.log(i);
}


Natural language:
Print the numbers 0 to 9.

${inputLanguage} code:
${inputCode}
Expand All @@ -52,16 +35,6 @@ const createPrompt = (
return endent`
You are an expert programmer in all programming languages. Translate the "${inputLanguage}" code to "${outputLanguage}" code. Do not include \`\`\`.

Example translating from JavaScript to Python:

JavaScript code:
for (let i = 0; i < 10; i++) {
console.log(i);
}

Python code:
for i in range(10):
print(i)

${inputLanguage} code:
${inputCode}
Expand Down