(modelId, requestInput, requestInputHttp, params, stream)
| 225 | } |
| 226 | |
| 227 | async 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) }, |
no test coverage detected