add ai worker
This commit is contained in:
@ -22,9 +22,7 @@ USER myuser
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ARG CF_API_TOKEN
|
||||
ARG CF_USER_ID
|
||||
ENV CF_API_TOKEN=$CF_API_TOKEN
|
||||
ENV CF_USER_ID=$CF_USER_ID
|
||||
ARG CF_AI_KEY
|
||||
ENV CF_AI_KEY=$CF_AI_KEY
|
||||
|
||||
CMD [ "node", "dist/index.js" ]
|
@ -163,36 +163,12 @@ export const generateCode = async ({
|
||||
instructions: string;
|
||||
}) => {
|
||||
return await fetch(
|
||||
`https://api.cloudflare.com/client/v4/accounts/${process.env.CF_USER_ID}/ai/run/@cf/meta/llama-3-8b-instruct`,
|
||||
`https://ai.ishaan1013.workers.dev/api?fileName=${fileName}&code=${code}&line=${line}&instructions=${instructions}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${process.env.CF_API_TOKEN}`,
|
||||
Authorization: `${process.env.CF_AI_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content:
|
||||
"You are an expert coding assistant. You read code from a file, and you suggest new code to add to the file. You may be given instructions on what to generate, which you should follow. You should generate code that is correct, efficient, and follows best practices. You should also generate code that is clear and easy to read. When you generate code, you should only return the code, and nothing else. You should not include backticks in the code you generate.",
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `The file is called ${fileName}.`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `Here are my instructions on what to generate: ${instructions}.`,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: `Suggest me code to insert at line ${line} in my file. Give only the code, and NOTHING else. DO NOT include backticks in your response. My code file content is as follows
|
||||
|
||||
${code}`,
|
||||
},
|
||||
],
|
||||
}),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user