@maximai/maxim-js
Version:
Maxim AI JS SDK. Visit https://getmaxim.ai for more info.
83 lines • 3.98 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const dataset_1 = require("src/lib/dataset/dataset");
const maxim_1 = require("../../maxim");
require("dotenv/config");
const axios_1 = __importDefault(require("axios"));
if (!process.env["MAXIM_API_KEY"])
throw new Error("Missing MAXIM_API_KEY environment variable");
if (!process.env["MAXIM_WORKSPACE_ID"])
throw new Error("Missing MAXIM_WORKSPACE_ID environment variable");
if (!process.env["MAXIM_LOG_REPO_ID"])
throw new Error("Missing MAXIM_LOG_REPO_ID environment variable");
const maxim = new maxim_1.Maxim({
apiKey: process.env["MAXIM_API_KEY"],
baseUrl: process.env["MAXIM_BASE_URL"],
});
const dataStructure = (0, dataset_1.createDataStructure)({
Input: "INPUT",
"Expected Output": "EXPECTED_OUTPUT",
targetLanguage: "VARIABLE",
nativeLanguage: "VARIABLE",
difficulty: "VARIABLE",
});
const data = [
{
Input: "How to say Hello",
"Expected Output": "To say \"Hello\" in Spanish, you say \"Hola.\" \n\nCan you try saying it? \nAlso, you can use \"Hola\" in different situations, just like in English! \n\nFor example: \n\n- \"Hola, ¿cómo estás?\" (Hello, how are you?) \n\nWould you like to learn how to respond to that question?",
targetLanguage: "Klingon",
nativeLanguage: "English",
difficulty: "beginner",
},
{
Input: "How to say Good",
"Expected Output": "Great question! In Spanish, \"good\" is \"bueno.\" \n\nHere's how you can use it in a sentence:\n\n- \"Es bueno.\" (It is good.)\n- \"El libro es bueno.\" (The book is good.)\n\nCan you try to use \"bueno\" in a sentence",
targetLanguage: "Klingon",
nativeLanguage: "English",
difficulty: "beginner",
},
];
async function main() {
const maximLogger = await maxim.logger({ id: process.env["MAXIM_LOG_REPO_ID"] });
const testRun = maxim
.createTestRun("testing tests + logs", process.env["MAXIM_WORKSPACE_ID"])
.withDataStructure(dataStructure)
.withData(data)
.withConcurrency(2)
.yieldsOutputWithTracing(async (data, traceId) => {
var _a, _b, _c, _d;
const response = await axios_1.default.post("http://localhost:3001/api/v1/chat", {
message: data.Input,
targetLanguage: data.targetLanguage,
nativeLanguage: data.nativeLanguage,
difficulty: data.difficulty,
}, {
headers: {
"trace-id": traceId,
},
});
const content = ((_c = (_b = (_a = response.data.data) === null || _a === void 0 ? void 0 : _a.choices[0]) === null || _b === void 0 ? void 0 : _b.message) === null || _c === void 0 ? void 0 : _c.content) || "";
const usage = (_d = response.data.data) === null || _d === void 0 ? void 0 : _d.usage;
return {
data: content,
meta: {
usage: {
totalTokens: (usage === null || usage === void 0 ? void 0 : usage.total_tokens) || 0,
completionTokens: (usage === null || usage === void 0 ? void 0 : usage.completion_tokens) || 0,
promptTokens: (usage === null || usage === void 0 ? void 0 : usage.prompt_tokens) || 0,
},
cost: {
input: ((usage === null || usage === void 0 ? void 0 : usage.prompt_tokens) || 0) * 0.0015,
output: ((usage === null || usage === void 0 ? void 0 : usage.completion_tokens) || 0) * 0.002,
total: ((usage === null || usage === void 0 ? void 0 : usage.total_tokens) || 0) * 0.00175,
},
},
};
}, maximLogger, true);
await testRun.run();
}
main().catch(console.error);
//# sourceMappingURL=testRun.js.map