@aigur/client
Advanced tools
Comparing version 1.6.2 to 1.7.0
# @aigur/client | ||
## 1.7.0 | ||
### Minor Changes | ||
- f5490b7e: Export node input/output schemas | ||
## 1.6.2 | ||
@@ -4,0 +10,0 @@ |
@@ -154,3 +154,3 @@ import { z } from 'zod'; | ||
declare const inputSchema$d: z.ZodObject<{ | ||
declare const inputSchema$e: z.ZodObject<{ | ||
image: z.ZodString; | ||
@@ -162,3 +162,3 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare const outputSchema$d: z.ZodObject<{ | ||
declare const outputSchema$e: z.ZodObject<{ | ||
labels: z.ZodArray<z.ZodString, "many">; | ||
@@ -170,5 +170,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function googleImageLabeling(input: z.input<typeof inputSchema$d>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$d>>; | ||
declare function googleImageLabeling(input: z.input<typeof inputSchema$e>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$e>>; | ||
declare const inputSchema$c: z.ZodObject<{ | ||
declare const inputSchema$d: z.ZodObject<{ | ||
prompt: z.ZodString; | ||
@@ -186,3 +186,3 @@ response_format: z.ZodDefault<z.ZodLiteral<"b64_json">>; | ||
}>; | ||
declare const outputSchema$c: z.ZodObject<{ | ||
declare const outputSchema$d: z.ZodObject<{ | ||
result: z.ZodString; | ||
@@ -194,5 +194,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function dalleBase64TextToImage(input: z.input<typeof inputSchema$c>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$c>>; | ||
declare function dalleBase64TextToImage(input: z.input<typeof inputSchema$d>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$d>>; | ||
declare const inputSchema$b: z.ZodObject<{ | ||
declare const inputSchema$c: z.ZodObject<{ | ||
prompt: z.ZodString; | ||
@@ -207,3 +207,3 @@ size: z.ZodDefault<z.ZodEnum<["256x256", "512x512", "1024x1024"]>>; | ||
}>; | ||
declare const outputSchema$b: z.ZodObject<{ | ||
declare const outputSchema$c: z.ZodObject<{ | ||
url: z.ZodString; | ||
@@ -215,7 +215,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function dalleUrlTextToImage(input: z.input<typeof inputSchema$b>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$b>>; | ||
declare function dalleUrlTextToImage(input: z.input<typeof inputSchema$c>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$c>>; | ||
declare const stabilityModel: z.ZodEnum<["stable-diffusion-v1-5", "stable-diffusion-512-v2-0", "stable-diffusion-768-v2-0", "stable-diffusion-512-v2-1", "stable-diffusion-768-v2-1"]>; | ||
declare const stabilityClipGuidancePreset: z.ZodEnum<["NONE", "FAST_BLUE", "FAST_GREEN", "SIMPLE", "SLOW", "SLOWER", "SLOWEST"]>; | ||
declare const inputSchema$a: z.ZodObject<{ | ||
declare const inputSchema$b: z.ZodObject<{ | ||
text_prompts: z.ZodEffects<z.ZodArray<z.ZodObject<{ | ||
@@ -272,3 +270,3 @@ text: z.ZodString; | ||
}>; | ||
declare const outputSchema$a: z.ZodObject<{ | ||
declare const outputSchema$b: z.ZodObject<{ | ||
result: z.ZodType<ArrayBuffer, z.ZodTypeDef, ArrayBuffer>; | ||
@@ -280,7 +278,7 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function stabilityTextToImage(input: z.input<typeof inputSchema$a>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$a>>; | ||
declare function stabilityTextToImage(input: z.input<typeof inputSchema$b>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$b>>; | ||
declare function output<PipelineOutput extends Record<string, unknown> | ReadableStream>(input: PipelineOutput): Promise<PipelineOutput>; | ||
declare const inputSchema$9: z.ZodObject<{ | ||
declare const inputSchema$a: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -292,3 +290,3 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare const outputSchema$9: z.ZodObject<{ | ||
declare const outputSchema$a: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -300,5 +298,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function cleanContextVars(input: z.input<typeof inputSchema$9>): Promise<z.infer<typeof outputSchema$9>>; | ||
declare function cleanContextVars(input: z.input<typeof inputSchema$a>): Promise<z.infer<typeof outputSchema$a>>; | ||
declare const inputSchema$8: z.ZodObject<{ | ||
declare const inputSchema$9: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -313,3 +311,3 @@ amount: z.ZodDefault<z.ZodOptional<z.ZodNumber>>; | ||
}>; | ||
declare const outputSchema$8: z.ZodObject<{ | ||
declare const outputSchema$9: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -321,5 +319,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function enhanceWithKeywords(input: z.input<typeof inputSchema$8>): Promise<z.infer<typeof outputSchema$8>>; | ||
declare function enhanceWithKeywords(input: z.input<typeof inputSchema$9>): Promise<z.infer<typeof outputSchema$9>>; | ||
declare const inputSchema$7: z.ZodObject<{ | ||
declare const inputSchema$8: z.ZodObject<{ | ||
strings: z.ZodRecord<z.ZodString, z.ZodString>; | ||
@@ -334,3 +332,3 @@ modifier: z.ZodString; | ||
}>; | ||
declare const outputSchema$7: z.ZodObject<{ | ||
declare const outputSchema$8: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -342,5 +340,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function replaceMultipleStrings(input: z.input<typeof inputSchema$7>): Promise<z.infer<typeof outputSchema$7>>; | ||
declare function replaceMultipleStrings(input: z.input<typeof inputSchema$8>): Promise<z.infer<typeof outputSchema$8>>; | ||
declare const inputSchema$6: z.ZodObject<{ | ||
declare const inputSchema$7: z.ZodObject<{ | ||
text: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>; | ||
@@ -355,3 +353,3 @@ modifier: z.ZodString; | ||
}>; | ||
declare const outputSchema$6: z.ZodObject<{ | ||
declare const outputSchema$7: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -363,5 +361,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function replaceString(input: z.input<typeof inputSchema$6>): Promise<z.infer<typeof outputSchema$6>>; | ||
declare function replaceString(input: z.input<typeof inputSchema$7>): Promise<z.infer<typeof outputSchema$7>>; | ||
declare const inputSchema$5: z.ZodEffects<z.ZodObject<{ | ||
declare const inputSchema$6: z.ZodEffects<z.ZodObject<{ | ||
prompt: z.ZodString; | ||
@@ -426,3 +424,3 @@ model: z.ZodDefault<z.ZodEnum<["text-davinci-003", "text-curie-001", "text-babbage-001", "text-ada-001", "code-davinci-002", "code-cushman-002", "gpt-3.5-turbo"]>>; | ||
}>; | ||
declare const outputSchema$5: z.ZodObject<{ | ||
declare const outputSchema$6: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -434,5 +432,5 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function gpt3Prediction(input: z.input<typeof inputSchema$5>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$5>>; | ||
declare function gpt3Prediction(input: z.input<typeof inputSchema$6>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$6>>; | ||
declare const gpt3TurboInputSchema: z.ZodObject<{ | ||
declare const inputSchema$5: z.ZodObject<{ | ||
messages: z.ZodArray<z.ZodObject<{ | ||
@@ -486,3 +484,3 @@ role: z.ZodEnum<["user", "system", "assistant"]>; | ||
}>; | ||
declare const gpt3TurboOutputSchema: z.ZodObject<{ | ||
declare const outputSchema$5: z.ZodObject<{ | ||
text: z.ZodString; | ||
@@ -494,3 +492,3 @@ }, "strip", z.ZodTypeAny, { | ||
}>; | ||
declare function gpt3TurboPrediction(input: z.input<typeof gpt3TurboInputSchema>, apiKeys: APIKeys): Promise<z.infer<typeof gpt3TurboOutputSchema>>; | ||
declare function gpt3TurboPrediction(input: z.input<typeof inputSchema$5>, apiKeys: APIKeys): Promise<z.infer<typeof outputSchema$5>>; | ||
@@ -727,2 +725,2 @@ declare const inputSchema$4: z.ZodObject<z.extendShape<{ | ||
export { Aigur, Pipeline, cleanContextVars, createClient, dalleBase64TextToImage, dalleUrlTextToImage, enhanceWithKeywords, googleImageLabeling, googleTextToSpeech, gpt3Prediction, gpt3PredictionStream, gpt3TurboPrediction, gpt3TurboPredictionStream, output, replaceMultipleStrings, replaceString, stabilityClipGuidancePreset, stabilityModel, stabilityTextToImage, stringToArrayBuffer, vercelEdgeFunction, vercelGenericEdge, whisperApi }; | ||
export { Aigur, Pipeline, cleanContextVars, createClient, dalleBase64TextToImage, dalleUrlTextToImage, enhanceWithKeywords, googleImageLabeling, googleTextToSpeech, gpt3Prediction, gpt3PredictionStream, gpt3TurboPrediction, gpt3TurboPredictionStream, output, replaceMultipleStrings, replaceString, stabilityTextToImage, stringToArrayBuffer, vercelEdgeFunction, vercelGenericEdge, whisperApi }; |
@@ -1,7 +0,7 @@ | ||
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} | ||
var j=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var ce=(n,e)=>{for(var t in e)j(n,t,{get:e[t],enumerable:!0})},de=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!ue.call(n,r)&&r!==t&&j(n,r,{get:()=>e[r],enumerable:!(o=se(e,r))||o.enumerable});return n};var me=n=>de(j({},"__esModule",{value:!0}),n);var Be={};ce(Be,{Pipeline:()=>T,cleanContextVars:()=>G,createClient:()=>Se,dalleBase64TextToImage:()=>F,dalleUrlTextToImage:()=>J,enhanceWithKeywords:()=>q,googleImageLabeling:()=>W,googleTextToSpeech:()=>re,gpt3Prediction:()=>X,gpt3PredictionStream:()=>ne,gpt3TurboPrediction:()=>Q,gpt3TurboPredictionStream:()=>ee,output:()=>E,replaceMultipleStrings:()=>H,replaceString:()=>Y,stabilityTextToImage:()=>V,stringToArrayBuffer:()=>oe,vercelEdgeFunction:()=>$e,vercelGenericEdge:()=>k,whisperApi:()=>ae});module.exports=me(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=z(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 z(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=z(t[r]),[s,u]=i.tee();n.values[p[0].nodeId].output=s;let c=await le(u);o[a]=c}}return o}function le(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 fe=2,ye=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??fe;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],C=e.values[i]={input:null,output:null};C.input=D(v,e.values),C.output=await y(C.input,this.apiKeys);let ie=K(e,r[i]);this.saveMemory(e,ie),u=!0}catch(y){if(s>t)throw y;await B((this.conf.retryDelayInMs??ye)*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 E(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(E,e,t)}getNodes(){return this.nodes}};var he=2,ge=350,Se=n=>{let{apiKeys:e}=n;return{apiKeys:e,pipeline:{create:t=>{let o={...t,memoryManager:n.memoryManager,retries:t.retries??he,retryDelayInMs:t.retryDelayInMs??ge,eventListener:n.eventListener,eventPublisher:n.eventPublisher},r=t.flow(new O([]));return new T(o,r,e)}}}};var I=require("zod"),xe=I.z.object({image:I.z.string()}),pt=I.z.object({labels:I.z.array(I.z.string())});async function W(n,e){let t=xe.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"),Ie=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 F(n,e){let t=Ie.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"),be=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 J(n,e){let t=be.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"),Pe=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"]),ve=d.z.enum(["NONE","FAST_BLUE","FAST_GREEN","SIMPLE","SLOW","SLOWER","SLOWEST"]),we=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:Pe.default("stable-diffusion-v1-5"),clip_guidance_preset:ve.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 V(n,e){let t=we.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"),Te=A.z.object({text:A.z.string()}),ht=A.z.object({text:A.z.string()});async function G(n){return{text:Te.parse(n).text.replace(/\$context\..*?\..*?\$/gm,"").trim()}}var P=require("zod"),Ae=P.z.object({text:P.z.string(),amount:P.z.number().optional().default(8)}),St=P.z.object({text:P.z.string()}),Ne={"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 Re(n){return Object.entries(Ne).map(([e,t])=>`Title: ${e} | ||
Description: ${t.slice(0,n).join(", ")} | ||
`).join(` | ||
`)}async function ve(n){let e=Ie.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following | ||
${Pe(e.amount)} | ||
`)}async function q(n){let e=Ae.parse(n);return{text:`Write a maximum of ${e.amount} keywords in a csv list that describes the following | ||
${Re(e.amount)} | ||
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),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 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"),Me=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 H(n){let e=Me.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"),De=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 Y(n){let e=De.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},Ee=U.transform(n=>L(n)),wt=l.z.object({text:l.z.string()});async function X(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",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 Q(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"),Z=require("eventsource-parser");var Oe=_.merge(N.z.object({stream:N.z.literal(!0).optional().default(!0)})),Et=N.z.object({stream:N.z.instanceof(globalThis.ReadableStream??Object)});async function ee(n,e){let t=Oe.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 Ce(o)}}async function Ce(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,Z.createParser)(a);for await(let p of n.body)i.feed(t.decode(p))}})}var R=require("zod"),te=require("eventsource-parser");var je=U.merge(R.z.object({stream:R.z.literal(!0).optional().default(!0)})).strict(),ze=je.transform(n=>L(n)),Ut=R.z.object({stream:R.z.instanceof(globalThis.ReadableStream??Object)});async function ne(n,e){let t=ze.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 Ue(t,r)}}async function Ue(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,te.createParser)(i);for await(let s of e.body)p.feed(o.decode(s))}})}var M=require("zod"),Le=M.z.object({string:M.z.string()}),_t=M.z.object({arrayBuffer:M.z.instanceof(ArrayBuffer)});async function oe(n){let e=Le.parse(n);return{arrayBuffer:Uint8Array.from(atob(e.string),o=>o.charCodeAt(0)).buffer}}var f=require("zod"),_e=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 re(n,e){let t=_e.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"),ke="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 ae(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(ke,{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,stabilityTextToImage,stringToArrayBuffer,vercelEdgeFunction,vercelGenericEdge,whisperApi}); |
{ | ||
"name": "@aigur/client", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -5,7 +5,7 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
image: z.string(), // base64 | ||
}); | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
labels: z.array(z.string()), | ||
@@ -12,0 +12,0 @@ }); |
@@ -5,3 +5,3 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
prompt: z.string(), | ||
@@ -12,3 +12,3 @@ response_format: z.literal('b64_json').default('b64_json'), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
result: z.string(), | ||
@@ -15,0 +15,0 @@ }); |
@@ -5,3 +5,3 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
prompt: z.string(), | ||
@@ -12,3 +12,3 @@ // response_format: z.enum(['b64_json', 'url']).default('b64_json'), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
url: z.string().url(), | ||
@@ -15,0 +15,0 @@ }); |
@@ -23,3 +23,3 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
text_prompts: z | ||
@@ -72,3 +72,3 @@ .array( | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
result: z.instanceof(ArrayBuffer), | ||
@@ -75,0 +75,0 @@ }); |
@@ -1,10 +0,10 @@ | ||
export * from './image/labeling/googleImageLabeling'; | ||
export * from './image/textToImage/dalleBase64'; | ||
export * from './image/textToImage/dalleUrl'; | ||
export * from './image/textToImage/stability'; | ||
export * from './output/output'; | ||
export * from './text/modify/cleanContextVars'; | ||
export * from './text/modify/enhanceWithKeywords'; | ||
export * from './text/modify/replaceMultipleStrings'; | ||
export * from './text/modify/replaceString'; | ||
export { googleImageLabeling } from './image/labeling/googleImageLabeling'; | ||
export { dalleBase64TextToImage } from './image/textToImage/dalleBase64'; | ||
export { dalleUrlTextToImage } from './image/textToImage/dalleUrl'; | ||
export { stabilityTextToImage } from './image/textToImage/stability'; | ||
export { output } from './output/output'; | ||
export { cleanContextVars } from './text/modify/cleanContextVars'; | ||
export { enhanceWithKeywords } from './text/modify/enhanceWithKeywords'; | ||
export { replaceMultipleStrings } from './text/modify/replaceMultipleStrings'; | ||
export { replaceString } from './text/modify/replaceString'; | ||
export { gpt3Prediction } from './text/prediction/gpt3'; | ||
@@ -14,4 +14,4 @@ export { gpt3TurboPrediction } from './text/prediction/gpt3-turbo'; | ||
export { gpt3PredictionStream } from './text/prediction/gpt3.stream'; | ||
export * from './transformation/stringToArrayBuffer'; | ||
export * from './voice/textToSpeech/googleTextToSpeech'; | ||
export * from './voice/transcribe/whisper/whisperapi'; | ||
export { stringToArrayBuffer } from './transformation/stringToArrayBuffer'; | ||
export { googleTextToSpeech } from './voice/textToSpeech/googleTextToSpeech'; | ||
export { whisperApi } from './voice/transcribe/whisper/whisperapi'; |
import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
text: z.string(), | ||
}); | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -9,0 +9,0 @@ }); |
import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
text: z.string(), | ||
@@ -8,3 +8,3 @@ amount: z.number().optional().default(8), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -11,0 +11,0 @@ }); |
import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
strings: z.record(z.string(), z.string()), | ||
@@ -8,3 +8,3 @@ modifier: z.string(), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -11,0 +11,0 @@ }); |
import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
text: z.string().or(z.array(z.string())), | ||
@@ -8,3 +8,3 @@ modifier: z.string(), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -11,0 +11,0 @@ }); |
import { z } from 'zod'; | ||
import { createParser, ParsedEvent, ReconnectInterval } from 'eventsource-parser'; | ||
import { gpt3TurboInputSchema as gpt3TurboBaseInputSchema } from './gpt3-turbo'; | ||
import { inputSchema as gpt3TurboBaseInputSchema } from './gpt3-turbo'; | ||
import type { APIKeys } from '../../../types'; | ||
const inputSchema = gpt3TurboBaseInputSchema.merge( | ||
export const inputSchema = gpt3TurboBaseInputSchema.merge( | ||
z.object({ | ||
@@ -9,0 +10,0 @@ stream: z.literal(true).optional().default(true), |
@@ -5,3 +5,3 @@ import { z } from 'zod'; | ||
export const gpt3TurboInputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
messages: z | ||
@@ -24,3 +24,3 @@ .array( | ||
export const gpt3TurboOutputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -30,6 +30,6 @@ }); | ||
export async function gpt3TurboPrediction( | ||
input: z.input<typeof gpt3TurboInputSchema>, | ||
input: z.input<typeof inputSchema>, | ||
apiKeys: APIKeys | ||
): Promise<z.infer<typeof gpt3TurboOutputSchema>> { | ||
const payload = gpt3TurboInputSchema.parse(input); | ||
): Promise<z.infer<typeof outputSchema>> { | ||
const payload = inputSchema.parse(input); | ||
const response = await fetch('https://api.openai.com/v1/chat/completions', { | ||
@@ -36,0 +36,0 @@ headers: { |
@@ -16,7 +16,7 @@ import { z } from 'zod'; | ||
const inputSchema = rawIinputSchema.transform((val) => | ||
export const inputSchema = rawIinputSchema.transform((val) => | ||
turboTransformer<z.input<typeof gpt3BaseInputSchema>>(val) | ||
); | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
stream: z.instanceof(globalThis.ReadableStream ?? Object), | ||
@@ -23,0 +23,0 @@ }); |
@@ -47,3 +47,3 @@ import { z } from 'zod'; | ||
const inputSchema = rawInputSchema.transform((val) => | ||
export const inputSchema = rawInputSchema.transform((val) => | ||
turboTransformer<z.input<typeof rawInputSchema>>(val) | ||
@@ -50,0 +50,0 @@ ); |
import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
string: z.string(), // base64 | ||
}); | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
arrayBuffer: z.instanceof(ArrayBuffer), | ||
@@ -9,0 +9,0 @@ }); |
@@ -5,3 +5,3 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
text: z.string(), | ||
@@ -76,3 +76,3 @@ speakingRate: z.number().min(0.25).max(4).optional().default(1), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
audio: z.string(), // base64 | ||
@@ -79,0 +79,0 @@ }); |
@@ -7,3 +7,3 @@ import { z } from 'zod'; | ||
const inputSchema = z.object({ | ||
export const inputSchema = z.object({ | ||
audioUrl: z.string().url(), | ||
@@ -16,3 +16,3 @@ language: z.string().default('en'), | ||
const outputSchema = z.object({ | ||
export const outputSchema = z.object({ | ||
text: z.string(), | ||
@@ -19,0 +19,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97397
2269