MCPcopy Create free account
hub / github.com/Bytez-com/docs / generateCodeSnippets

Function generateCodeSnippets

docs/scripts/generatePages/index.js:227–295  ·  view source on GitHub ↗
(modelId, requestInput, requestInputHttp, params, stream)

Source from the content-addressed store, hash-verified

225}
226
227async function generateCodeSnippets(modelId, requestInput, requestInputHttp, params, stream) {
228 const js = formatIntoCodeSnippet(
229 JS_TEMPLATE,
230 params,
231 stream,
232 (sectionsAsString) => {
233 if (paramsExist(params)) {
234 return sectionsAsString;
235 }
236
237 const replacedString = sectionsAsString
238 .replace(
239 // notice how we're removing params
240 `const { error, output } = await model.run(input, params);`,
241 `const { error, output } = await model.run(input);`
242 )
243 // notice how we're removing params, this is for the streaming case
244 .replace(
245 `const readStream = await model.run(input, params, stream);`,
246 `const readStream = await model.run(input, stream);`
247 );
248
249 return replacedString;
250 },
251 [
252 { tokenId: `'$MODEL_ID'`, replaceWith: `'${modelId}'` },
253 { tokenId: `'$INPUT'`, replaceWith: JSON.stringify(requestInput, null, 2) },
254 { tokenId: `'$PARAMS_PAYLOAD'`, replaceWith: JSON.stringify(params, null, 2) },
255 ]
256 );
257
258 const py = formatIntoCodeSnippet(
259 PY_TEMPLATE,
260 params,
261 stream,
262 (sectionsAsString) => {
263 if (paramsExist(params)) {
264 return sectionsAsString;
265 }
266
267 const replacedString = sectionsAsString
268 .replace(
269 // notice how we're removing params
270 `result = model.run(input, params)`,
271 `result = model.run(input)`
272 )
273 // notice how we're removing params, this is for the streaming case
274 .replace(
275 `readStream = model.run(input, params, stream)`,
276 `readStream = model.run(input, stream=stream)`
277 );
278
279 return replacedString;
280 },
281 [
282 { tokenId: `"$MODEL_ID"`, replaceWith: `"${modelId}"` },
283 { tokenId: `"$INPUT"`, replaceWith: JSON.stringify(requestInput, null, 2) },
284 { tokenId: `"$PARAMS_PAYLOAD"`, replaceWith: JSON.stringify(params, null, 2) },

Callers 1

mainFunction · 0.85

Calls 3

formatIntoCodeSnippetFunction · 0.85
paramsExistFunction · 0.85
formatCurlFunction · 0.85

Tested by

no test coverage detected