Hi, I'm trying to run a function from appwrite dashboard. I've been following the next tutorial:
Then, I've create the next function:
import { HfInference } from '@huggingface/inference';
export default async ({ req, res, log, error }) => {
log('Hello, Logs!');
log(req.body);
if (!req.body.prompt || typeof req.body.prompt !== 'string') {
log('No body');
return res.json({
ok: false,
error: 'Missing required field prompt'
}, 400);
}
else{
log(Prompt: ${req.body.prompt});
}
const hf = new HfInference(process.env.HUGGINGFACE_ACCESS_TOKEN);
try {
const completion = await hf.textGeneration({
model: 'mistralai/Mistral-7B-Instruct-v0.2',
inputs: req.body.prompt,
max_new_tokens: req.body.max_new_tokens || 200,
});
return res.json({ ok: true, completion }, 200);
} catch (err) {
return res.json({ ok: false, error: 'Failed to query model.' }, 500);
}
}
But, at the time to run it from appwrite dashboard, my code run the if statement: if (!req.body.prompt || typeof req.body.prompt !== 'string') { ......... }
The logs I get is:
Hello, Logs! { "prompt": "Write a story about a dragon" } No body
In the appwrite dashboard I run and pass the parameters to the body field as indicated in the tutorial: { "prompt": "Write a story about a dragon" }
but the "req.body.prompt" always is undefined i dont know what this happens.
Thanks in advanced.
Recommended threads
- Appwrite Auth & Function don't reveal cl...
When I execute a function or sign in with my Flutter app, Appwrite does not show my real IP: instead, it seems that Appwrite shows Fastly CDN IP address.
- Why does this happen?
`AppwriteException: general_argument_invalid, Invalid `secret` param: Value must be a valid string and at least 1 chars and no longer than 256 chars (400)` the...
- Selfhosted starter python function retur...
I am running a selfhosted appwrite instance. Creating a node function and executing it works just fine but when i try to execute a python starter function, i ge...