openai-streams
Advanced tools
Comparing version 1.0.21 to 1.0.22-canary.2
@@ -0,2 +1,3 @@ | ||
export declare const RUNTIME: string; | ||
export declare const ENCODER: TextEncoder; | ||
export declare const DECODER: TextDecoder; |
@@ -1,1 +0,1 @@ | ||
const e=new TextEncoder,o=new TextDecoder;export{o as DECODER,e as ENCODER}; | ||
const e=globalThis.process?.versions?.node?"node":"edge",o=new TextEncoder,n=new TextDecoder;export{n as DECODER,o as ENCODER,e as RUNTIME}; |
@@ -1,6 +0,1 @@ | ||
import { OpenAIAPI } from "../types"; | ||
/** | ||
* Create a new completion stream. Stream of strings by default, set `mode: | ||
* 'raw'` for the raw stream of JSON objects. | ||
*/ | ||
export declare const OpenAI: OpenAIAPI; | ||
export * from "./node"; |
@@ -1,1 +0,1 @@ | ||
import{streamArray as t}from"yield-stream";import{ENCODER as c}from"../../globs/index.js";import{EventStream as h,TokenStream as w}from"../streaming/index.js";const E=async(n,p,{mode:e="tokens",apiKey:s=process.env.OPENAI_API_KEY}={})=>{if(!s)throw new Error("No API key provided. Please set the OPENAI_API_KEY environment variable or pass the { apiKey } option.");const a=n==="completions",o=await fetch(`https://api.openai.com/v1/${n}`,{method:"POST",body:JSON.stringify({...p,stream:a?!0:void 0}),headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json",Accept:"application/json"}});if(!o.body)throw new Error("No response body");if(a)switch(e){case"tokens":return w(o.body);case"raw":return h(o.body);default:throw new Error(`Invalid mode: ${e}`)}const r=await o.text();switch(e){case"tokens":const d=JSON.parse(r),{text:i}=d.choices?.[0]??{};if(typeof i!="string")return console.error("No text choices received from OpenAI: "+r),t([]);const m=c.encode(i);return t([m]);case"raw":const f=c.encode(r);return t([f]);default:throw new Error(`Invalid mode: ${e}`)}};export{E as OpenAI}; | ||
export*from"./node.js"; |
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import type { CreateCompletionRequest, CreateEditRequest, CreateEmbeddingRequest, CreateFineTuneRequest, CreateImageRequest } from "./pinned"; | ||
@@ -16,3 +17,4 @@ export type StreamMode = "raw" | "tokens"; | ||
}; | ||
export type OpenAIAPI = <T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<ReadableStream<Uint8Array>>; | ||
export type OpenAIEdge = <T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<ReadableStream<Uint8Array>>; | ||
export type OpenAINode = <T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<NodeJS.ReadableStream>; | ||
export * from "./pinned"; |
{ | ||
"name": "openai-streams", | ||
"description": "Tools for working with OpenAI streams in Node.js and TypeScript.", | ||
"version": "1.0.21", | ||
"version": "1.0.22-canary.2", | ||
"license": "MIT", | ||
@@ -23,4 +23,4 @@ "type": "module", | ||
"docs": "yarn typedoc src", | ||
"prebuild": "yarn docs", | ||
"build": "tsmodule build", | ||
"postbuild": "yarn docs", | ||
"test": "ava", | ||
@@ -27,0 +27,0 @@ "pretest": "yarn build", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63897
28
1838
1