New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

polyfact

Package Overview
Dependencies
Maintainers
3
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyfact - npm Package Compare versions

Comparing version 0.1.33 to 0.1.35

.github/workflows/publish.yml

48

dist/chats/index.js

@@ -25,8 +25,5 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Chat = exports.createChat = void 0;
const axios_1 = __importDefault(require("axios"));
const axios_1 = __importStar(require("axios"));
const t = __importStar(require("polyfact-io-ts"));

@@ -37,2 +34,3 @@ const stream_1 = require("stream");

const memory_1 = require("../memory");
const error_1 = require("../helpers/error");
const Message = t.type({

@@ -46,9 +44,17 @@ id: t.string,

async function createChat(systemPrompt, options = {}) {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(options);
const response = await axios_1.default.post(`${endpoint}/chats`, { system_prompt: systemPrompt }, {
headers: {
"X-Access-Token": token,
},
});
return response?.data?.id;
try {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(options);
const response = await axios_1.default.post(`${endpoint}/chats`, { system_prompt: systemPrompt }, {
headers: {
"X-Access-Token": token,
},
});
return response?.data?.id;
}
catch (e) {
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}
throw e;
}
}

@@ -137,8 +143,16 @@ exports.createChat = createChat;

async getMessages() {
const response = await axios_1.default.get(`${this.clientOptions.endpoint}/chat/${await this.chatId}/history`, {
headers: {
"X-Access-Token": this.clientOptions.token,
},
});
return response?.data?.filter((message) => Message.is(message));
try {
const response = await axios_1.default.get(`${this.clientOptions.endpoint}/chat/${await this.chatId}/history`, {
headers: {
"X-Access-Token": this.clientOptions.token,
},
});
return response?.data?.filter((message) => Message.is(message));
}
catch (e) {
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}
throw e;
}
}

@@ -145,0 +159,0 @@ }

@@ -30,3 +30,3 @@ "use strict";

exports.generateStream = exports.generateStreamWithInfos = exports.generateWithInfo = exports.generate = exports.generateWithTokenUsage = void 0;
const axios_1 = __importDefault(require("axios"));
const axios_1 = __importStar(require("axios"));
const t = __importStar(require("polyfact-io-ts"));

@@ -36,18 +36,3 @@ const stream_1 = require("stream");

