Skip to content

Commit

Permalink
Add explanations-start async api.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneenders committed Sep 1, 2024
1 parent 2b625dd commit bf8dce5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions infra/testApi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const costStartData = await testAsyncAPI("cost-start", costBody)
assertIdAndPath(costStartData)
assert.equal(costStartData.cost > 0, true)

const explainStartData = await testAsyncAPI("explanations-start",localErrorBody)
assertIdAndPath(explainStartData)
assert.equal(explainStartData.explanation.length > 0, true, 'explanation should not be empty');

// --------------------------------------
// END ASYNC APIS
// --------------------------------------
Expand Down
19 changes: 19 additions & 0 deletions src/api/demo.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
[("api" "mathjs") #:method "post" ->mathjs-endpoint]
[("api" "translate") #:method "post" translate-endpoint]
[("api" "explanations") #:method "post" explanations-endpoint]
[("api" "explanations-start") #:method "post" explanations-start-endpoint]
[((hash-arg) (string-arg)) generate-page]
[("results.json") generate-report]))

Expand Down Expand Up @@ -435,6 +436,24 @@
(define id (start-job command))
(wait-for-job id))))

(define explanations-start-endpoint
(post-with-json-response (lambda (post-data)
(define formula-str (hash-ref post-data 'formula))
(define formula (read-syntax 'web (open-input-string formula-str)))
(define sample (hash-ref post-data 'sample))
(define seed (hash-ref post-data 'seed #f))
(define test (parse-test formula))
(define pcontext (json->pcontext sample (test-context test)))
(define command
(create-job 'explanations
test
#:seed seed
#:pcontext pcontext
#:profile? #f
#:timeline-disabled? #t))
(define job-id (start-job command))
(hasheq 'job job-id 'path (make-path job-id)))))

(define analyze-endpoint
(post-with-json-response (lambda (post-data)
(define formula-str (hash-ref post-data 'formula))
Expand Down

0 comments on commit bf8dce5

Please sign in to comment.