Repository: promptfoo/promptfoo
Issue: HF Text Generation Inference Response Parsing Issue
Root cause: Interface Contract Mismatch

I'm trying out your hugging face provider for text-generation-inference and there is a small bug.

The hugging face "inference endpoint" returns a list of dicts, but the text-generation-inference servers only return a dict.  So `response.data[0]?.generated_text` needs to be `response.data?.generated_text`.

Also, the docs for the hugging face "inference endpoint" notes that the "[return values is either a dict or a list of dicts if you sent a list of inputs.](https://huggingface.co/docs/api-inference/detailed_parameters?code=curl#text-generation-task)".

Here's an example request to a TGI endpoint:
```
{
  "inputs": "My name is Olivier and I",
  "parameters": {
    "top_k": 10,
    "top_p": 0.95,
    "temperature": 0.5,
    "repetition_penalty": 1.03,
    "max_new_tokens": 20,
    "return_full_text": true,
    "do_sample": true
  }
}
```

and here's the response:
```
{
  "generated_text": "My name is Olivier and I am a 3D artist and animator from France.\n\nI have been working in the"
}
```


Also, here's the custom provider that I'm currently using and it's working 

```
const fetch = require('node-fetch');

class HuggingfaceTgiProvider {
  constructor(options = {}) {
      const { id, config = {} } = options;
      this.id = id ? () => id : this.id;
      this.config = config;
      this.debug = config.debug || false;
  }

  id() {
      return `huggingface:text-generation-inference:${this.id}`;
  }

  toString() {
      return `[Huggingface Text Generation Inference Provider ${this.id}]`;
  }

  async callApi(prompt) {
      const params = {
          inputs: prompt,
          parameters: this.config,
      };
      const url = this.config.apiEndpoint;

      if (this.debug) {
          console.log("Request URL:", url);
          console.log("Request Params:", params);
      }

      let response;
      try {
          response = await fetch(url, {
              method: 'POST',
              headers: {'Content-Type': 'application/json'},
              body: JSON.stringify(params),
          });

          const jsonResponse = await response.json();
          if (this.debug) {
              console.log("Raw Response:", jsonResponse); 
          }

          if (jsonResponse.error) {
              return {
                  error: `API call error: ${jsonResponse.error}`,
              };
          }
          if (!jsonResponse) {
              return {
                  error: `Malformed response data: ${jsonResponse}`,
              };
          }
          return {
              output: jsonResponse?.generated_text,
          };
      }
      catch (err) {
          if (this.debug) {
              console.log("Error during API call:", err);
          }
          return {
              error: `API call error: ${String(err)}. Output:\n${response?.data}`,
          };
      }
  }
}

module.exports = HuggingfaceTgiProvider;
```

Hi @amihalik,

Thanks for the report and the insight into a fix.  #357 should handle when the endpoint returns a dict instead of array.