fix ai gen

This commit is contained in:
Ishaan Dey 2024-05-14 00:18:27 -07:00
parent ce5e55bdf6
commit f3e9f81722
5 changed files with 10 additions and 19 deletions

View File

@ -8,9 +8,9 @@ export default {
if (request.method !== 'GET') { if (request.method !== 'GET') {
return new Response('Method Not Allowed', { status: 405 }); return new Response('Method Not Allowed', { status: 405 });
} }
if (request.headers.get('Authorization') !== env.KEY) { // if (request.headers.get('Authorization') !== env.KEY) {
return new Response('Unauthorized', { status: 401 }); // return new Response('Unauthorized', { status: 401 });
} // }
const url = new URL(request.url); const url = new URL(request.url);
const fileName = url.searchParams.get('fileName'); const fileName = url.searchParams.get('fileName');

View File

@ -75,6 +75,7 @@ const readAndParseKubeYaml = (
if (!process.env.CF_AI_KEY) { if (!process.env.CF_AI_KEY) {
throw new Error("CF_AI_KEY is not defined"); throw new Error("CF_AI_KEY is not defined");
} }
const regexEnv = new RegExp(`<CF_AI_KEY>`, "g"); const regexEnv = new RegExp(`<CF_AI_KEY>`, "g");
docString = docString.replace(regexEnv, process.env.CF_AI_KEY); docString = docString.replace(regexEnv, process.env.CF_AI_KEY);

View File

@ -22,7 +22,4 @@ USER myuser
EXPOSE 3000 EXPOSE 3000
ARG CF_AI_KEY
ENV CF_AI_KEY=$CF_AI_KEY
CMD [ "node", "dist/index.js" ] CMD [ "node", "dist/index.js" ]

View File

@ -404,8 +404,6 @@ io.on("connection", async (socket) => {
} }
); );
console.log("CF_AI_KEY", process.env.CF_AI_KEY);
// Generate code from cloudflare workers AI // Generate code from cloudflare workers AI
const generateCodePromise = fetch( const generateCodePromise = fetch(
`https://ai.ishaan1013.workers.dev/api?fileName=${fileName}&code=${code}&line=${line}&instructions=${instructions}`, `https://ai.ishaan1013.workers.dev/api?fileName=${fileName}&code=${code}&line=${line}&instructions=${instructions}`,
@ -423,7 +421,9 @@ io.on("connection", async (socket) => {
]); ]);
const json = await generateCodeResponse.json(); const json = await generateCodeResponse.json();
callback(json);
console.log("Code generation response", json);
callback({ response: json.response, success: true });
} }
); );

View File

@ -71,20 +71,13 @@ export default function GenerateInput({
data.code, data.code,
data.line, data.line,
regenerate ? currentPrompt : input, regenerate ? currentPrompt : input,
(res: { (res: { response: string; success: boolean }) => {
result: {
response: string;
};
success: boolean;
errors: any[];
messages: any[];
}) => {
if (!res.success) { if (!res.success) {
console.error(res.errors); toast.error("Failed to generate code.");
return; return;
} }
setCode(res.result.response); setCode(res.response);
router.refresh(); router.refresh();
} }
); );