-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathhttp.ts
33 lines (30 loc) · 913 Bytes
/
http.ts
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
import { SlashCommand } from "../../index.js";
import { removeQuotesAndEscapes } from "../../util/index.js";
import { streamResponse } from "../../llm/stream.js";
const HttpSlashCommand: SlashCommand = {
name: "http",
description: "Call an HTTP endpoint to serve response",
run: async function* ({ ide, llm, input, params, fetch }) {
const url = params?.url;
if (!url) {
throw new Error("URL is not defined in params");
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
input: removeQuotesAndEscapes(input),
}),
});
// Stream the response
if (response.body === null) {
throw new Error("Response body is null");
}
for await (const chunk of streamResponse(response)) {
yield chunk;
}
},
};
export default HttpSlashCommand;