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 5.5.0 to 5.5.1-canary.0

dist/lib/backoff.d.ts

2

dist/lib/openai/edge.js

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

import{streamArray as c}from"yield-stream";import{ENCODER as h}from"../../globs/shared.js";import{OpenAIError as e}from"../errors.js";import{ChatStream as b,EventStream as u,getTokensFromResponse as R,TokenStream as g}from"../streaming/index.js";import{OpenAIAPIEndpoints as y}from"../types.js";const D=async(n,m,{mode:r="tokens",apiBase:d="https://api.openai.com/v1",apiKey:i=process.env.OPENAI_API_KEY,apiHeaders:f={},controller:l,onDone:A,onParse:E}={})=>{if(!i)throw new e("NO_API_KEY");const p=n==="completions"||n==="chat",I=y[n],o=await fetch(`${d}/${I}`,{method:"POST",body:JSON.stringify({...m,stream:p?!0:void 0}),headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json",Accept:"application/json",...f},signal:l?.signal});switch(o.status){case 401:throw new e("INVALID_API_KEY");case 404:throw new e("INVALID_MODEL");case 429:throw new e("RATE_LIMIT_REACHED");case 500:throw new e("SERVER_ERROR");default:if(!o.body)throw new e("UNKNOWN")}let t;const s={mode:r,onDone:A,onParse:E};if(p)switch(r){case"raw":t=u(o.body,s);break;case"tokens":switch(n){case"chat":t=b(o.body,s);break;default:t=g(o.body,s);break}break;default:throw console.error(`Unknown mode: ${r} for streaming response.`),new e("UNKNOWN")}else{const a=await o.text();switch(r){case"tokens":const N=JSON.parse(a),w=R(N);if(typeof w!="string"){console.error("No text choices received from OpenAI: "+a),t=c([]);break}const O=h.encode(w);t=c([O]);break;case"raw":const k=h.encode(a);t=c([k]);break;default:throw console.error(`Unknown mode: ${r} for non-streaming response.`),new e("UNKNOWN")}}return t};export{D as OpenAI};
import{streamArray as c}from"yield-stream";import{OpenAIAPIEndpoints as b}from"../types.js";import{ENCODER as m}from"../../globs/shared.js";import{OpenAIError as e}from"../errors.js";import{fetchWithBackoff as u}from"../backoff.js";import{ChatStream as R,EventStream as g,getTokensFromResponse as y,TokenStream as S}from"../streaming/index.js";const $=async(n,h,{mode:r="tokens",apiBase:f="https://api.openai.com/v1",apiKey:i=process.env.OPENAI_API_KEY,apiHeaders:d={},controller:l,onDone:A,onParse:E}={})=>{if(!i)throw new e("NO_API_KEY");const p=n==="completions"||n==="chat",I=b[n],t=await u(`${f}/${I}`,{method:"POST",body:JSON.stringify({...h,stream:p?!0:void 0}),headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json",Accept:"application/json",...d},signal:l?.signal});switch(t.status){case 401:throw new e("INVALID_API_KEY");case 404:throw new e("INVALID_MODEL");case 429:throw new e("RATE_LIMIT_REACHED");case 500:throw new e("SERVER_ERROR");default:if(!t.body)throw new e("UNKNOWN")}let o;const s={mode:r,onDone:A,onParse:E};if(p)switch(r){case"raw":o=g(t.body,s);break;case"tokens":switch(n){case"chat":o=R(t.body,s);break;default:o=S(t.body,s);break}break;default:throw console.error(`Unknown mode: ${r} for streaming response.`),new e("UNKNOWN")}else{const a=await t.text();switch(r){case"tokens":const N=JSON.parse(a),w=y(N);if(typeof w!="string"){console.error("No text choices received from OpenAI: "+a),o=c([]);break}const O=m.encode(w);o=c([O]);break;case"raw":const k=m.encode(a);o=c([k]);break;default:throw console.error(`Unknown mode: ${r} for non-streaming response.`),new e("UNKNOWN")}}return o};export{$ as OpenAI};

@@ -6,3 +6,3 @@ {

"homepage": "https://github.com/SpellcraftAI/openai-streams",
"version": "5.5.0",
"version": "5.5.1-canary.0",
"license": "MIT",

@@ -9,0 +9,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