{"flow":{"id":47,"summary":"Insert zendesk articles into supabase with openaiembedings","versions":[184,185],"created_by":"sindre svendby964","created_at":"2023-06-19T13:50:02.646Z","votes":0,"approved":false,"apps":["openai","zendesk","supabase"],"value":{"modules":[{"id":"e","value":{"path":"f/zendesk/getAllArticles","type":"script","input_transforms":{"baseUrl":{"expr":"flow_input.zenDeskBaseUrl","type":"javascript"},"zenAuth":{"expr":"flow_input.zenAuth","type":"javascript"}}},"cache_ttl":10800},{"id":"b","value":{"type":"forloopflow","modules":[{"id":"c","retry":{"constant":{"seconds":0,"attempts":0},"exponential":{"seconds":0,"attempts":0,"multiplier":1}},"value":{"path":"hub/858/openai/create_embedding","type":"rawscript","content":"import type { Resource } from \"https://deno.land/x/windmill@v1.85.0/mod.ts\";\nimport { Configuration, OpenAIApi } from \"npm:openai@3.1.0\";\n\nexport async function main(\n  auth: Resource<\"openai\">,\n  prompt: string,\n  model: string = \"text-embedding-ada-002\",\n) {\n  const configuration = new Configuration({\n    apiKey: auth.api_key,\n    organization: auth.organization_id,\n  });\n  const openai = new OpenAIApi(configuration);\n\n  try {\n    const response = await openai.createEmbedding({\n      model,\n      input: prompt\n    });\n\n    const [{ embedding }] = response.data.data;\n    return embedding;\n  } catch (error) {\n    if (error.response) {\n      console.log(error.response.status);\n      console.log(error.response.data);\n    } else {\n      console.log(error.message);\n    }\n    throw error;\n  }\n}\n","language":"deno","input_transforms":{"auth":{"expr":"flow_input.openai","type":"javascript"},"model":{"type":"static","value":"text-embedding-ada-002"},"prompt":{"expr":"`${flow_input.iter.value.content}`","type":"javascript"}}},"summary":"Create Embedding","cache_ttl":604800},{"id":"d","value":{"path":"hub/944/supabase/insert_data","type":"rawscript","content":"import { Resource } from \"https://deno.land/x/windmill@v1.85.0/mod.ts\";\nimport { createClient } from \"npm:@supabase/supabase-js\";\n\n\nexport async function main(\n  auth: Resource<\"supabase\">,\n  embedding: any,\n  document: string,\n  link: string,\n) {\n  const supabase = createClient(\n    auth.supabaseUrl,\n    auth.supabaseKey,\n    { auth: { persistSession: false } },\n  );\n\n  return await supabase.from(\"documents\").insert({\n    content: document,\n    embedding,\n    link,\n  });\n}","language":"deno","input_transforms":{"auth":{"expr":"flow_input.supabase","type":"javascript"},"link":{"expr":"`${flow_input.iter.value.link}`","type":"javascript"},"document":{"expr":"`${flow_input.iter.value.content}`","type":"javascript"},"embedding":{"expr":"results.c","type":"javascript"}}},"summary":"Insert data on Supabase"}],"iterator":{"expr":"results.e","type":"javascript"},"parallel":false,"skip_failures":true}}]},"schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["zenAuth","zenDeskBaseUrl","supabase","openai"],"properties":{"openai":{"type":"object","format":"resource-openai","default":"","description":""},"zenAuth":{"type":"object","format":"resource-zendesk","default":"","description":"Resource<\"zendesk\">"},"supabase":{"type":"object","format":"resource-supabase","default":"","description":""},"zenDeskBaseUrl":{"type":"string","format":"uri","default":"","description":"https://example.zendesk.com where example is your subdomain for zendesk"}}},"description":"This workflow automates the process of extracting articles from Zendesk, creating text embeddings, and saving these along with the original text to a database.\n\nThe workflow is broken down into two main modules:\n\n1. The first module uses the Zendesk API to retrieve articles (in .htnl format) from the your workspace, and then strips out any html tags.\n\n2. The second module operates in a loop for each of the extracted documentation files. It utilizes OpenAI's text-embedding model to create embeddings of the text and then stores these embeddings, along with the original text content and its link, into a Supabase database.\n\nThis is useful for creating a semantic search functionality in a web application or software documentation site. The text embeddings can be used to find the most relevant documents based on semantic similarity to a query.","recording":null,"vcreated_at":"2023-06-19T13:50:40.821Z","vcreated_by":"sindre svendby964","comments":[]}}