https://promptfoo.dev/ logo
Setting up a HTTP provider in TypeScript SDK
# ❓|questions
p
I'm attempting to create a custom
TestSuiteConfig
object in TypeScript which includes a custom HTTP provider for my service, but I'm struggling to find examples of that. The type of `ProviderOptions`:
Copy code
ts

export interface ProviderOptions {
    id?: ProviderId;
    label?: ProviderLabel;
    config?: any;
    prompts?: string[];
    transform?: string;
    delay?: number;
    env?: EnvOverrides;
}
Is not clear what
config
should look like. What would the equivalent of
Copy code
yml
providers:
  - id: 'https://example.com/generate'
    config:
      method: 'POST'
      headers:
        'Content-Type': 'application/json'
      body:
        myPrompt: '{{prompt}}'
      responseParser: 'json.output'
Look like in TS?
i
It would look like an object with a "config" key, and nested "body" key etc.
The yaml translate directly to a js object
Copy code
js
{
  // ...
  providers: [{
    id: 'https://example.com/generate',
    config: {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: {
        foo: '{{bar}}',
      },
      responseParser: (json) => json.output,
    }
  }],
}
p
Perfect, that was all I needed!
Is there support for non JSON responses? I have an API which simply streams down the tokens as plain text, is that supported?
i
Ah nope, but I can add support for that by tomorrow
So you can do whatever you need with a plaintext response
p
got it, in the meantime i've set up a custom provider function to handle this
2 Views