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

@aigur/client

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aigur/client - npm Package Compare versions

Comparing version 1.11.0 to 1.12.0

src/nodes/text/prediction/gpt4.stream.ts

6

CHANGELOG.md
# @aigur/client
## 1.12.0
### Minor Changes
- 2883a14e: Add support for GPT-4
## 1.11.0

@@ -4,0 +10,0 @@

8

dist/index.js

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

var Z=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var ct=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var mt=(n,e)=>{for(var t in e)Z(n,t,{get:e[t],enumerable:!0})},ft=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ct(e))!ut.call(n,r)&&r!==t&&Z(n,r,{get:()=>e[r],enumerable:!(o=pt(e,r))||o.enumerable});return n};var lt=n=>ft(Z({},"__esModule",{value:!0}),n);var sn={};mt(sn,{Pipeline:()=>F,audioClassification:()=>me,automaticSpeechRecognition:()=>le,cleanContextVars:()=>Ve,conversational:()=>ye,createClient:()=>St,dalleBase64TextToImage:()=>We,dalleUrlTextToImage:()=>Je,enhanceWithKeywords:()=>Ge,featureExtraction:()=>he,fillMask:()=>Se,googleImageLabeling:()=>Fe,googleTextToSpeech:()=>at,gpt3Prediction:()=>Xe,gpt3PredictionStream:()=>ot,gpt3TurboPrediction:()=>Ze,gpt3TurboPredictionStream:()=>tt,hf:()=>ce,imageClassification:()=>Ie,imageSegmentation:()=>we,objectDetection:()=>Ae,output:()=>Y,questionAnswer:()=>Te,replaceMultipleStrings:()=>Ye,replaceString:()=>Qe,stabilityTextToImage:()=>qe,stringToArrayBuffer:()=>rt,summarization:()=>Ce,tableQuestionAnswer:()=>Re,textClassification:()=>Me,textGeneration:()=>Ee,textToImage:()=>Ke,tokenClassification:()=>Ue,translation:()=>Be,vercelEdgeFunction:()=>an,vercelGenericEdge:()=>re,whisperApi:()=>it,zeroShotClassification:()=>He});module.exports=lt(sn);function ae(n){return new Promise(e=>setTimeout(e,n))}function G(n,e){if(typeof n=="string")return o(n);return t({...n});function t(a){let i={};for(let c in a)i[c]=o(a[c]);return i}function o(a){if(Array.isArray(a))return a.map(p=>t(p));if(typeof a=="object"&&a!==null)return t(a);let i=a,c=ee(a);for(let p of c){let m=e[p.nodeId].output;if(m==null)continue;let f=m[p.property];if(f instanceof ArrayBuffer){i=f;continue}i=i?.replace(new RegExp(r(p.value)),f),i==="undefined"?i=void 0:i!==f&&i===f.toString()&&(i=f)}return i}function r(a){return a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}function ee(n){if(typeof n!="string")return[];let e=/\$context\.(\d+|input|memory|pipeline)\.(\w+)\$/g,t=n.matchAll(e),o=[];for(let r of t)o.push({value:r[0],nodeId:r[1],property:r[2]});return o}function H(n=16){let e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=t.length;for(let r=0;r<n;r++)e+=t.charAt(Math.floor(Math.random()*o));return e}function ie(n){let e={input:{input:n.input,output:n.input},memory:{input:n.memory,output:n.memory},pipeline:{input:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId},output:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId}}};return{pipelineInstanceId:n.pipelineInstanceId,input:n.input,output:{},values:e,memory:n.memory,userId:n.userId}}async function se(n,e){let{memoryToSave:t}=e;if(!t)return;let o=G(t,n.values);for(let r in t)for(let a in o){let i=o[a];if(i instanceof ReadableStream){let c=ee(t[r]),[p,m]=i.tee();n.values[c[0].nodeId].output=p;let f=await dt(m);o[a]=f}}return o}function dt(n){return new Promise(async e=>{let t=n.getReader(),o=new TextDecoder,r=!1,a="";for(;!r;){let{value:i,done:c}=await t.read();r=c;let p=o.decode(i);a+=p}e(a)})}var yt=2,gt=350,F=class{constructor(e,t,o){this.conf=e;this.flow=t;this.apiKeys=o;this.onProgressListeners=new Map;this.onStartListeners=new Map;this.onFinishListeners=new Map;this.pipelineInstanceId=H(16);this.eventIndex=0;this.vercel={invoke:(e,t)=>this.invokeRemote(`/api/pipelines/${this.conf.id}`,e,{userId:t?.userId}),invokeStream:(e,t,o)=>this.invokeStream(`/api/pipelines/${this.conf.id}`,e,t,{userId:o?.userId})};this.listenToEvents()}async invoke(e,t){let o=await this.loadMemory(t?.userId),r=ie({input:e,pipelineInstanceId:t?.pipelineInstanceId??this.pipelineInstanceId,userId:t?.userId??"",memory:o});return await this.processPipeline(r),r.output}async saveMemory(e,t){let o=await t;!this.conf.memoryManager||!o||this.conf.memoryManager.saveMemory(this.getMemoryId(e.userId),o)}getMemoryId(e){return`${this.conf.id}${e?`-${e}`:""}`}loadMemory(e){return this.conf.memoryManager?this.conf.memoryManager.loadMemory(this.getMemoryId(e)):Promise.resolve(null)}invokeRemote(e,t,o){return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:o?.userId??""})}).then(r=>r.json())}async invokeStream(e,t,o,r){let a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:r?.userId??""})});if(!a.ok)throw new Error(a.statusText);let i=a.body;if(!i)return;let c=i.getReader(),p=new TextDecoder,m=!1;for(;!m;){let{value:f,done:T}=await c.read();m=T;let $=p.decode(f);o($)}}onProgress(e){let t=H();return this.onProgressListeners.set(t,e),()=>{this.onProgressListeners.delete(t)}}onStart(e){let t=H();return this.onStartListeners.set(t,e),()=>{this.onStartListeners.delete(t)}}onFinish(e){let t=H();return this.onFinishListeners.set(t,e),()=>{this.onFinishListeners.delete(t)}}async processPipeline(e){let t=this.conf.retries??yt;try{let o=this.notifyEvent({type:"pipeline:start",context:e});if(this.conf.stream||await o,this.conf.validateInput){let i=this.conf.validateInput(e.input);if(!i.valid)throw new Error(i.message)}let r=this.flow.getNodes();for(let i=0;i<r.length;i++){let c=this.notifyEvent({type:"node:start",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await c;let p=0,m=!1;do{p++;try{let{action:T,input:$}=r[i],X=e.values[i]={input:null,output:null};X.input=G($,e.values),X.output=await T(X.input,this.apiKeys);let st=se(e,r[i]);this.saveMemory(e,st),m=!0}catch(T){if(p>t)throw T;await ae((this.conf.retryDelayInMs??gt)*p)}}while(!m&&p<=t);let f=this.notifyEvent({type:"node:finish",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await f}e.output=e.values[r.length-1].output;let a=this.notifyEvent({type:"pipeline:finish",context:e,data:{output:e.output instanceof ReadableStream?"Stream":e.output}});return this.conf.stream||await a,e}catch(o){throw console.error(o),o}}listenToEvents(){!this.conf.updateProgress||typeof window>"u"||!this.conf.eventListener||this.conf.eventListener(this.pipelineInstanceId,e=>{e.pipelineId===this.conf.id&&(e.type==="node:start"||e.type==="node:finish"?this.triggerListeners(this.onProgressListeners,e):e.type==="pipeline:start"?this.triggerListeners(this.onStartListeners,e):e.type==="pipeline:finish"&&this.triggerListeners(this.onFinishListeners,e))})}triggerListeners(e,...t){for(let o of e.values())o(...t)}notifyEvent(e){if(!(!this.conf.updateProgress||!this.conf.eventPublisher))return this.conf.eventPublisher(e.context.pipelineInstanceId,{pipelineId:this.conf.id,eventIndex:this.eventIndex++,type:e.type,data:e.data})}};async function Y(n){return n}var Q=class{constructor(e){this.nodes=e}node(e,t,o){let r=this.createDynamicPlaceholders("memory"),a=this.createDynamicPlaceholders("input"),i=this.createDynamicPlaceholders(this.nodes.length),c=this.nodes.length>0?this.nodes[this.nodes.length-1]:a,p="$context.pipeline.userId$",m={action:e,input:t({nodes:this.nodes,prev:c.output,input:a,memory:r,userId:p}),output:this.createDynamicPlaceholders(this.nodes.length),memoryToSave:o?o({nodes:this.nodes,prev:c.output,output:i,input:a,memory:r,userId:p}):null};return this.nodes.push(m),this}createDynamicPlaceholders(e){let t={},o={get:function(a,i){return`$context.${e}.${i}$`}};return new Proxy(t,o)}output(e,t){return this.node(Y,e,t)}getNodes(){return this.nodes}};var ht=2,xt=350,St=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??ht,retryDelayInMs:t.retryDelayInMs??xt,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new Q([]));return new F(o,r,e)}}}};var z=require("zod"),ue=require("@huggingface/inference");var O=require("zod"),pe=require("@huggingface/inference");function ce(n,e){return(t,o)=>{let r=new pe.HfInference(o.huggingface);return n(r).call(r,t,e)}}var s=O.z.object({retry_on_error:O.z.boolean().optional().default(!0),use_cache:O.z.boolean().optional().default(!0),use_gpu:O.z.boolean().optional(),wait_for_model:O.z.boolean().optional()}).optional();var bt=z.z.object({model:z.z.string(),data:z.z.instanceof(ArrayBuffer),options:s}),_n=z.z.object({result:z.z.array(z.z.object({label:z.z.string(),score:z.z.number()}))});async function me(n,e){let{options:t,...o}=bt.parse(n);return{result:await new ue.HfInference(e.huggingface).audioClassification(o,t)}}var K=require("zod"),fe=require("@huggingface/inference");var It=K.z.object({model:K.z.string(),data:K.z.instanceof(ArrayBuffer),options:s}),Mn=K.z.object({text:K.z.string()});async function le(n,e){let{options:t,...o}=It.parse(n),r=new fe.HfInference(e.huggingface),{text:a}=await r.automaticSpeechRecognition(o,t);return{text:a}}var u=require("zod"),de=require("@huggingface/inference");var Pt=u.z.object({model:u.z.string(),inputs:u.z.object({generated_responses:u.z.string().array().optional(),past_user_inputs:u.z.string().array().optional(),text:u.z.string()}),parameters:u.z.object({max_length:u.z.number().int().optional(),max_time:u.z.number().min(0).max(120).optional(),min_length:u.z.number().int().optional(),repetition_penalty:u.z.number().min(0).max(100).optional(),temperature:u.z.number().min(0).max(100).optional().default(1),top_k:u.z.number().int().optional(),top_p:u.z.number().optional()}).optional(),options:s}),On=u.z.object({conversation:u.z.object({generated_responses:u.z.string().array(),past_user_inputs:u.z.string().array()}),generated_text:u.z.string(),warnings:u.z.string().array()});async function ye(n,e){let{options:t,...o}=Pt.parse(n);return await new de.HfInference(e.huggingface).conversational(o,t)}var b=require("zod"),ge=require("@huggingface/inference");var wt=b.z.object({model:b.z.string(),inputs:b.z.record(b.z.string(),b.z.any()).or(b.z.record(b.z.string(),b.z.any()).array()),options:s}),Un=b.z.object({result:b.z.array(b.z.number().or(b.z.number().array()))});async function he(n,e){let{options:t,...o}=wt.parse(n);return{result:await new ge.HfInference(e.huggingface).featureExtraction(o,t)}}var v=require("zod"),xe=require("@huggingface/inference");var vt=v.z.object({model:v.z.string(),inputs:v.z.string(),options:s}),$n=v.z.object({result:v.z.array(v.z.object({score:v.z.number(),sequence:v.z.string(),token:v.z.number(),token_str:v.z.string()}))});async function Se(n,e){let{options:t,...o}=vt.parse(n);return{result:await new xe.HfInference(e.huggingface).fillMask(o,t)}}var C=require("zod"),be=require("@huggingface/inference");var At=C.z.object({model:C.z.string(),data:C.z.instanceof(ArrayBuffer),options:s}),Wn=C.z.object({result:C.z.array(C.z.object({label:C.z.string(),score:C.z.number()}))});async function Ie(n,e){let{options:t,...o}=At.parse(n);return{result:await new be.HfInference(e.huggingface).imageClassification(o,t)}}var j=require("zod"),Pe=require("@huggingface/inference");var jt=j.z.object({model:j.z.string(),data:j.z.instanceof(ArrayBuffer),options:s}),Vn=j.z.object({result:j.z.array(j.z.object({label:j.z.string(),mask:j.z.string(),score:j.z.number()}))});async function we(n,e){let{options:t,...o}=jt.parse(n);return{result:await new Pe.HfInference(e.huggingface).imageSegmentation(o,t)}}var g=require("zod"),ve=require("@huggingface/inference");var Tt=g.z.object({model:g.z.string(),data:g.z.instanceof(ArrayBuffer),options:s}),Qn=g.z.object({result:g.z.array(g.z.object({box:g.z.object({xmax:g.z.number(),xmin:g.z.number(),ymax:g.z.number(),ymin:g.z.number()}),label:g.z.string(),score:g.z.number()}))});async function Ae(n,e){let{options:t,...o}=Tt.parse(n);return{result:await new ve.HfInference(e.huggingface).objectDetection(o,t)}}var A=require("zod"),je=require("@huggingface/inference");var zt=A.z.object({model:A.z.string(),inputs:A.z.object({context:A.z.string(),question:A.z.string()}),options:s}),eo=A.z.object({answer:A.z.string(),end:A.z.number(),score:A.z.number(),start:A.z.number()});async function Te(n,e){let{options:t,...o}=zt.parse(n);return await new je.HfInference(e.huggingface).questionAnswer(o,t)}var h=require("zod"),ze=require("@huggingface/inference");var Ct=h.z.object({model:h.z.string(),inputs:h.z.string(),parameters:h.z.object({max_length:h.z.number().int().optional(),max_time:h.z.number().min(0).max(120).optional(),min_length:h.z.number().int().optional(),repetition_penalty:h.z.number().min(0).max(100).optional(),temperature:h.z.number().min(0).max(100).optional().default(1),top_k:h.z.number().int().optional(),top_p:h.z.number().optional()}).optional(),options:s}),oo=h.z.object({summary_text:h.z.string()});async function Ce(n,e){let{options:t,...o}=Ct.parse(n),r=new ze.HfInference(e.huggingface),{summary_text:a}=await r.summarization(o,t);return{summary_text:a}}var I=require("zod"),_e=require("@huggingface/inference");var _t=I.z.object({model:I.z.string(),inputs:I.z.object({query:I.z.string(),table:I.z.record(I.z.string().array())}),options:s}),io=I.z.object({aggregator:I.z.string(),answer:I.z.string(),cells:I.z.string().array(),coordinates:I.z.number().array().array()});async function Re(n,e){let{options:t,...o}=_t.parse(n);return await new _e.HfInference(e.huggingface).tableQuestionAnswer(o,t)}var _=require("zod"),Ne=require("@huggingface/inference");var Rt=_.z.object({model:_.z.string(),inputs:_.z.string(),options:s}),co=_.z.object({result:_.z.array(_.z.object({label:_.z.string(),score:_.z.number()}))});async function Me(n,e){let{options:t,...o}=Rt.parse(n);return{result:await new Ne.HfInference(e.huggingface).textClassification(o,t)}}var l=require("zod"),De=require("@huggingface/inference");var Nt=l.z.object({model:l.z.string(),inputs:l.z.string(),parameters:l.z.object({do_sample:l.z.boolean().optional().default(!0),max_new_tokens:l.z.number().int().min(0).max(250).optional(),max_time:l.z.number().min(0).max(120).optional(),num_return_sequences:l.z.number().int().min(0).optional().default(1),repetition_penalty:l.z.number().min(0).max(100).optional(),return_full_text:l.z.boolean().optional().default(!0),temperature:l.z.number().min(0).max(100).optional().default(1),top_k:l.z.number().int().optional(),top_p:l.z.number().optional()}).optional(),options:s}),fo=l.z.object({generated_text:l.z.string()});async function Ee(n,e){let{options:t,...o}=Nt.parse(n),r=new De.HfInference(e.huggingface),{generated_text:a}=await r.textGeneration(o,t);return{generated_text:a}}var D=require("zod"),Oe=require("@huggingface/inference");var Mt=D.z.object({model:D.z.string(),inputs:D.z.string(),negative_prompt:D.z.string().optional(),options:s}),go=D.z.object({result:D.z.instanceof(ArrayBuffer)});async function Ke(n,e){let{options:t,...o}=Mt.parse(n);return{result:await new Oe.HfInference(e.huggingface).textToImage(o,t)}}var x=require("zod"),ke=require("@huggingface/inference");var Dt=x.z.object({model:x.z.string(),inputs:x.z.string(),parameters:x.z.object({aggregation_strategy:x.z.enum(["none","simple","first","average","max"]).optional().default("simple")}).optional(),options:s}),So=x.z.object({result:x.z.array(x.z.object({end:x.z.number(),entity_group:x.z.string(),score:x.z.number(),start:x.z.number(),word:x.z.string()}))});async function Ue(n,e){let{options:t,...o}=Dt.parse(n);return{result:await new ke.HfInference(e.huggingface).tokenClassification(o,t)}}var k=require("zod"),Le=require("@huggingface/inference");var Et=k.z.object({model:k.z.string(),inputs:k.z.string(),options:s}),Po=k.z.object({translation_text:k.z.string()});async function Be(n,e){let{options:t,...o}=Et.parse(n),r=new Le.HfInference(e.huggingface),{translation_text:a}=await r.translation(o,t);return{translation_text:a}}var S=require("zod"),$e=require("@huggingface/inference");var Ot=S.z.object({model:S.z.string(),inputs:S.z.string().or(S.z.string().array()),parameters:S.z.object({candidate_labels:S.z.string().array(),multi_label:S.z.boolean().optional()}),options:s}),Ao=S.z.object({result:S.z.array(S.z.object({labels:S.z.string().array(),scores:S.z.number().array(),sequence:S.z.string()}))});async function He(n,e){let{options:t,...o}=Ot.parse(n);return{result:await new $e.HfInference(e.huggingface).zeroShotClassification(o,t)}}var U=require("zod"),Kt=U.z.object({image:U.z.string()}),Jo=U.z.object({labels:U.z.array(U.z.string())});async function Fe(n,e){let t=Kt.parse(n),o=`https://vision.googleapis.com/v1/images:annotate?key=${e.googleapis}`,r={requests:[{image:{content:t.image},features:[{type:"LABEL_DETECTION"}]}]};return{labels:(await(await fetch(o,{method:"POST",body:JSON.stringify(r)})).json()).responses[0].labelAnnotations.map(c=>c.description)}}var E=require("zod"),kt=E.z.object({prompt:E.z.string(),response_format:E.z.literal("b64_json").default("b64_json"),size:E.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),Vo=E.z.object({result:E.z.string()});async function We(n,e){let t=kt.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:a}=await r.json();return{result:a[0].b64_json}}var L=require("zod"),Ut=L.z.object({prompt:L.z.string(),size:L.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),Yo=L.z.object({url:L.z.string().url()});async function Je(n,e){let t=Ut.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:a}=await r.json();return{url:a[0].url}}var d=require("zod"),Lt=d.z.enum(["stable-diffusion-v1-5","stable-diffusion-512-v2-0","stable-diffusion-768-v2-0","stable-diffusion-512-v2-1","stable-diffusion-768-v2-1"]),Bt=d.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),$t=d.z.object({text_prompts:d.z.array(d.z.object({text:d.z.string(),weight:d.z.number().min(-1).max(1).default(1)})).refine(n=>n.length>0,"Must have at least one text prompt"),model:Lt.default("stable-diffusion-v1-5"),clip_guidance_preset:Bt.optional(),steps:d.z.number().min(0).max(150).optional(),sampler:d.z.enum(["DDIM","DDPM","K_DPMPP_2M","K_DPMPP_2S_ANCESTRAL","K_DPM_2","K_DPM_2_ANCESTRAL","K_EULER","K_EULER_ANCESTRAL","K_HEUN","K_LMS"]).optional(),cfg_scale:d.z.number().min(0).max(35).optional(),seed:d.z.number().min(0).optional(),height:d.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64"),width:d.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64")}),Xo=d.z.object({result:d.z.instanceof(ArrayBuffer)});async function qe(n,e){let t=$t.parse(n),o=`https://api.stability.ai/v1beta/generation/${t.model}/text-to-image`;return{result:await(await fetch(o,{headers:{"Content-Type":"application/json",Accept:"image/png",Authorization:e.stability},method:"POST",body:JSON.stringify(t)})).arrayBuffer()}}var W=require("zod"),Ht=W.z.object({text:W.z.string()}),er=W.z.object({text:W.z.string()});async function Ve(n){return{text:Ht.parse(n).text.replace(/\$context\..*?\..*?\$/gm,"").trim()}}var B=require("zod"),Ft=B.z.object({text:B.z.string(),amount:B.z.number().optional().default(8)}),nr=B.z.object({text:B.z.string()}),Wt={"Colonial-style home":"Colonial, traditional, classic, historical, timeless, elegant, regal, grand, spacious, architectural, wood-framed, brick-exterior, symmetrical, gabled roof, columns, portico, fireplace, formal, ornate, landscaped".split(", "),"High-end penthouse apartment":"Luxury, high-end, penthouse, apartment, upscale, contemporary, modern, stylish, designer, elite, high-rise, rooftop, panoramic, views, spacious, open-plan, top-floor, amenities, concierge, service, exclusive".split(", ")};function Jt(n){return Object.entries(Wt).map(([e,t])=>`Title: ${e}
var ne=Object.defineProperty;var dt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var gt=Object.prototype.hasOwnProperty;var ht=(n,e)=>{for(var t in e)ne(n,t,{get:e[t],enumerable:!0})},xt=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of yt(e))!gt.call(n,r)&&r!==t&&ne(n,r,{get:()=>e[r],enumerable:!(o=dt(e,r))||o.enumerable});return n};var St=n=>xt(ne({},"__esModule",{value:!0}),n);var ln={};ht(ln,{Pipeline:()=>W,audioClassification:()=>ye,automaticSpeechRecognition:()=>he,cleanContextVars:()=>Xe,conversational:()=>Se,createClient:()=>vt,dalleBase64TextToImage:()=>Ge,dalleUrlTextToImage:()=>Ye,enhanceWithKeywords:()=>Ze,featureExtraction:()=>Ie,fillMask:()=>we,googleImageLabeling:()=>Ve,googleTextToSpeech:()=>mt,gpt3Prediction:()=>nt,gpt3PredictionStream:()=>st,gpt3TurboPrediction:()=>ot,gpt3TurboPredictionStream:()=>at,gpt4Prediction:()=>pt,gpt4PredictionStream:()=>ct,hf:()=>le,imageClassification:()=>ve,imageSegmentation:()=>Te,objectDetection:()=>_e,output:()=>X,questionAnswer:()=>Re,replaceMultipleStrings:()=>et,replaceString:()=>tt,stabilityTextToImage:()=>Qe,stringToArrayBuffer:()=>ut,summarization:()=>Me,tableQuestionAnswer:()=>De,textClassification:()=>Ke,textGeneration:()=>Ue,textToImage:()=>Be,tokenClassification:()=>He,translation:()=>We,vercelEdgeFunction:()=>fn,vercelGenericEdge:()=>pe,whisperApi:()=>ft,zeroShotClassification:()=>qe});module.exports=St(ln);function ce(n){return new Promise(e=>setTimeout(e,n))}function Q(n,e){if(typeof n=="string")return o(n);return t({...n});function t(a){let i={};for(let c in a)i[c]=o(a[c]);return i}function o(a){if(Array.isArray(a))return a.map(p=>t(p));if(typeof a=="object"&&a!==null)return t(a);let i=a,c=oe(a);for(let p of c){let m=e[p.nodeId].output;if(m==null)continue;let f=m[p.property];if(f instanceof ArrayBuffer){i=f;continue}i=i?.replace(new RegExp(r(p.value)),f),i==="undefined"?i=void 0:i!==f&&i===f.toString()&&(i=f)}return i}function r(a){return a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}function oe(n){if(typeof n!="string")return[];let e=/\$context\.(\d+|input|memory|pipeline)\.(\w+)\$/g,t=n.matchAll(e),o=[];for(let r of t)o.push({value:r[0],nodeId:r[1],property:r[2]});return o}function F(n=16){let e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",o=t.length;for(let r=0;r<n;r++)e+=t.charAt(Math.floor(Math.random()*o));return e}function ue(n){let e={input:{input:n.input,output:n.input},memory:{input:n.memory,output:n.memory},pipeline:{input:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId},output:{pipelineInstanceId:n.pipelineInstanceId,userId:n.userId}}};return{pipelineInstanceId:n.pipelineInstanceId,input:n.input,output:{},values:e,memory:n.memory,userId:n.userId}}async function me(n,e){let{memoryToSave:t}=e;if(!t)return;let o=Q(t,n.values);for(let r in t)for(let a in o){let i=o[a];if(i instanceof ReadableStream){let c=oe(t[r]),[p,m]=i.tee();n.values[c[0].nodeId].output=p;let f=await bt(m);o[a]=f}}return o}function bt(n){return new Promise(async e=>{let t=n.getReader(),o=new TextDecoder,r=!1,a="";for(;!r;){let{value:i,done:c}=await t.read();r=c;let p=o.decode(i);a+=p}e(a)})}var It=2,Pt=350,W=class{constructor(e,t,o){this.conf=e;this.flow=t;this.apiKeys=o;this.onProgressListeners=new Map;this.onStartListeners=new Map;this.onFinishListeners=new Map;this.pipelineInstanceId=F(16);this.eventIndex=0;this.vercel={invoke:(e,t)=>this.invokeRemote(`/api/pipelines/${this.conf.id}`,e,{userId:t?.userId}),invokeStream:(e,t,o)=>this.invokeStream(`/api/pipelines/${this.conf.id}`,e,t,{userId:o?.userId})};this.listenToEvents()}async invoke(e,t){let o=await this.loadMemory(t?.userId),r=ue({input:e,pipelineInstanceId:t?.pipelineInstanceId??this.pipelineInstanceId,userId:t?.userId??"",memory:o});return await this.processPipeline(r),r.output}async saveMemory(e,t){let o=await t;!this.conf.memoryManager||!o||this.conf.memoryManager.saveMemory(this.getMemoryId(e.userId),o)}getMemoryId(e){return`${this.conf.id}${e?`-${e}`:""}`}loadMemory(e){return this.conf.memoryManager?this.conf.memoryManager.loadMemory(this.getMemoryId(e)):Promise.resolve(null)}invokeRemote(e,t,o){return fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:o?.userId??""})}).then(r=>r.json())}async invokeStream(e,t,o,r){let a=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({input:t,pipelineInstanceId:this.pipelineInstanceId,userId:r?.userId??""})});if(!a.ok)throw new Error(a.statusText);let i=a.body;if(!i)return;let c=i.getReader(),p=new TextDecoder,m=!1;for(;!m;){let{value:f,done:z}=await c.read();m=z;let H=p.decode(f);o(H)}}onProgress(e){let t=F();return this.onProgressListeners.set(t,e),()=>{this.onProgressListeners.delete(t)}}onStart(e){let t=F();return this.onStartListeners.set(t,e),()=>{this.onStartListeners.delete(t)}}onFinish(e){let t=F();return this.onFinishListeners.set(t,e),()=>{this.onFinishListeners.delete(t)}}async processPipeline(e){let t=this.conf.retries??It;try{let o=this.notifyEvent({type:"pipeline:start",context:e});if(this.conf.stream||await o,this.conf.validateInput){let i=this.conf.validateInput(e.input);if(!i.valid)throw new Error(i.message)}let r=this.flow.getNodes();for(let i=0;i<r.length;i++){let c=this.notifyEvent({type:"node:start",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await c;let p=0,m=!1;do{p++;try{let{action:z,input:H}=r[i],te=e.values[i]={input:null,output:null};te.input=Q(H,e.values),te.output=await z(te.input,this.apiKeys);let lt=me(e,r[i]);this.saveMemory(e,lt),m=!0}catch(z){if(p>t)throw z;await ce((this.conf.retryDelayInMs??Pt)*p)}}while(!m&&p<=t);let f=this.notifyEvent({type:"node:finish",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await f}e.output=e.values[r.length-1].output;let a=this.notifyEvent({type:"pipeline:finish",context:e,data:{output:e.output instanceof ReadableStream?"Stream":e.output}});return this.conf.stream||await a,e}catch(o){throw console.error(o),o}}listenToEvents(){!this.conf.updateProgress||typeof window>"u"||!this.conf.eventListener||this.conf.eventListener(this.pipelineInstanceId,e=>{e.pipelineId===this.conf.id&&(e.type==="node:start"||e.type==="node:finish"?this.triggerListeners(this.onProgressListeners,e):e.type==="pipeline:start"?this.triggerListeners(this.onStartListeners,e):e.type==="pipeline:finish"&&this.triggerListeners(this.onFinishListeners,e))})}triggerListeners(e,...t){for(let o of e.values())o(...t)}notifyEvent(e){if(!(!this.conf.updateProgress||!this.conf.eventPublisher))return this.conf.eventPublisher(e.context.pipelineInstanceId,{pipelineId:this.conf.id,eventIndex:this.eventIndex++,type:e.type,data:e.data})}};async function X(n){return n}var Z=class{constructor(e){this.nodes=e}node(e,t,o){let r=this.createDynamicPlaceholders("memory"),a=this.createDynamicPlaceholders("input"),i=this.createDynamicPlaceholders(this.nodes.length),c=this.nodes.length>0?this.nodes[this.nodes.length-1]:a,p="$context.pipeline.userId$",m={action:e,input:t({nodes:this.nodes,prev:c.output,input:a,memory:r,userId:p}),output:this.createDynamicPlaceholders(this.nodes.length),memoryToSave:o?o({nodes:this.nodes,prev:c.output,output:i,input:a,memory:r,userId:p}):null};return this.nodes.push(m),this}createDynamicPlaceholders(e){let t={},o={get:function(a,i){return`$context.${e}.${i}$`}};return new Proxy(t,o)}output(e,t){return this.node(X,e,t)}getNodes(){return this.nodes}};var wt=2,At=350,vt=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??wt,retryDelayInMs:t.retryDelayInMs??At,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new Z([]));return new W(o,r,e)}}}};var _=require("zod"),de=require("@huggingface/inference");var K=require("zod"),fe=require("@huggingface/inference");function le(n,e){return(t,o)=>{let r=new fe.HfInference(o.huggingface);return n(r).call(r,t,e)}}var s=K.z.object({retry_on_error:K.z.boolean().optional().default(!0),use_cache:K.z.boolean().optional().default(!0),use_gpu:K.z.boolean().optional(),wait_for_model:K.z.boolean().optional()}).optional();var jt=_.z.object({model:_.z.string(),data:_.z.instanceof(ArrayBuffer),options:s}),En=_.z.object({result:_.z.array(_.z.object({label:_.z.string(),score:_.z.number()}))});async function ye(n,e){let{options:t,...o}=jt.parse(n);return{result:await new de.HfInference(e.huggingface).audioClassification(o,t)}}var k=require("zod"),ge=require("@huggingface/inference");var Tt=k.z.object({model:k.z.string(),data:k.z.instanceof(ArrayBuffer),options:s}),Un=k.z.object({text:k.z.string()});async function he(n,e){let{options:t,...o}=Tt.parse(n),r=new ge.HfInference(e.huggingface),{text:a}=await r.automaticSpeechRecognition(o,t);return{text:a}}var u=require("zod"),xe=require("@huggingface/inference");var zt=u.z.object({model:u.z.string(),inputs:u.z.object({generated_responses:u.z.string().array().optional(),past_user_inputs:u.z.string().array().optional(),text:u.z.string()}),parameters:u.z.object({max_length:u.z.number().int().optional(),max_time:u.z.number().min(0).max(120).optional(),min_length:u.z.number().int().optional(),repetition_penalty:u.z.number().min(0).max(100).optional(),temperature:u.z.number().min(0).max(100).optional().default(1),top_k:u.z.number().int().optional(),top_p:u.z.number().optional()}).optional(),options:s}),$n=u.z.object({conversation:u.z.object({generated_responses:u.z.string().array(),past_user_inputs:u.z.string().array()}),generated_text:u.z.string(),warnings:u.z.string().array()});async function Se(n,e){let{options:t,...o}=zt.parse(n);return await new xe.HfInference(e.huggingface).conversational(o,t)}var I=require("zod"),be=require("@huggingface/inference");var _t=I.z.object({model:I.z.string(),inputs:I.z.record(I.z.string(),I.z.any()).or(I.z.record(I.z.string(),I.z.any()).array()),options:s}),Wn=I.z.object({result:I.z.array(I.z.number().or(I.z.number().array()))});async function Ie(n,e){let{options:t,...o}=_t.parse(n);return{result:await new be.HfInference(e.huggingface).featureExtraction(o,t)}}var v=require("zod"),Pe=require("@huggingface/inference");var Ct=v.z.object({model:v.z.string(),inputs:v.z.string(),options:s}),Vn=v.z.object({result:v.z.array(v.z.object({score:v.z.number(),sequence:v.z.string(),token:v.z.number(),token_str:v.z.string()}))});async function we(n,e){let{options:t,...o}=Ct.parse(n);return{result:await new Pe.HfInference(e.huggingface).fillMask(o,t)}}var C=require("zod"),Ae=require("@huggingface/inference");var Rt=C.z.object({model:C.z.string(),data:C.z.instanceof(ArrayBuffer),options:s}),Qn=C.z.object({result:C.z.array(C.z.object({label:C.z.string(),score:C.z.number()}))});async function ve(n,e){let{options:t,...o}=Rt.parse(n);return{result:await new Ae.HfInference(e.huggingface).imageClassification(o,t)}}var T=require("zod"),je=require("@huggingface/inference");var Nt=T.z.object({model:T.z.string(),data:T.z.instanceof(ArrayBuffer),options:s}),eo=T.z.object({result:T.z.array(T.z.object({label:T.z.string(),mask:T.z.string(),score:T.z.number()}))});async function Te(n,e){let{options:t,...o}=Nt.parse(n);return{result:await new je.HfInference(e.huggingface).imageSegmentation(o,t)}}var h=require("zod"),ze=require("@huggingface/inference");var Mt=h.z.object({model:h.z.string(),data:h.z.instanceof(ArrayBuffer),options:s}),oo=h.z.object({result:h.z.array(h.z.object({box:h.z.object({xmax:h.z.number(),xmin:h.z.number(),ymax:h.z.number(),ymin:h.z.number()}),label:h.z.string(),score:h.z.number()}))});async function _e(n,e){let{options:t,...o}=Mt.parse(n);return{result:await new ze.HfInference(e.huggingface).objectDetection(o,t)}}var j=require("zod"),Ce=require("@huggingface/inference");var Ot=j.z.object({model:j.z.string(),inputs:j.z.object({context:j.z.string(),question:j.z.string()}),options:s}),io=j.z.object({answer:j.z.string(),end:j.z.number(),score:j.z.number(),start:j.z.number()});async function Re(n,e){let{options:t,...o}=Ot.parse(n);return await new Ce.HfInference(e.huggingface).questionAnswer(o,t)}var x=require("zod"),Ne=require("@huggingface/inference");var Dt=x.z.object({model:x.z.string(),inputs:x.z.string(),parameters:x.z.object({max_length:x.z.number().int().optional(),max_time:x.z.number().min(0).max(120).optional(),min_length:x.z.number().int().optional(),repetition_penalty:x.z.number().min(0).max(100).optional(),temperature:x.z.number().min(0).max(100).optional().default(1),top_k:x.z.number().int().optional(),top_p:x.z.number().optional()}).optional(),options:s}),co=x.z.object({summary_text:x.z.string()});async function Me(n,e){let{options:t,...o}=Dt.parse(n),r=new Ne.HfInference(e.huggingface),{summary_text:a}=await r.summarization(o,t);return{summary_text:a}}var P=require("zod"),Oe=require("@huggingface/inference");var Et=P.z.object({model:P.z.string(),inputs:P.z.object({query:P.z.string(),table:P.z.record(P.z.string().array())}),options:s}),fo=P.z.object({aggregator:P.z.string(),answer:P.z.string(),cells:P.z.string().array(),coordinates:P.z.number().array().array()});async function De(n,e){let{options:t,...o}=Et.parse(n);return await new Oe.HfInference(e.huggingface).tableQuestionAnswer(o,t)}var R=require("zod"),Ee=require("@huggingface/inference");var Kt=R.z.object({model:R.z.string(),inputs:R.z.string(),options:s}),go=R.z.object({result:R.z.array(R.z.object({label:R.z.string(),score:R.z.number()}))});async function Ke(n,e){let{options:t,...o}=Kt.parse(n);return{result:await new Ee.HfInference(e.huggingface).textClassification(o,t)}}var d=require("zod"),ke=require("@huggingface/inference");var kt=d.z.object({model:d.z.string(),inputs:d.z.string(),parameters:d.z.object({do_sample:d.z.boolean().optional().default(!0),max_new_tokens:d.z.number().int().min(0).max(250).optional(),max_time:d.z.number().min(0).max(120).optional(),num_return_sequences:d.z.number().int().min(0).optional().default(1),repetition_penalty:d.z.number().min(0).max(100).optional(),return_full_text:d.z.boolean().optional().default(!0),temperature:d.z.number().min(0).max(100).optional().default(1),top_k:d.z.number().int().optional(),top_p:d.z.number().optional()}).optional(),options:s}),So=d.z.object({generated_text:d.z.string()});async function Ue(n,e){let{options:t,...o}=kt.parse(n),r=new ke.HfInference(e.huggingface),{generated_text:a}=await r.textGeneration(o,t);return{generated_text:a}}var D=require("zod"),Le=require("@huggingface/inference");var Ut=D.z.object({model:D.z.string(),inputs:D.z.string(),negative_prompt:D.z.string().optional(),options:s}),Po=D.z.object({result:D.z.instanceof(ArrayBuffer)});async function Be(n,e){let{options:t,...o}=Ut.parse(n);return{result:await new Le.HfInference(e.huggingface).textToImage(o,t)}}var S=require("zod"),$e=require("@huggingface/inference");var Lt=S.z.object({model:S.z.string(),inputs:S.z.string(),parameters:S.z.object({aggregation_strategy:S.z.enum(["none","simple","first","average","max"]).optional().default("simple")}).optional(),options:s}),vo=S.z.object({result:S.z.array(S.z.object({end:S.z.number(),entity_group:S.z.string(),score:S.z.number(),start:S.z.number(),word:S.z.string()}))});async function He(n,e){let{options:t,...o}=Lt.parse(n);return{result:await new $e.HfInference(e.huggingface).tokenClassification(o,t)}}var U=require("zod"),Fe=require("@huggingface/inference");var Bt=U.z.object({model:U.z.string(),inputs:U.z.string(),options:s}),zo=U.z.object({translation_text:U.z.string()});async function We(n,e){let{options:t,...o}=Bt.parse(n),r=new Fe.HfInference(e.huggingface),{translation_text:a}=await r.translation(o,t);return{translation_text:a}}var b=require("zod"),Je=require("@huggingface/inference");var $t=b.z.object({model:b.z.string(),inputs:b.z.string().or(b.z.string().array()),parameters:b.z.object({candidate_labels:b.z.string().array(),multi_label:b.z.boolean().optional()}),options:s}),Ro=b.z.object({result:b.z.array(b.z.object({labels:b.z.string().array(),scores:b.z.number().array(),sequence:b.z.string()}))});async function qe(n,e){let{options:t,...o}=$t.parse(n);return{result:await new Je.HfInference(e.huggingface).zeroShotClassification(o,t)}}var L=require("zod"),Ht=L.z.object({image:L.z.string()}),Xo=L.z.object({labels:L.z.array(L.z.string())});async function Ve(n,e){let t=Ht.parse(n),o=`https://vision.googleapis.com/v1/images:annotate?key=${e.googleapis}`,r={requests:[{image:{content:t.image},features:[{type:"LABEL_DETECTION"}]}]};return{labels:(await(await fetch(o,{method:"POST",body:JSON.stringify(r)})).json()).responses[0].labelAnnotations.map(c=>c.description)}}var E=require("zod"),Ft=E.z.object({prompt:E.z.string(),response_format:E.z.literal("b64_json").default("b64_json"),size:E.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),er=E.z.object({result:E.z.string()});async function Ge(n,e){let t=Ft.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:a}=await r.json();return{result:a[0].b64_json}}var B=require("zod"),Wt=B.z.object({prompt:B.z.string(),size:B.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),nr=B.z.object({url:B.z.string().url()});async function Ye(n,e){let t=Wt.parse(n),r=await fetch("https://api.openai.com/v1/images/generations",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)}),{data:a}=await r.json();return{url:a[0].url}}var y=require("zod"),Jt=y.z.enum(["stable-diffusion-v1-5","stable-diffusion-512-v2-0","stable-diffusion-768-v2-0","stable-diffusion-512-v2-1","stable-diffusion-768-v2-1"]),qt=y.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),Vt=y.z.object({text_prompts:y.z.array(y.z.object({text:y.z.string(),weight:y.z.number().min(-1).max(1).default(1)})).refine(n=>n.length>0,"Must have at least one text prompt"),model:Jt.default("stable-diffusion-v1-5"),clip_guidance_preset:qt.optional(),steps:y.z.number().min(0).max(150).optional(),sampler:y.z.enum(["DDIM","DDPM","K_DPMPP_2M","K_DPMPP_2S_ANCESTRAL","K_DPM_2","K_DPM_2_ANCESTRAL","K_EULER","K_EULER_ANCESTRAL","K_HEUN","K_LMS"]).optional(),cfg_scale:y.z.number().min(0).max(35).optional(),seed:y.z.number().min(0).optional(),height:y.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64"),width:y.z.number().min(128).optional().refine(n=>typeof n<"u"?n%64===0:!0,"Must be a multiple of 64")}),rr=y.z.object({result:y.z.instanceof(ArrayBuffer)});async function Qe(n,e){let t=Vt.parse(n),o=`https://api.stability.ai/v1beta/generation/${t.model}/text-to-image`;return{result:await(await fetch(o,{headers:{"Content-Type":"application/json",Accept:"image/png",Authorization:e.stability},method:"POST",body:JSON.stringify(t)})).arrayBuffer()}}var J=require("zod"),Gt=J.z.object({text:J.z.string()}),ir=J.z.object({text:J.z.string()});async function Xe(n){return{text:Gt.parse(n).text.replace(/\$context\..*?\..*?\$/gm,"").trim()}}var $=require("zod"),Yt=$.z.object({text:$.z.string(),amount:$.z.number().optional().default(8)}),pr=$.z.object({text:$.z.string()}),Qt={"Colonial-style home":"Colonial, traditional, classic, historical, timeless, elegant, regal, grand, spacious, architectural, wood-framed, brick-exterior, symmetrical, gabled roof, columns, portico, fireplace, formal, ornate, landscaped".split(", "),"High-end penthouse apartment":"Luxury, high-end, penthouse, apartment, upscale, contemporary, modern, stylish, designer, elite, high-rise, rooftop, panoramic, views, spacious, open-plan, top-floor, amenities, concierge, service, exclusive".split(", ")};function Xt(n){return Object.entries(Qt).map(([e,t])=>`Title: ${e}
Description: ${t.slice(0,n).join(", ")}
`).join(`
`)}async function Ge(n){let e=Ft.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following
${Jt(e.amount)}
`)}async function Ze(n){let e=Yt.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following
${Xt(e.amount)}
Title: ${e.text}
Description:`}}var N=require("zod"),qt=N.z.object({strings:N.z.record(N.z.string(),N.z.string()),modifier:N.z.string()}),rr=N.z.object({text:N.z.string()});async function Ye(n){let e=qt.parse(n);for(let t in e.strings)e.modifier=e.modifier.replace(new RegExp(`\\$\\(${t}\\)\\$`,"gm"),e.strings[t]);return{text:e.modifier}}var M=require("zod"),Vt=M.z.object({text:M.z.string().or(M.z.array(M.z.string())),modifier:M.z.string()}),ir=M.z.object({text:M.z.string()});async function Qe(n){let e=Vt.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var P=require("zod"),te=P.z.object({prompt:P.z.string(),model:P.z.enum(["text-davinci-003","text-curie-001","text-babbage-001","text-ada-001","code-davinci-002","code-cushman-002","gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:P.z.number().min(0).max(2).default(.7),top_p:P.z.number().min(0).max(1).default(1),frequency_penalty:P.z.number().min(-2).max(2).default(0),presence_penalty:P.z.number().min(-2).max(2).default(0),max_tokens:P.z.number().default(200),n:P.z.number().default(1)}).strict(),ne=n=>{if(n.model==="gpt-3.5-turbo"){let{prompt:e,...t}=n;return{...t,messages:[{role:"user",content:n.prompt}]}}return n},Gt=te.transform(n=>ne(n)),pr=P.z.object({text:P.z.string()});async function Xe(n,e){let t=Gt.parse(n),o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions",a=await(await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json();return{text:(t.model==="gpt-3.5-turbo"?a.choices[0]?.message.content:a.choices[0].text).replace(/^(?:\n)+/gm,"")}}var y=require("zod"),oe=y.z.object({messages:y.z.array(y.z.object({role:y.z.enum(["user","system","assistant"]),content:y.z.string()})).nonempty(),model:y.z.enum(["gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:y.z.number().min(0).max(2).default(.7),top_p:y.z.number().min(0).max(1).default(1),frequency_penalty:y.z.number().min(-2).max(2).default(0),presence_penalty:y.z.number().min(-2).max(2).default(0),max_tokens:y.z.number().default(200),n:y.z.number().default(1)}),ur=y.z.object({text:y.z.string()});async function Ze(n,e){let t=oe.parse(n);return{text:(await(await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json()).choices[0]?.message.content.replace(/^(?:\n)+/gm,"")}}var et=require("eventsource-parser"),J=require("zod");var Yt=oe.merge(J.z.object({stream:J.z.literal(!0).optional().default(!0)})),yr=J.z.object({stream:J.z.instanceof(globalThis.ReadableStream??Object)});async function tt(n,e){let t=Yt.parse(n),o=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await Qt(o)}}async function Qt(n){let e=new TextEncoder,t=new TextDecoder;return new ReadableStream({async start(r){function a(c){if(c.type==="event"){let p=c.data;if(p==="[DONE]"){r.close();return}try{let f=JSON.parse(p).choices[0]?.delta.content,T=e.encode(f);r.enqueue(T)}catch(m){r.error(m)}}}let i=(0,et.createParser)(a);for await(let c of n.body)i.feed(t.decode(c))}})}var nt=require("eventsource-parser"),q=require("zod");var Xt=te.merge(q.z.object({stream:q.z.literal(!0).optional().default(!0)})).strict(),Zt=Xt.transform(n=>ne(n)),br=q.z.object({stream:q.z.instanceof(globalThis.ReadableStream??Object)});async function ot(n,e){let t=Zt.parse(n),o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions",r=await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await en(t,r)}}async function en(n,e){let t=new TextEncoder,o=new TextDecoder;return new ReadableStream({async start(a){function i(p){if(p.type==="event"){let m=p.data;if(m==="[DONE]"){a.close();return}try{let f=JSON.parse(m),T=n.model==="gpt-3.5-turbo"?f.choices[0]?.delta.content:f.choices[0].text,$=t.encode(T);a.enqueue($)}catch(f){a.error(f)}}}let c=(0,nt.createParser)(i);for await(let p of e.body)c.feed(o.decode(p))}})}var V=require("zod"),tn=V.z.object({string:V.z.string()}),Pr=V.z.object({arrayBuffer:V.z.instanceof(ArrayBuffer)});async function rt(n){let e=tn.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var w=require("zod"),nn=w.z.object({text:w.z.string(),speakingRate:w.z.number().min(.25).max(4).optional().default(1),pitch:w.z.number().min(-20).max(20).optional().default(0),encoding:w.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:w.z.object({language:w.z.string().optional().default("en-US"),name:w.z.enum(["en-US-Standard-A","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J","en-US-Studio-M","en-US-Studio-O","en-US-Wavenet-A","en-US-Wavenet-B","en-US-Wavenet-C","en-US-Wavenet-D","en-US-Wavenet-E","en-US-Wavenet-F","en-US-Wavenet-G","en-US-Wavenet-H","en-US-Wavenet-I","en-US-Wavenet-J","en-US-News-K","en-US-News-L","en-US-News-M","en-US-News-N","en-US-Standard-A","en-US-Standard-B","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J"]).or(w.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),vr=w.z.object({audio:w.z.string()});async function at(n,e){let t=nn.parse(n),o=`https://us-central1-texttospeech.googleapis.com/v1beta1/text:synthesize?key=${e.googleapis}`,r={input:{text:t.text},voice:{languageCode:t.voice.language,name:t.voice.name},audioConfig:{audioEncoding:t.encoding,speakingRate:t.speakingRate,pitch:t.pitch}};return{audio:(await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).json()).audioContent}}var R=require("zod"),on="https://transcribe.whisperapi.com",rn=R.z.object({audioUrl:R.z.string().url(),language:R.z.string().default("en"),autoDetectLanguage:R.z.boolean().default(!1),fileType:R.z.string().default("mp3"),task:R.z.enum(["transcribe","translate"]).default("transcribe")}),jr=R.z.object({text:R.z.string()});async function it(n,e){let t=rn.parse(n),o=new FormData;o.append("url",t.audioUrl),t.autoDetectLanguage||o.append("language",t.language),o.append("fileType",t.fileType),o.append("task",t.task);let r=await fetch(on,{method:"POST",headers:{contentType:"application/json",Authorization:"Bearer "+e.whisperapi},body:o});if(!r.ok)throw new Error(r.statusText);return{text:(await r.json()).text.trim()}}async function re(n,e){let{pipelineInstanceId:t,userId:o,input:r}=await e.json(),{searchParams:a}=new URL(e.url);if(!a.has("id"))return new Response("Missing id",{status:400});let i=a.get("id"),c=n[i];return{output:await c.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:c}}function an(n){return async e=>{let t=await re(n,e);return t instanceof Response?t:t.pipeline.conf.stream&&t.output instanceof ReadableStream?new Response(t.output):new Response(JSON.stringify(t.output,null,2),{headers:{"content-type":"application/json;charset=UTF-8"}})}}0&&(module.exports={Pipeline,audioClassification,automaticSpeechRecognition,cleanContextVars,conversational,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,featureExtraction,fillMask,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,gpt3TurboPrediction,gpt3TurboPredictionStream,hf,imageClassification,imageSegmentation,objectDetection,output,questionAnswer,replaceMultipleStrings,replaceString,stabilityTextToImage,stringToArrayBuffer,summarization,tableQuestionAnswer,textClassification,textGeneration,textToImage,tokenClassification,translation,vercelEdgeFunction,vercelGenericEdge,whisperApi,zeroShotClassification});
Description:`}}var M=require("zod"),Zt=M.z.object({strings:M.z.record(M.z.string(),M.z.string()),modifier:M.z.string()}),ur=M.z.object({text:M.z.string()});async function et(n){let e=Zt.parse(n);for(let t in e.strings)e.modifier=e.modifier.replace(new RegExp(`\\$\\(${t}\\)\\$`,"gm"),e.strings[t]);return{text:e.modifier}}var O=require("zod"),en=O.z.object({text:O.z.string().or(O.z.array(O.z.string())),modifier:O.z.string()}),fr=O.z.object({text:O.z.string()});async function tt(n){let e=en.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var w=require("zod"),re=w.z.object({prompt:w.z.string(),model:w.z.enum(["text-davinci-003","text-curie-001","text-babbage-001","text-ada-001","code-davinci-002","code-cushman-002","gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:w.z.number().min(0).max(2).default(.7),top_p:w.z.number().min(0).max(1).default(1),frequency_penalty:w.z.number().min(-2).max(2).default(0),presence_penalty:w.z.number().min(-2).max(2).default(0),max_tokens:w.z.number().default(200),n:w.z.number().default(1)}).strict(),ae=n=>{if(n.model==="gpt-3.5-turbo"){let{prompt:e,...t}=n;return{...t,messages:[{role:"user",content:n.prompt}]}}return n},tn=re.transform(n=>ae(n)),dr=w.z.object({text:w.z.string()});async function nt(n,e){let t=tn.parse(n),o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions",a=await(await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json();return{text:(t.model==="gpt-3.5-turbo"?a.choices[0]?.message.content:a.choices[0].text).replace(/^(?:\n)+/gm,"")}}var g=require("zod"),ie=g.z.object({messages:g.z.array(g.z.object({role:g.z.enum(["user","system","assistant"]),content:g.z.string()})).nonempty(),model:g.z.enum(["gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:g.z.number().min(0).max(2).default(.7),top_p:g.z.number().min(0).max(1).default(1),frequency_penalty:g.z.number().min(-2).max(2).default(0),presence_penalty:g.z.number().min(-2).max(2).default(0),max_tokens:g.z.number().default(200),n:g.z.number().default(1)}),gr=g.z.object({text:g.z.string()});async function ot(n,e){let t=ie.parse(n);return{text:(await(await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json()).choices[0]?.message.content.replace(/^(?:\n)+/gm,"")}}var q=require("zod");var rt=require("eventsource-parser");async function ee(n){let e=new TextEncoder,t=new TextDecoder;return new ReadableStream({async start(r){function a(c){if(c.type==="event"){let p=c.data;if(p==="[DONE]"){r.close();return}try{let f=JSON.parse(p).choices[0]?.delta.content,z=e.encode(f);r.enqueue(z)}catch(m){r.error(m)}}}let i=(0,rt.createParser)(a);for await(let c of n.body)i.feed(t.decode(c))}})}var nn=ie.merge(q.z.object({stream:q.z.literal(!0).optional().default(!0)})),wr=q.z.object({stream:q.z.instanceof(globalThis.ReadableStream??Object)});async function at(n,e){let t=nn.parse(n),o=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await ee(o)}}var it=require("eventsource-parser"),V=require("zod");var on=re.merge(V.z.object({stream:V.z.literal(!0).optional().default(!0)})).strict(),rn=on.transform(n=>ae(n)),zr=V.z.object({stream:V.z.instanceof(globalThis.ReadableStream??Object)});async function st(n,e){let t=rn.parse(n),o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions",r=await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await an(t,r)}}async function an(n,e){let t=new TextEncoder,o=new TextDecoder;return new ReadableStream({async start(a){function i(p){if(p.type==="event"){let m=p.data;if(m==="[DONE]"){a.close();return}try{let f=JSON.parse(m),z=n.model==="gpt-3.5-turbo"?f.choices[0]?.delta.content:f.choices[0].text,H=t.encode(z);a.enqueue(H)}catch(f){a.error(f)}}}let c=(0,it.createParser)(i);for await(let p of e.body)c.feed(o.decode(p))}})}var l=require("zod"),se=l.z.object({messages:l.z.array(l.z.object({role:l.z.enum(["user","system","assistant"]).or(l.z.string()),content:l.z.string()})),model:l.z.enum(["gpt-4","gpt-4-32k"]).or(l.z.string()).default("gpt-4"),temperature:l.z.number().min(0).max(2).default(.7),top_p:l.z.number().min(0).max(1).default(1),frequency_penalty:l.z.number().min(-2).max(2).default(0),presence_penalty:l.z.number().min(-2).max(2).default(0),max_tokens:l.z.number().default(200),n:l.z.number().default(1)}).strict(),Cr=l.z.object({text:l.z.string()});async function pt(n,e){let t=se.parse(n),a=await(await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)})).json();return console.log("***output",a),{text:(a.choices[0]?.message.content).replace(/^(?:\n)+/gm,"")}}var G=require("zod");var sn=se.merge(G.z.object({stream:G.z.literal(!0).optional().default(!0)})),Or=G.z.object({stream:G.z.instanceof(globalThis.ReadableStream??Object)});async function ct(n,e){let t=sn.parse(n),o=await fetch("https://api.openai.com/v1/chat/completions",{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await ee(o)}}var Y=require("zod"),pn=Y.z.object({string:Y.z.string()}),Er=Y.z.object({arrayBuffer:Y.z.instanceof(ArrayBuffer)});async function ut(n){let e=pn.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var A=require("zod"),cn=A.z.object({text:A.z.string(),speakingRate:A.z.number().min(.25).max(4).optional().default(1),pitch:A.z.number().min(-20).max(20).optional().default(0),encoding:A.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:A.z.object({language:A.z.string().optional().default("en-US"),name:A.z.enum(["en-US-Standard-A","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J","en-US-Studio-M","en-US-Studio-O","en-US-Wavenet-A","en-US-Wavenet-B","en-US-Wavenet-C","en-US-Wavenet-D","en-US-Wavenet-E","en-US-Wavenet-F","en-US-Wavenet-G","en-US-Wavenet-H","en-US-Wavenet-I","en-US-Wavenet-J","en-US-News-K","en-US-News-L","en-US-News-M","en-US-News-N","en-US-Standard-A","en-US-Standard-B","en-US-Standard-C","en-US-Standard-D","en-US-Standard-E","en-US-Standard-F","en-US-Standard-G","en-US-Standard-H","en-US-Standard-I","en-US-Standard-J"]).or(A.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),kr=A.z.object({audio:A.z.string()});async function mt(n,e){let t=cn.parse(n),o=`https://us-central1-texttospeech.googleapis.com/v1beta1/text:synthesize?key=${e.googleapis}`,r={input:{text:t.text},voice:{languageCode:t.voice.language,name:t.voice.name},audioConfig:{audioEncoding:t.encoding,speakingRate:t.speakingRate,pitch:t.pitch}};return{audio:(await(await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).json()).audioContent}}var N=require("zod"),un="https://transcribe.whisperapi.com",mn=N.z.object({audioUrl:N.z.string().url(),language:N.z.string().default("en"),autoDetectLanguage:N.z.boolean().default(!1),fileType:N.z.string().default("mp3"),task:N.z.enum(["transcribe","translate"]).default("transcribe")}),Lr=N.z.object({text:N.z.string()});async function ft(n,e){let t=mn.parse(n),o=new FormData;o.append("url",t.audioUrl),t.autoDetectLanguage||o.append("language",t.language),o.append("fileType",t.fileType),o.append("task",t.task);let r=await fetch(un,{method:"POST",headers:{contentType:"application/json",Authorization:"Bearer "+e.whisperapi},body:o});if(!r.ok)throw new Error(r.statusText);return{text:(await r.json()).text.trim()}}async function pe(n,e){let{pipelineInstanceId:t,userId:o,input:r}=await e.json(),{searchParams:a}=new URL(e.url);if(!a.has("id"))return new Response("Missing id",{status:400});let i=a.get("id"),c=n[i];return{output:await c.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:c}}function fn(n){return async e=>{let t=await pe(n,e);return t instanceof Response?t:t.pipeline.conf.stream&&t.output instanceof ReadableStream?new Response(t.output):new Response(JSON.stringify(t.output,null,2),{headers:{"content-type":"application/json;charset=UTF-8"}})}}0&&(module.exports={Pipeline,audioClassification,automaticSpeechRecognition,cleanContextVars,conversational,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,featureExtraction,fillMask,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,gpt3TurboPrediction,gpt3TurboPredictionStream,gpt4Prediction,gpt4PredictionStream,hf,imageClassification,imageSegmentation,objectDetection,output,questionAnswer,replaceMultipleStrings,replaceString,stabilityTextToImage,stringToArrayBuffer,summarization,tableQuestionAnswer,textClassification,textGeneration,textToImage,tokenClassification,translation,vercelEdgeFunction,vercelGenericEdge,whisperApi,zeroShotClassification});
{
"name": "@aigur/client",
"version": "1.11.0",
"version": "1.12.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -15,4 +15,6 @@ export * from './huggingface';

export { gpt3PredictionStream } from './text/prediction/gpt3.stream';
export { gpt4Prediction } from './text/prediction/gpt4';
export { gpt4PredictionStream } from './text/prediction/gpt4.stream';
export { stringToArrayBuffer } from './transformation/stringToArrayBuffer';
export { googleTextToSpeech } from './voice/textToSpeech/googleTextToSpeech';
export { whisperApi } from './voice/transcribe/whisper/whisperapi';

@@ -1,8 +0,7 @@

import { createParser, ParsedEvent, ReconnectInterval } from 'eventsource-parser';
import { z } from 'zod';
import { OpenAIStream } from './openaiStream';
import { inputSchema as gpt3TurboBaseInputSchema } from './gpt3-turbo';
import type { APIKeys } from '../../../types';
export const inputSchema = gpt3TurboBaseInputSchema.merge(

@@ -36,36 +35,2 @@ z.object({

async function OpenAIStream(response: Response) {
const encoder = new TextEncoder();
const decoder = new TextDecoder();
const stream = new ReadableStream({
async start(controller) {
function onParse(event: ParsedEvent | ReconnectInterval) {
if (event.type === 'event') {
const data = event.data;
if (data === '[DONE]') {
controller.close();
return;
}
try {
const json = JSON.parse(data);
const text = json.choices[0]?.delta.content;
const queue = encoder.encode(text);
controller.enqueue(queue);
} catch (e) {
controller.error(e);
}
}
}
const parser = createParser(onParse);
for await (const chunk of response.body as any) {
parser.feed(decoder.decode(chunk));
}
},
});
return stream;
}
export const name = 'gpt3TurboPredictionStream';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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