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.6.0 to 1.6.1

6

CHANGELOG.md
# @aigur/client
## 1.6.1
### Patch Changes
- eee80567: remove excess log
## 1.6.0

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

2

dist/index.js

@@ -7,2 +7,2 @@ var C=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var ee=Object.prototype.hasOwnProperty;var te=(n,e)=>{for(var t in e)C(n,t,{get:e[t],enumerable:!0})},ne=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z(e))!ee.call(n,r)&&r!==t&&C(n,r,{get:()=>e[r],enumerable:!(o=Q(e,r))||o.enumerable});return n};var oe=n=>ne(C({},"__esModule",{value:!0}),n);var Be={};te(Be,{Pipeline:()=>T,cleanContextVars:()=>xe,createClient:()=>ue,dalleBase64TextToImage:()=>le,dalleUrlTextToImage:()=>ye,enhanceWithKeywords:()=>ve,googleImageLabeling:()=>de,googleTextToSpeech:()=>Le,gpt3Prediction:()=>J,gpt3PredictionStream:()=>Y,gpt3TurboPrediction:()=>V,gpt3TurboPredictionStream:()=>q,output:()=>z,replaceMultipleStrings:()=>Te,replaceString:()=>Ne,stabilityClipGuidancePreset:()=>W,stabilityModel:()=>F,stabilityTextToImage:()=>ge,stringToArrayBuffer:()=>ze,vercelEdgeFunction:()=>$e,vercelGenericEdge:()=>k,whisperApi:()=>Ke});module.exports=oe(Be);function D(n,e){if(typeof n=="string")return o(n);return t({...n});function t(a){let i={};for(let p in a)i[p]=o(a[p]);return i}function o(a){if(Array.isArray(a))return a.map(s=>t(s));if(typeof a=="object"&&a!==null)return t(a);let i=a,p=j(a);for(let s of p){let u=e[s.nodeId].output;if(u==null)continue;let c=u[s.property];if(c instanceof ArrayBuffer){i=c;continue}i=i?.replace(new RegExp(r(s.value)),c),i==="undefined"?i=void 0:i!==c&&i===c.toString()&&(i=c)}return i}function r(a){return a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}}function j(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}async function K(n,e){let{memoryToSave:t}=e;if(!t)return;let o=D(t,n.values);for(let r in t)for(let a in o){let i=o[a];if(i instanceof ReadableStream){let p=j(t[r]),[s,u]=i.tee();n.values[p[0].nodeId].output=s;let c=await re(u);o[a]=c}}return o}function re(n){return new Promise(async e=>{let t=n.getReader(),o=new TextDecoder,r=!1,a="";for(;!r;){let{value:i,done:p}=await t.read();r=p;let s=o.decode(i);a+=s}e(a)})}function $(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}}function w(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 B(n){return new Promise(e=>setTimeout(e,n))}var ae=2,ie=350,T=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=w(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=$({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 p=i.getReader(),s=new TextDecoder,u=!1;for(;!u;){let{value:c,done:y}=await p.read();u=y;let v=s.decode(c);o(v)}}onProgress(e){let t=w();return this.onProgressListeners.set(t,e),()=>{this.onProgressListeners.delete(t)}}onStart(e){let t=w();return this.onStartListeners.set(t,e),()=>{this.onStartListeners.delete(t)}}onFinish(e){let t=w();return this.onFinishListeners.set(t,e),()=>{this.onFinishListeners.delete(t)}}async processPipeline(e){let t=this.conf.retries??ae;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 p=this.notifyEvent({type:"node:start",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await p;let s=0,u=!1;do{s++;try{let{action:y,input:v}=r[i],E=e.values[i]={input:null,output:null};E.input=D(v,e.values),E.output=await y(E.input,this.apiKeys);let X=K(e,r[i]);this.saveMemory(e,X),u=!0}catch(y){if(s>t)throw y;await B((this.conf.retryDelayInMs??ie)*s)}}while(!u&&s<=t);let c=this.notifyEvent({type:"node:finish",context:e,data:{node:r[i].action.name,tag:r[i].tag??"",index:i}});this.conf.stream||await c}let a=this.notifyEvent({type:"pipeline:finish",context:e});return this.conf.stream||await a,e.output=e.values[r.length-1].output,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 z(n){return n}var O=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),p=this.nodes.length>0?this.nodes[this.nodes.length-1]:a,s="$context.pipeline.userId$",u={action:e,input:t({nodes:this.nodes,prev:p.output,input:a,memory:r,userId:s}),output:this.createDynamicPlaceholders(this.nodes.length),memoryToSave:o?o({nodes:this.nodes,prev:p.output,output:i,input:a,memory:r,userId:s}):null};return this.nodes.push(u),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(z,e,t)}getNodes(){return this.nodes}};var se=2,pe=350,ue=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??se,retryDelayInMs:t.retryDelayInMs??pe,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new O([]));return new T(o,r,e)}}}};var I=require("zod"),ce=I.z.object({image:I.z.string()}),pt=I.z.object({labels:I.z.array(I.z.string())});async function de(n,e){let t=ce.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(p=>p.description)}}var x=require("zod"),me=x.z.object({prompt:x.z.string(),response_format:x.z.literal("b64_json").default("b64_json"),size:x.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),ct=x.z.object({result:x.z.string()});async function le(n,e){let t=me.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"),fe=b.z.object({prompt:b.z.string(),size:b.z.enum(["256x256","512x512","1024x1024"]).default("512x512")}),mt=b.z.object({url:b.z.string().url()});async function ye(n,e){let t=fe.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"),F=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"]),W=d.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),he=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:F.default("stable-diffusion-v1-5"),clip_guidance_preset:W.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")}),ft=d.z.object({result:d.z.instanceof(ArrayBuffer)});async function ge(n,e){let t=he.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 A=require("zod"),Se=A.z.object({text:A.z.string()}),ht=A.z.object({text:A.z.string()});async function xe(n){return{text:Se.parse(n).text.replace(/\$context\..*?\..*?\$/gm,"").trim()}}var P=require("zod"),Ie=P.z.object({text:P.z.string(),amount:P.z.number().optional().default(8)}),St=P.z.object({text:P.z.string()}),be={"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 Pe(n){return Object.entries(be).map(([e,t])=>`Title: ${e}

Title: ${e.text}
Description:`}}var g=require("zod"),we=g.z.object({strings:g.z.record(g.z.string(),g.z.string()),modifier:g.z.string()}),It=g.z.object({text:g.z.string()});async function Te(n){let e=we.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 S=require("zod"),Ae=S.z.object({text:S.z.string().or(S.z.array(S.z.string())),modifier:S.z.string()}),Pt=S.z.object({text:S.z.string()});async function Ne(n){let e=Ae.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var l=require("zod"),U=l.z.object({prompt:l.z.string(),model:l.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: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(),L=n=>{if(n.model==="gpt-3.5-turbo"){let{prompt:e,...t}=n;return{...t,messages:[{role:"user",content:n.prompt}]}}return n},Re=U.transform(n=>L(n)),wt=l.z.object({text:l.z.string()});async function J(n,e){let t=Re.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 m=require("zod"),_=m.z.object({messages:m.z.array(m.z.object({role:m.z.enum(["user","system","assistant"]),content:m.z.string()})).nonempty(),model:m.z.enum(["gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:m.z.number().min(0).max(2).default(.7),top_p:m.z.number().min(0).max(1).default(1),frequency_penalty:m.z.number().min(-2).max(2).default(0),presence_penalty:m.z.number().min(-2).max(2).default(0),max_tokens:m.z.number().default(200),n:m.z.number().default(1)}),At=m.z.object({text:m.z.string()});async function V(n,e){let t=_.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 N=require("zod"),G=require("eventsource-parser");var Me=_.merge(N.z.object({stream:N.z.literal(!0).optional().default(!0)})),Ot=N.z.object({stream:N.z.instanceof(globalThis.ReadableStream??Object)});async function q(n,e){let t=Me.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 De(o)}}async function De(n){let e=new TextEncoder,t=new TextDecoder;return new ReadableStream({async start(r){function a(p){if(p.type==="event"){let s=p.data;if(s==="[DONE]"){r.close();return}try{let c=JSON.parse(s).choices[0]?.delta.content,y=e.encode(c);r.enqueue(y)}catch(u){r.error(u)}}}let i=(0,G.createParser)(a);for await(let p of n.body)i.feed(t.decode(p))}})}var R=require("zod"),H=require("eventsource-parser");var Oe=U.merge(R.z.object({stream:R.z.literal(!0).optional().default(!0)})).strict(),Ee=Oe.transform(n=>L(n)),Ut=R.z.object({stream:R.z.instanceof(globalThis.ReadableStream??Object)});async function Y(n,e){let t=Ee.parse(n);console.log("***payload",t);let o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions";console.log("***endpoint",o);let r=await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await Ce(t,r)}}async function Ce(n,e){let t=new TextEncoder,o=new TextDecoder;return new ReadableStream({async start(a){function i(s){if(s.type==="event"){let u=s.data;if(u==="[DONE]"){a.close();return}try{let c=JSON.parse(u),y=n.model==="gpt-3.5-turbo"?c.choices[0]?.delta.content:c.choices[0].text,v=t.encode(y);a.enqueue(v)}catch(c){a.error(c)}}}let p=(0,H.createParser)(i);for await(let s of e.body)p.feed(o.decode(s))}})}var M=require("zod"),je=M.z.object({string:M.z.string()}),_t=M.z.object({arrayBuffer:M.z.instanceof(ArrayBuffer)});async function ze(n){let e=je.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var f=require("zod"),Ue=f.z.object({text:f.z.string(),speakingRate:f.z.number().min(.25).max(4).optional().default(1),pitch:f.z.number().min(-20).max(20).optional().default(0),encoding:f.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:f.z.object({language:f.z.string().optional().default("en-US"),name:f.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(f.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),Kt=f.z.object({audio:f.z.string()});async function Le(n,e){let t=Ue.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 h=require("zod"),_e="https://transcribe.whisperapi.com",ke=h.z.object({audioUrl:h.z.string().url(),language:h.z.string().default("en"),autoDetectLanguage:h.z.boolean().default(!1),fileType:h.z.string().default("mp3"),task:h.z.enum(["transcribe","translate"]).default("transcribe")}),Bt=h.z.object({text:h.z.string()});async function Ke(n,e){let t=ke.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(_e,{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 k(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"),p=n[i];return{output:await p.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:p}}function $e(n){return async e=>{let t=await k(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,cleanContextVars,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,gpt3TurboPrediction,gpt3TurboPredictionStream,output,replaceMultipleStrings,replaceString,stabilityClipGuidancePreset,stabilityModel,stabilityTextToImage,stringToArrayBuffer,vercelEdgeFunction,vercelGenericEdge,whisperApi});
Description:`}}var g=require("zod"),we=g.z.object({strings:g.z.record(g.z.string(),g.z.string()),modifier:g.z.string()}),It=g.z.object({text:g.z.string()});async function Te(n){let e=we.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 S=require("zod"),Ae=S.z.object({text:S.z.string().or(S.z.array(S.z.string())),modifier:S.z.string()}),Pt=S.z.object({text:S.z.string()});async function Ne(n){let e=Ae.parse(n);return{text:e.modifier.replace(/\$\(text\)\$/gm,Array.isArray(e.text)?e.text.join(", "):e.text)}}var l=require("zod"),U=l.z.object({prompt:l.z.string(),model:l.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: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(),L=n=>{if(n.model==="gpt-3.5-turbo"){let{prompt:e,...t}=n;return{...t,messages:[{role:"user",content:n.prompt}]}}return n},Re=U.transform(n=>L(n)),wt=l.z.object({text:l.z.string()});async function J(n,e){let t=Re.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 m=require("zod"),_=m.z.object({messages:m.z.array(m.z.object({role:m.z.enum(["user","system","assistant"]),content:m.z.string()})).nonempty(),model:m.z.enum(["gpt-3.5-turbo"]).default("gpt-3.5-turbo"),temperature:m.z.number().min(0).max(2).default(.7),top_p:m.z.number().min(0).max(1).default(1),frequency_penalty:m.z.number().min(-2).max(2).default(0),presence_penalty:m.z.number().min(-2).max(2).default(0),max_tokens:m.z.number().default(200),n:m.z.number().default(1)}),At=m.z.object({text:m.z.string()});async function V(n,e){let t=_.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 N=require("zod"),G=require("eventsource-parser");var Me=_.merge(N.z.object({stream:N.z.literal(!0).optional().default(!0)})),Ot=N.z.object({stream:N.z.instanceof(globalThis.ReadableStream??Object)});async function q(n,e){let t=Me.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 De(o)}}async function De(n){let e=new TextEncoder,t=new TextDecoder;return new ReadableStream({async start(r){function a(p){if(p.type==="event"){let s=p.data;if(s==="[DONE]"){r.close();return}try{let c=JSON.parse(s).choices[0]?.delta.content,y=e.encode(c);r.enqueue(y)}catch(u){r.error(u)}}}let i=(0,G.createParser)(a);for await(let p of n.body)i.feed(t.decode(p))}})}var R=require("zod"),H=require("eventsource-parser");var Oe=U.merge(R.z.object({stream:R.z.literal(!0).optional().default(!0)})).strict(),Ee=Oe.transform(n=>L(n)),Ut=R.z.object({stream:R.z.instanceof(globalThis.ReadableStream??Object)});async function Y(n,e){let t=Ee.parse(n),o=t.model==="gpt-3.5-turbo"?"https://api.openai.com/v1/chat/completions":"https://api.openai.com/v1/completions";console.log("***endpoint",o);let r=await fetch(o,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.openai}`},method:"POST",body:JSON.stringify(t)});return{stream:await Ce(t,r)}}async function Ce(n,e){let t=new TextEncoder,o=new TextDecoder;return new ReadableStream({async start(a){function i(s){if(s.type==="event"){let u=s.data;if(u==="[DONE]"){a.close();return}try{let c=JSON.parse(u),y=n.model==="gpt-3.5-turbo"?c.choices[0]?.delta.content:c.choices[0].text,v=t.encode(y);a.enqueue(v)}catch(c){a.error(c)}}}let p=(0,H.createParser)(i);for await(let s of e.body)p.feed(o.decode(s))}})}var M=require("zod"),je=M.z.object({string:M.z.string()}),_t=M.z.object({arrayBuffer:M.z.instanceof(ArrayBuffer)});async function ze(n){let e=je.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var f=require("zod"),Ue=f.z.object({text:f.z.string(),speakingRate:f.z.number().min(.25).max(4).optional().default(1),pitch:f.z.number().min(-20).max(20).optional().default(0),encoding:f.z.enum(["MP3","FLAC","LINEAR16","MULAW","AMR","AMR_WB","OGG_OPUS","SPEEX_WITH_HEADER_BYTE","WEBM_OPUS"]).optional().default("MP3"),voice:f.z.object({language:f.z.string().optional().default("en-US"),name:f.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(f.z.string()).optional().default("en-US-Neural2-C")}).optional().default({language:"en-US",name:"en-US-Neural2-C"})}),Kt=f.z.object({audio:f.z.string()});async function Le(n,e){let t=Ue.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 h=require("zod"),_e="https://transcribe.whisperapi.com",ke=h.z.object({audioUrl:h.z.string().url(),language:h.z.string().default("en"),autoDetectLanguage:h.z.boolean().default(!1),fileType:h.z.string().default("mp3"),task:h.z.enum(["transcribe","translate"]).default("transcribe")}),Bt=h.z.object({text:h.z.string()});async function Ke(n,e){let t=ke.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(_e,{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 k(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"),p=n[i];return{output:await p.invoke(r,{pipelineInstanceId:t,userId:o}),pipeline:p}}function $e(n){return async e=>{let t=await k(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,cleanContextVars,createClient,dalleBase64TextToImage,dalleUrlTextToImage,enhanceWithKeywords,googleImageLabeling,googleTextToSpeech,gpt3Prediction,gpt3PredictionStream,gpt3TurboPrediction,gpt3TurboPredictionStream,output,replaceMultipleStrings,replaceString,stabilityClipGuidancePreset,stabilityModel,stabilityTextToImage,stringToArrayBuffer,vercelEdgeFunction,vercelGenericEdge,whisperApi});
{
"name": "@aigur/client",
"version": "1.6.0",
"version": "1.6.1",
"description": "",

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

@@ -29,3 +29,2 @@ import { z } from 'zod';

const payload = inputSchema.parse(input);
console.log(`***payload`, payload);
const endpoint =

@@ -32,0 +31,0 @@ payload.model === 'gpt-3.5-turbo'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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