Comparing version 0.1.9 to 0.1.10
@@ -23,4 +23,7 @@ import { generateWithType, t } from "../lib/index"; | ||
}), | ||
{ | ||
provider: "cohere", | ||
}, | ||
), | ||
); | ||
})(); |
@@ -34,5 +34,15 @@ import fetch from "node-fetch"; | ||
export type GenerationOptions = { | ||
provider?: "openai" | "cohere"; | ||
}; | ||
async function generateWithTokenUsage( | ||
task: string, | ||
options: GenerationOptions = {}, | ||
): Promise<{ result: string; tokenUsage: { input: number; output: number } }> { | ||
if (!POLYFACT_TOKEN) { | ||
throw new Error( | ||
"Please put your polyfact token in the POLYFACT_TOKEN environment variable. You can get one at https://app.polyfact.com", | ||
); | ||
} | ||
const res = await fetch(`${POLYFACT_ENDPOINT}/generate`, { | ||
@@ -44,3 +54,3 @@ method: "POST", | ||
}, | ||
body: JSON.stringify({ task }), | ||
body: JSON.stringify({ task, provider: options.provider || "openai" }), | ||
}).then((res) => res.json()); | ||
@@ -55,4 +65,4 @@ | ||
async function generate(task: string): Promise<string> { | ||
const res = await generateWithTokenUsage(task); | ||
async function generate(task: string, options: GenerationOptions = {}): Promise<string> { | ||
const res = await generateWithTokenUsage(task, options); | ||
@@ -59,0 +69,0 @@ return res.result; |
@@ -1,2 +0,2 @@ | ||
import { generate, generateWithTokenUsage } from "./generate"; | ||
import { generate, generateWithTokenUsage, GenerationOptions } from "./generate"; | ||
import { | ||
@@ -6,2 +6,3 @@ generateWithType, | ||
} from "./probabilistic_helpers/generateWithType"; | ||
import { transcribe } from "./transcribe"; | ||
import { t } from "./probabilistic_helpers/types"; | ||
@@ -17,2 +18,4 @@ import { splitString } from "./split"; | ||
t, | ||
GenerationOptions, | ||
transcribe, | ||
}; |
/* eslint-disable no-use-before-define */ | ||
import * as t from "io-ts"; | ||
import fetch from "node-fetch"; | ||
import { generate, generateWithTokenUsage } from "../index"; | ||
import { generate, generateWithTokenUsage, GenerationOptions } from "../index"; | ||
@@ -85,2 +85,3 @@ function typePartial2String(entries: [string, any][], indent: number, partial: boolean): string { | ||
type: t.TypeC<T>, | ||
options: GenerationOptions = {}, | ||
): Promise<{ result: t.TypeOf<t.TypeC<T>>; tokenUsage: { input: number; output: number } }> { | ||
@@ -92,2 +93,3 @@ const typeFormat = tsio2String(type); | ||
generateTypedPrompt(typeFormat, task), | ||
options, | ||
); | ||
@@ -123,6 +125,7 @@ | ||
type: t.TypeC<T>, | ||
options: GenerationOptions = {}, | ||
): Promise<t.TypeOf<t.TypeC<T>>> { | ||
const res = await generateWithTypeWithTokenUsage(task, type); | ||
const res = await generateWithTypeWithTokenUsage(task, type, options); | ||
return res.result; | ||
} |
{ | ||
"name": "polyfact", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"main": "dist/index.js", | ||
@@ -10,2 +10,3 @@ "types": "dist/index.d.ts", | ||
"dependencies": { | ||
"form-data": "^4.0.0", | ||
"fp-ts": "^2.16.0", | ||
@@ -43,4 +44,4 @@ "io-ts": "^2.2.20", | ||
"cmd:build": "esbuild cmd/index.ts --bundle --outfile=build/polyfact.tmp --platform=node && echo -n '#!/usr/bin/env node\n' | cat - build/polyfact.tmp > build/polyfact && rm build/polyfact.tmp", | ||
"build": "tsc lib/index.ts --declaration --outDir dist" | ||
"build": "tsc -p tsconfig.json --declaration --outDir dist" | ||
} | ||
} |
@@ -19,3 +19,3 @@ { | ||
"outDir": "./dist", | ||
"baseUrl": "src/", | ||
"baseUrl": "lib/", | ||
"paths": { | ||
@@ -22,0 +22,0 @@ "@/*": ["*"] |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
849584
46
1779
6
7
+ Addedform-data@^4.0.0
+ Addedasynckit@0.4.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedes-set-tostringtag@2.1.0(transitive)
+ Addedform-data@4.0.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.3.0(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)