fix ai gen
This commit is contained in:
parent
ce5e55bdf6
commit
f3e9f81722
@ -8,9 +8,9 @@ export default {
|
||||
if (request.method !== 'GET') {
|
||||
return new Response('Method Not Allowed', { status: 405 });
|
||||
}
|
||||
if (request.headers.get('Authorization') !== env.KEY) {
|
||||
return new Response('Unauthorized', { status: 401 });
|
||||
}
|
||||
// if (request.headers.get('Authorization') !== env.KEY) {
|
||||
// return new Response('Unauthorized', { status: 401 });
|
||||
// }
|
||||
|
||||
const url = new URL(request.url);
|
||||
const fileName = url.searchParams.get('fileName');
|
||||
|
@ -75,6 +75,7 @@ const readAndParseKubeYaml = (
|
||||
if (!process.env.CF_AI_KEY) {
|
||||
throw new Error("CF_AI_KEY is not defined");
|
||||
}
|
||||
|
||||
const regexEnv = new RegExp(`<CF_AI_KEY>`, "g");
|
||||
docString = docString.replace(regexEnv, process.env.CF_AI_KEY);
|
||||
|
||||
|
@ -22,7 +22,4 @@ USER myuser
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ARG CF_AI_KEY
|
||||
ENV CF_AI_KEY=$CF_AI_KEY
|
||||
|
||||
CMD [ "node", "dist/index.js" ]
|
@ -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
|
||||
const generateCodePromise = fetch(
|
||||
`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();
|
||||
callback(json);
|
||||
|
||||
console.log("Code generation response", json);
|
||||
callback({ response: json.response, success: true });
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -71,20 +71,13 @@ export default function GenerateInput({
|
||||
data.code,
|
||||
data.line,
|
||||
regenerate ? currentPrompt : input,
|
||||
(res: {
|
||||
result: {
|
||||
response: string;
|
||||
};
|
||||
success: boolean;
|
||||
errors: any[];
|
||||
messages: any[];
|
||||
}) => {
|
||||
(res: { response: string; success: boolean }) => {
|
||||
if (!res.success) {
|
||||
console.error(res.errors);
|
||||
toast.error("Failed to generate code.");
|
||||
return;
|
||||
}
|
||||
|
||||
setCode(res.result.response);
|
||||
setCode(res.response);
|
||||
router.refresh();
|
||||
}
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user