Path: blob/master/src/packages/next/pages/api/v2/jupyter/execute.ts
5907 views
/*1Evaluation of code using a Jupyter kernel as a service.23The INPUT parameters are:45- kernel: the name of the Jupyter kernel6- history: list of previous inputs as string (in order) that were sent to the kernel.7- input: a new input89ALTERNATIVELY, can just give:1011- hash: hash of kernel/history/input1213and if output is known it is returned. Otherwise, nothing happens.14We are trusting that there aren't hash collisions for this applications,15since we're using a sha1 hash.1617The OUTPUT is:1819- a list of messages that describe the output of the last code execution.2021*/2223import type { Request, Response } from "express";2425import { execute } from "@cocalc/server/jupyter/execute";26import getAccountId from "lib/account/get-account";27import getParams from "lib/api/get-params";28import { getAnonymousID } from "lib/user-id";2930export default async function handle(req: Request, res: Response) {31try {32const result = await doIt(req);33res.json({ ...result, success: true });34} catch (err) {35res.json({ error: `${err.message}` });36return;37}38}3940async function doIt(req: Request) {41const { input, kernel, history, tag, noCache, hash, project_id, path } =42getParams(req);43const account_id = await getAccountId(req);44const anonymous_id = await getAnonymousID(req);45return await execute({46account_id,47project_id,48path,49anonymous_id,50input,51hash,52history,53kernel,54tag,55noCache,56});57}585960