| 173 | } |
| 174 | |
| 175 | function toAccordion({ |
| 176 | exampleTitle, |
| 177 | exampleDescription, |
| 178 | supportsUrlInput, |
| 179 | supportsBase64Input, |
| 180 | mediaInputType, |
| 181 | defaultOpen, |
| 182 | js, |
| 183 | py, |
| 184 | curl, |
| 185 | }) { |
| 186 | const codeGroupItems = []; |
| 187 | |
| 188 | for (const { snippet, renderAs, label } of [ |
| 189 | { snippet: js, renderAs: 'javascript', label: 'javascript' }, |
| 190 | { snippet: py, renderAs: 'python', label: 'python' }, |
| 191 | { snippet: curl, renderAs: 'bash', label: 'http' }, |
| 192 | ]) { |
| 193 | const codeGroupItem = ` |
| 194 | \`\`\`${renderAs} ${label} |
| 195 | ${snippet} |
| 196 | \`\`\` |
| 197 | `.trim(); |
| 198 | |
| 199 | codeGroupItems.push(codeGroupItem); |
| 200 | } |
| 201 | |
| 202 | const codeGroupsString = codeGroupItems.join('\n'); |
| 203 | |
| 204 | const shouldHaveBase64Details = supportsUrlInput && supportsBase64Input; |
| 205 | |
| 206 | const base64Details = ` |
| 207 | You can send the **${mediaInputType}** via \`url\` or \`base64\` data URL. |
| 208 | |
| 209 | We recommend \`url\` for better performance, as \`base64\` increases payload size. |
| 210 | `.trim(); |
| 211 | |
| 212 | const Accordion = new Component({ |
| 213 | name: 'Accordion', |
| 214 | props: { defaultOpen, title: exampleTitle }, |
| 215 | children: [ |
| 216 | exampleDescription, |
| 217 | new Component({ |
| 218 | name: 'CodeGroup', |
| 219 | children: [codeGroupsString, ...(shouldHaveBase64Details ? [base64Details] : [])], |
| 220 | }), |
| 221 | ], |
| 222 | }); |
| 223 | |
| 224 | return Accordion; |
| 225 | } |
| 226 | |
| 227 | async function generateCodeSnippets(modelId, requestInput, requestInputHttp, params, stream) { |
| 228 | const js = formatIntoCodeSnippet( |