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.22-canary.3 to 1.0.22-canary.4

dist/lib/openai/node.d.ts

6

dist/lib/openai/edge.d.ts

@@ -1,6 +0,8 @@

import { OpenAIEdge } from "../types";
import { OpenAIEdgeClient } from "../types";
/**
* OpenAI Edge client.
*
* Create a new completion stream. Stream of strings by default, set `mode:
* 'raw'` for the raw stream of JSON objects.
*/
export declare const OpenAI: OpenAIEdge;
export declare const OpenAI: OpenAIEdgeClient;

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

import{streamArray as i,yieldStream as h}from"yield-stream";import{ENCODER as d}from"../../globs/shared.js";import{EventStream as l,TokenStream as y}from"../streaming/index.js";const p=async(t,s,{mode:e="tokens",apiKey:r=process.env.OPENAI_API_KEY}={})=>{if(!r)throw new Error("No API key provided. Please set the OPENAI_API_KEY environment variable or pass the { apiKey } option.");const n=t==="completions",o=await fetch(`https://api.openai.com/v1/${t}`,{method:"POST",body:JSON.stringify({...s,stream:n?!0:void 0}),headers:{Authorization:`Bearer ${r}`,"Content-Type":"application/json",Accept:"application/json"}});if(!o.body)throw new Error("No response body");if(n)switch(e){case"tokens":return y(o.body);case"raw":return l(o.body);default:throw new Error(`Invalid mode: ${e}`)}const a=await o.text();switch(e){case"tokens":const m=JSON.parse(a),{text:c}=m.choices?.[0]??{};if(typeof c!="string")return console.error("No text choices received from OpenAI: "+a),i([]);const f=d.encode(c);return i([f]);case"raw":const w=d.encode(a);return i([w]);default:throw new Error(`Invalid mode: ${e}`)}};p.Node=async(t,s,e)=>{const{Readable:r}=await import("stream"),n=await p(t,s,e);return r.from(h(n))};export{p as OpenAI};
import{streamArray as r}from"yield-stream";import{ENCODER as c}from"../../globs/shared.js";import{EventStream as h,TokenStream as w}from"../streaming/index.js";const I=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 i=n==="completions",o=await fetch(`https://api.openai.com/v1/${n}`,{method:"POST",body:JSON.stringify({...p,stream:i?!0:void 0}),headers:{Authorization:`Bearer ${s}`,"Content-Type":"application/json",Accept:"application/json"}});if(!o.body)throw new Error("No response body");if(i)switch(e){case"tokens":return w(o.body);case"raw":return h(o.body);default:throw new Error(`Invalid mode: ${e}`)}const t=await o.text();switch(e){case"tokens":const d=JSON.parse(t),{text:a}=d.choices?.[0]??{};if(typeof a!="string")return console.error("No text choices received from OpenAI: "+t),r([]);const m=c.encode(a);return r([m]);case"raw":const f=c.encode(t);return r([f]);default:throw new Error(`Invalid mode: ${e}`)}};export{I as OpenAI};
export * from "./edge";
export * from "./node";

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

export*from"./edge.js";
export*from"./edge.js";export*from"./node.js";

@@ -20,9 +20,4 @@ /// <reference types="node" />

*/
export type OpenAIEdge = (<T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<ReadableStream<Uint8Array>>) & {
/**
* The OpenAI API client for Node.js runtime.
*/
Node: OpenAINode;
};
export type OpenAINode = <T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<NodeJS.ReadableStream>;
export type OpenAIEdgeClient = (<T extends OpenAIAPIEndpoint>(endpoint: T, args: OpenAICreateArgs<T>, options?: OpenAIOptions) => Promise<ReadableStream<Uint8Array>>);
export type OpenAINodeClient = <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.22-canary.3",
"version": "1.0.22-canary.4",
"license": "MIT",

@@ -6,0 +6,0 @@ "type": "module",

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