File size: 1,078 Bytes
496163b
0bd72ac
9af7af9
0bd72ac
 
 
 
 
9af7af9
0bd72ac
9af7af9
0bd72ac
 
 
 
 
 
9af7af9
 
496163b
0bd72ac
 
 
 
 
 
9af7af9
 
0bd72ac
 
 
496163b
0bd72ac
 
 
 
9af7af9
0bd72ac
9af7af9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// src/providers/http_provider.mjs
import { BaseProvider } from "./base.mjs";

/**
 * Generic HTTP provider.
 * Expected server contract:
 *   POST { prompt: "..." } → { output: "...", score?: number }
 */
export class HttpProvider extends BaseProvider {
  constructor(stage = "reward") {
    super();

    // REWARD_URL, VERIFIER_URL, GENERATOR_URL, HTTP_URL fallback
    this.url =
      process.env[`${stage.toUpperCase()}_URL`] ||
      process.env.HTTP_URL ||
      "http://localhost:8001/score";
  }

  async generate(prompt) {
    const body = { prompt };

    const res = await fetch(this.url, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(body)
    });

    if (!res.ok) throw new Error(`HttpProvider error: ${res.status}`);

    const json = await res.json();

    // Normalize: allow reward server to return { output } or full JSON
    if (typeof json === "string") return json;
    if (json.output) return json.output;
    if (json.response) return json.response;

    return JSON.stringify(json);
  }
}