
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@polymath-ai/client
Advanced tools
polymath
is a utility that uses AI to intelligently answer free-form
questions based on a particular library of content.
This is an ESM JavaScript client that you can use to ask a Polymath or series of them a couple types of questions.
This is the heart of what a Polymath does. It has a library of content, and given a query, it will return a subset of the library bits that represent good context for that given query.
let polymathResults = await client.ask("How long is a piece of string?");
polymathResults
is an object that contains:
bits
: a function that returns an array of all of the bits that matched. Each bit contains:
text
: string;embedding
: Vector;similarity?
: number;token_count
: number;context(tokenLength)
: A function that returns a helpful string of all of the text to easily be used in
a completion request. Can limit the context by passing in the tokenLength
limit.
maxBits(tokenLength)
: A function that returns the bits that fit into a given token length
This isn't the main job for a Polymath, but often you want to ask for a completion, we want to make it simple to do so in one fell swoop.
let completionResult = await client.completion(
"How long is a piece of string?"
);
completionResult
is an object that contains:
bits
: an array of all of the bits that matched. Same as above from polymathResults
infos
: An array with all of the info entries (without duplicates). They contain:
url
: pointing to the sourcetitle?
: content titledescription?
: content descriptioncompletion
: text of the completion (answer) from the model
When you setup a polymath object you have to pass in some options.
You have to pass in an Open AI API key, and then you need to tell it where you want to ask for information.
This can be locally via library files. Place an array of files and/or file patterns that point to
individual files, file globs (e.g. ./libraries/*.json
), or directories (.json files will be loaded).
For example, with a specific file:
let client = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
libraryFiles: ["./libraries/knowledge-string.json"],
promptTemplate:
"Answer using the context below please.\n\nContext: {context}\n\nQuestion: {prompt}\n\nAnswer:",
});
And/or you can point to a remote server URL for a Polymath:
let client = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
servers: ["https://polymath.almaer.com/"],
});
And why not ask multiple polymath servers?
let client = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
servers: ["https://remix.polymath.chat/", "https://preact.polymath.chat/"],
});
let results = await polymath.completion("Can you use Remix with Preact?");
If you have stored your library in Pinecone then you can tell Polymath to look there.
You will want to setup your environment variables, either directly or via a .env
file.
let client = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
pinecone: {
apiKey: process.env.PINECONE_API_KEY,
baseUrl: process.env.PINECONE_BASE_URL,
namespace: process.env.PINECONE_NAMESPACE,
},
});
let r = await client.ask("How long is a piece of string?");
You can also pass in other optional info such as overriding the prompt that you wish to use:
let polymath = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
libraryFiles: ["./libraries/knowledge-string.json"],
promptTemplate:
"Answer using the context below please.\n\nContext: {context}\n\nQuestion: {prompt}\n\nAnswer:",
});
And if you want some debugging info, just pass in debug: true
:
let polymath = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
libraryFiles: ["./libraries/knowledge-string.json"],
debug: true,
});
You may want to process a completion as it streams to you. To do so you need to setup a streamProcessor:
let client = new Polymath({
apiKey: process.env.OPENAI_API_KEY,
libraryFiles: ["./libraries/knowledge-string.json"],
});
let completionOptions = {
model: "text-davinci-003",
stream: true,
};
let streamProcessor = {
processResults: (r) => {
resolve();
t.pass();
},
processDelta: (delta) => {
// console.log("STREAMING DELTA:", delta);
},
};
client.completion(
"How long is a piece of string?",
undefined, // PolymathResults
undefined, // askOptions
completionOptions,
streamProcessor
);
Tests are located in tests/
. We use ava for a simple test library.
To run them you will want to set your OpenAI API Key environment variable first, and some of the tests will
use the simple library libraries/knowledge-string.json
that you can poke at too.
FAQs
A JavaScript client library to run Polymath
We found that @polymath-ai/client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.