UNPKG

genosdb

Version:

GenosDB (GDB): distributed graph database in real-time, peer-to-peer, scalable storage - efficient querying of complex relationships.

14 lines (11 loc) 1.4 kB
function C(c){const O=c.map;return c.map=async function(...A){const L=await O.call(this,...A),h=A.find((j)=>j&&typeof j==="object")||{},{prompt:b}=h;if(b)L.results=await w(L.results,b);return L},c}async function w(c,O){const A=c.map((b)=>b.value),L=` ${O} Strict rules: - Return a JSON array with the SAME structure as the input. - Each array element must be a modification of the corresponding input object. - Only modify fields INSIDE the \`value\` object. - DO NOT add, remove, or restructure external nodes like \`id\`, \`edges\`, or \`timestamp\`. - DO NOT include explanations or extra text. Return ONLY the JSON array with modified \`value\` objects. Input example: ${JSON.stringify(A)} `,h=await z(L);return console.log(h),c.map((b,j)=>{const k=Array.isArray(h)?h[j]:h;return{...b,value:{...b.value,...k||{}}}})}async function z(c){try{const A=await fetch("https://text.pollinations.ai/",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:[{role:"system",content:"You are an AI assistant specialized in processing structured data objects."},{role:"user",content:c}],model:"openai",seed:Math.floor(Math.random()*1000),jsonMode:!0})});if(!A.ok)throw new Error(`Pollinations API error: ${A.statusText}`);const L=await A.json();return L.data||L}catch(O){throw console.error("Error processing prompt with Pollinations API:",O.message),O}}export{C as withAI};