Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

openai-streams

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openai-streams - npm Package Compare versions

Comparing version 1.0.21 to 1.0.22-canary.2

dist/edge/index.d.ts

1

dist/globs/shared.d.ts

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

export declare const RUNTIME: string;
export declare const ENCODER: TextEncoder;
export declare const DECODER: TextDecoder;

2

dist/globs/shared.js

@@ -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",

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