Back

'Missing required field `prompt`'

  • 0
  • Functions
Pablo
31 May, 2024, 21:57

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}); }

TypeScript
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.

TL;DR
Issue: The developer is receiving an error message stating 'Missing required field `prompt`' when trying to run a function from the appwrite dashboard. The logs indicate that the prompt field is not being detected correctly. Solution: The code is checking if req.body.prompt is a string, but it should be checking if it exists first. Modify the if statement to check if req.body has the 'prompt' field.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more