const clientOpts_1 = require("./clientOpts");
class GenerationError extends Error {
constructor(errorType) {
switch (errorType) {
case "llm_init_failed":
super("The server failed to initialize its LLM.");
break;
case "generation_failed":
super("The generation failed.");
break;
default:
super("An unknown error occured");
break;
}
this.errorType = errorType || "unknown_error";
}
}
const error_1 = require("./helpers/error");
const PartialResultType = t.partial({

@@ -82,3 +67,6 @@ ressources: t.array(t.type({ id: t.string, content: t.string, similarity: t.number })),

if (!GenerationAPIResponse.is(res.data)) {
throw new GenerationError();
throw new error_1.ApiError({
code: "mismatched_response",
message: "The response from the API does not match the expected format",
});
}

@@ -92,4 +80,4 @@ return {

catch (e) {
if (e instanceof Error) {
throw new GenerationError(e.name);
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}

@@ -96,0 +84,0 @@ throw e;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = exports.set = void 0;
const axios_1 = __importDefault(require("axios"));
const axios_1 = __importStar(require("axios"));
const clientOpts_1 = require("./clientOpts");
const error_1 = require("./helpers/error");
async function set(key, value, clientOptions = {}) {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
await axios_1.default.put(`${endpoint}/kv`, {
key,
value,
}, {
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
});
try {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
await axios_1.default.put(`${endpoint}/kv`, {
key,
value,
}, {
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
});
}
catch (e) {
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}
throw e;
}
}
exports.set = set;
async function get(key, clientOptions = {}) {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
const response = await axios_1.default
.get(`${endpoint}/kv?key=${key}`, {
method: "GET",
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
})
.catch(() => ({
data: "",
}));
return response.data;
try {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
const response = await axios_1.default
.get(`${endpoint}/kv?key=${key}`, {
method: "GET",
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
})
.catch(() => ({
data: "",
}));
return response.data;
}
catch (e) {
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}
throw e;
}
}

@@ -37,0 +74,0 @@ exports.get = get;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Memory = exports.getAllMemories = exports.updateMemory = exports.createMemory = void 0;
const axios_1 = __importDefault(require("axios"));
const axios_1 = __importStar(require("axios"));
const clientOpts_1 = require("./clientOpts");
class MemoryError extends Error {
constructor(errorType) {
// TODO: proper error handling once the api is up and running
switch (errorType) {
default:
super("An unknown error occured");
break;
}
this.errorType = errorType || "unknown_error";
}
}
const error_1 = require("./helpers/error");
async function createMemory(clientOptions = {}) {

@@ -32,5 +42,4 @@ const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);

catch (e) {
console.log(e);
if (e instanceof Error) {
throw new MemoryError(e.name);
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}

@@ -57,4 +66,4 @@ throw e;

catch (e) {
if (e instanceof Error) {
throw new MemoryError(e.name);
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}

@@ -77,4 +86,4 @@ throw e;

catch (e) {
if (e instanceof Error) {
throw new MemoryError(e.name);
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}

@@ -81,0 +90,0 @@ throw e;

@@ -30,6 +30,7 @@ "use strict";

exports.transcribe = void 0;
const axios_1 = __importDefault(require("axios"));
const axios_1 = __importStar(require("axios"));
const form_data_1 = __importDefault(require("form-data"));
const t = __importStar(require("polyfact-io-ts"));
const clientOpts_1 = require("./clientOpts");
const error_1 = require("./helpers/error");
const ResultType = t.type({

@@ -39,18 +40,28 @@ text: t.string,

async function transcribe(file, clientOptions = {}) {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
const formData = new form_data_1.default();
formData.append("file", file, {
contentType: "audio/mp3",
filename: "file.mp3",
});
const res = await axios_1.default.post(`${endpoint}/transcribe`, formData, {
headers: {
"X-Access-Token": token,
},
});
const { data } = res;
if (ResultType.is(data)) {
return data.text;
try {
const { token, endpoint } = (0, clientOpts_1.defaultOptions)(clientOptions);
const formData = new form_data_1.default();
formData.append("file", file, {
contentType: "audio/mp3",
filename: "file.mp3",
});
const res = await axios_1.default.post(`${endpoint}/transcribe`, formData, {
headers: {
"X-Access-Token": token,
},
});
if (!ResultType.is(res.data)) {
throw new error_1.ApiError({
code: "mismatched_response",
message: "The response from the API does not match the expected format",
});
}
return res.data.text;
}
throw new Error(`Unexpected response from polyfact: ${JSON.stringify(data, null, 2)}`);
catch (e) {
if (e instanceof axios_1.AxiosError) {
throw new error_1.ApiError(e?.response?.data);
}
throw e;
}
}

@@ -57,0 +68,0 @@ exports.transcribe = transcribe;

@@ -22,4 +22,5 @@ import { kv, generateWithType, t } from "../lib/index";

functionDescriptionType,
{},
);
console.log(returnType);
})();

@@ -1,2 +0,2 @@

import axios from "axios";
import axios, { AxiosError } from "axios";
import * as t from "polyfact-io-ts";

@@ -13,2 +13,3 @@ import { Readable, PassThrough } from "stream";

import { Memory } from "../memory";
import { ApiError, ErrorData } from "../helpers/error";

@@ -26,15 +27,22 @@ const Message = t.type({

): Promise<string> {
const { token, endpoint } = defaultOptions(options);
try {
const { token, endpoint } = defaultOptions(options);
const response = await axios.post(
`${endpoint}/chats`,
{ system_prompt: systemPrompt },
{
headers: {
"X-Access-Token": token,
const response = await axios.post(
`${endpoint}/chats`,
{ system_prompt: systemPrompt },
{
headers: {
"X-Access-Token": token,
},
},
},
);
);
return response?.data?.id;
return response?.data?.id;
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}
throw e;
}
}

@@ -172,14 +180,21 @@

async getMessages(): Promise<t.TypeOf<typeof Message>[]> {
const response = await axios.get(
`${this.clientOptions.endpoint}/chat/${await this.chatId}/history`,
{
headers: {
"X-Access-Token": this.clientOptions.token,
try {
const response = await axios.get(
`${this.clientOptions.endpoint}/chat/${await this.chatId}/history`,
{
headers: {
"X-Access-Token": this.clientOptions.token,
},
},
},
);
);
return response?.data?.filter((message: any): message is t.TypeOf<typeof Message> =>
Message.is(message),
);
return response?.data?.filter((message: any): message is t.TypeOf<typeof Message> =>
Message.is(message),
);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}
throw e;
}
}

@@ -186,0 +201,0 @@ }

@@ -1,2 +0,2 @@

import axios from "axios";
import axios, { AxiosError } from "axios";
import * as t from "polyfact-io-ts";

@@ -7,22 +7,4 @@ import { Readable } from "stream";

import { Memory } from "./memory";
import { ApiError, ErrorData } from "./helpers/error";
class GenerationError extends Error {
errorType?: string;
constructor(errorType?: string) {
switch (errorType) {
case "llm_init_failed":
super("The server failed to initialize its LLM.");
break;
case "generation_failed":
super("The generation failed.");
break;
default:
super("An unknown error occured");
break;
}
this.errorType = errorType || "unknown_error";
}
}
const PartialResultType = t.partial({

@@ -105,3 +87,6 @@ ressources: t.array(t.type({ id: t.string, content: t.string, similarity: t.number })),

if (!GenerationAPIResponse.is(res.data)) {
throw new GenerationError();
throw new ApiError({
code: "mismatched_response",
message: "The response from the API does not match the expected format",
});
}

@@ -114,5 +99,5 @@

};
} catch (e) {
if (e instanceof Error) {
throw new GenerationError(e.name);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}

@@ -119,0 +104,0 @@ throw e;

@@ -1,3 +0,4 @@

import axios from "axios";
import axios, { AxiosError } from "axios";
import { ClientOptions, defaultOptions } from "./clientOpts";
import { ApiError, ErrorData } from "./helpers/error";

@@ -9,17 +10,24 @@ export async function set(

): Promise<void> {
const { token, endpoint } = defaultOptions(clientOptions);
try {
const { token, endpoint } = defaultOptions(clientOptions);
await axios.put(
`${endpoint}/kv`,
{
key,
value,
},
{
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
await axios.put(
`${endpoint}/kv`,
{
key,
value,
},
},
);
{
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
},
);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}
throw e;
}
}

@@ -31,17 +39,24 @@

): Promise<string> {
const { token, endpoint } = defaultOptions(clientOptions);
try {
const { token, endpoint } = defaultOptions(clientOptions);
const response = await axios
.get(`${endpoint}/kv?key=${key}`, {
method: "GET",
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
})
.catch(() => ({
data: "",
}));
const response = await axios
.get(`${endpoint}/kv?key=${key}`, {
method: "GET",
headers: {
"X-Access-Token": token,
"Content-Type": "application/json",
},
})
.catch(() => ({
data: "",
}));
return response.data;
return response.data;
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}
throw e;
}
}

@@ -48,0 +63,0 @@

@@ -1,18 +0,5 @@

import axios from "axios";
import axios, { AxiosError } from "axios";
import { ClientOptions, defaultOptions } from "./clientOpts";
import { ApiError, ErrorData } from "./helpers/error";
class MemoryError extends Error {
errorType?: string;
constructor(errorType?: string) {
// TODO: proper error handling once the api is up and running
switch (errorType) {
default:
super("An unknown error occured");
break;
}
this.errorType = errorType || "unknown_error";
}
}
async function createMemory(clientOptions: Partial<ClientOptions> = {}): Promise<{ id: string }> {

@@ -34,6 +21,5 @@ const { token, endpoint } = defaultOptions(clientOptions);

return res.data;
} catch (e) {
console.log(e);
if (e instanceof Error) {
throw new MemoryError(e.name);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}

@@ -69,5 +55,5 @@ throw e;

return res.data;
} catch (e) {
if (e instanceof Error) {
throw new MemoryError(e.name);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}

@@ -92,5 +78,5 @@ throw e;

return res.data;
} catch (e) {
if (e instanceof Error) {
throw new MemoryError(e.name);
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}

@@ -97,0 +83,0 @@ throw e;

@@ -1,2 +0,2 @@

import axios from "axios";
import axios, { AxiosError } from "axios";
import FormData from "form-data";

@@ -6,2 +6,3 @@ import { Readable } from "stream";

import { ClientOptions, defaultOptions } from "./clientOpts";
import { ApiError, ErrorData } from "./helpers/error";

@@ -16,23 +17,31 @@ const ResultType = t.type({

): Promise<string> {
const { token, endpoint } = defaultOptions(clientOptions);
try {
const { token, endpoint } = defaultOptions(clientOptions);
const formData = new FormData();
formData.append("file", file, {
contentType: "audio/mp3",
filename: "file.mp3",
});
const formData = new FormData();
formData.append("file", file, {
contentType: "audio/mp3",
filename: "file.mp3",
});
const res = await axios.post(`${endpoint}/transcribe`, formData, {
headers: {
"X-Access-Token": token,
},
});
const res = await axios.post(`${endpoint}/transcribe`, formData, {
headers: {
"X-Access-Token": token,
},
});
const { data } = res;
if (!ResultType.is(res.data)) {
throw new ApiError({
code: "mismatched_response",
message: "The response from the API does not match the expected format",
});
}
if (ResultType.is(data)) {
return data.text;
return res.data.text;
} catch (e: unknown) {
if (e instanceof AxiosError) {
throw new ApiError(e?.response?.data as ErrorData);
}
throw e;
}
throw new Error(`Unexpected response from polyfact: ${JSON.stringify(data, null, 2)}`);
}

@@ -39,0 +48,0 @@ export default function client(clientOptions: Partial<ClientOptions> = {}) {

{
"name": "polyfact",
"version": "0.1.33",
"version": "0.1.35",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc