Skip to content

Latest commit

 

History

History
365 lines (237 loc) · 5.5 KB

Web API.md

File metadata and controls

365 lines (237 loc) · 5.5 KB

Web API

This document outlines the endpoints that are available when running gactar as a web server (i.e. by passing -w on the command line).

Important Note: The web API is intended for local use only. It should not be used to expose gactar to the internet. It is not designed for security or to prevent abuse.

General

/version

Get the version of gactar being run.

Parameters

   (none)

Returns

version string

   The current version tag when gactar was built.

Example

http://localhost:8181/version

Result:

{
  "version": "v0.2.0"
}

/run

Parameters

amod string

   The amod code to run.

goal string

   The initial goal.

Returns

Map of results - one entry for each framework that was run.

modelName string

   The name of the model (comes from the amod code).

code string

   The generated code for the given framework.

output string

   The output of running the model on the framework.

Example

 http://localhost:8181/run

Request payload:

{
  "amod": "==model==\nname: count\n ...",
  "goal": "countFrom: 2 5 starting"
}

Result:

{
  "results": {
    "ccm": {
      "modelName": "count",
      "code": "# Generated by gactar v0.2.0 ...",
      "output": "   0.000 production_match_delay 0 ...\n"
    },
    "pyactr": {
      "modelName": "count",
      "code": "# Generated by gactar v0.2.0 ...",
      "output": "(0, 'PROCEDURAL', 'CONFLICT RESOLUTION') ..."
    },
    "vanilla": {
      "modelName": "count",
      "code": ";;; Generated by gactar v0.2.0 ...",
      "output": "0.000   GOAL                   SET-BUFFER-CHUNK GOAL GOAL NIL ..."
    }
  }
}

Examples

/examples/list

Get a list of the available examples built-in to the server.

Parameters

   (none)

Returns

example_list string array

   The amod file names which may be used with the /examples/[example_name] endpoint.

Example

 http://localhost:8181/examples/list

Result:

{
  "example_list": [
    "addition.amod",
    "addition2.amod",
    "count.amod",
    "semantic.amod",
    "topdown_parser.amod"
  ]
}

/examples/[example_name]

Get the specified built-in example from the server.

Parameters

The name of the example (as part of the URL).

Returns

The amod code for the requested example. (Note that it is not JSON like the other endpoints - it is straight text.)

Example

 http://localhost:8181/examples/count.amod

Result:

==model==

// The name of the model (used when generating code and for error messages)
name: count

...

Sessions

/session/begin

Parameters

   (none)

Returns

sessionID integer

   The id of the new session.

Example

 http://localhost:8181/session/begin

Result:

{
  "sessionID": 1
}

/session/end

Parameters

sessionID integer

   The id of the session to end.

Returns

   (none)

Example

 http://localhost:8181/session/end

Request payload:

{
  "sessionID": 1
}

/session/runModel

Parameters

sessionID integer

   The id of the session.

modelID integer

   The ID of the model to run.

buffers string

   The initial contents of the buffers.

includeCode boolean

   Whether to include the generated code as part of the response. (default: false)

Returns

Map of results - one entry for each framework that was run.

modelName string

   The name of the model (comes from the amod code).

code string

   The generated code for the given framework.

output string

   The output of running the model on the framework.

sessionID integer

   The id of the session.

modelID integer

   The ID of the model which was run.

Example

 http://localhost:8181/session/runModel

Request payload:

{
  "sessionID": 1,
  "modelID": 1,
  "buffers": {
    "goal": "countFrom: 2 5 starting"
  }
}

Result:

{
  "results": {
    "ccm": {
      "modelName": "count",
      "output": "   0.000 production_match_delay 0 ...\n",
      "sessionID": 7,
      "modelID": 2
    },
    "pyactr": {
      "modelName": "count",
      "output": "(0, 'PROCEDURAL', 'CONFLICT RESOLUTION') ...",
      "sessionID": 7,
      "modelID": 2
    },
    "vanilla": {
      "modelName": "count",
      "output": "0.000   GOAL                   SET-BUFFER-CHUNK GOAL GOAL NIL ...",
      "sessionID": 7,
      "modelID": 2
    }
  }
}

Models

/model/load

Given a model (amod code), compile and store it on the server. It returns an id to use to reference the model.

Parameters

amod string

   The amod code to load.

sessionID integer

   The id of the session to load this model in.

Returns

modelID integer

   The ID of this model to use in other calls to the API.

modelName string

   The name of the model (comes from the amod code).

sessionID integer

   The id of the session.

Example

 http://localhost:8181/model/load

Request payload:

{
  "amod": "==model==\nname: count\n ...",
  "sessionID": 1
}

Result:

{
  "modelID": 1,
  "modelName": "count",
  "sessionID": 1
}