@axflow/models
Version:
Zero-dependency, modular SDK for building robust natural language applications
35 lines (32 loc) • 866 B
JavaScript
// src/openai/embedding.ts
import { POST } from "@axflow/models/shared";
// src/openai/shared.ts
function headers(apiKey, customHeaders) {
const headers2 = {
accept: "application/json",
"content-type": "application/json",
...customHeaders
};
if (typeof apiKey === "string") {
headers2.authorization = `Bearer ${apiKey}`;
}
return headers2;
}
// src/openai/embedding.ts
var OPENAI_COMPLETIONS_API_URL = "https://api.openai.com/v1/embeddings";
async function run(request, options) {
const url = options.apiUrl || OPENAI_COMPLETIONS_API_URL;
const response = await POST(url, {
headers: headers(options.apiKey, options.headers),
body: JSON.stringify(request),
fetch: options.fetch,
signal: options.signal
});
return response.json();
}
var OpenAIEmbedding = class {
static run = run;
};
export {
OpenAIEmbedding
};