Before you begin running any JAC program, always remember to install or update your current version of jaseci. You can do this by running the following commands:
pip3 install jaseci
or pip3 install jaseci --upgrade
pip3 install jaseci-serv
or pip3 install jaseci-serv --upgrade
- Skeleton of the app will be built out;
- advised folder structure, naming conventions will be conveyed;
- sample news post dataset will be provided in the form of JSON file;
- Code thru objective will be to step through building:
- the graph structure to organize the news post data,
- the walker which imports the data and spawns the graph
- other walkers which provide complementing CRUD operations on graph data
- Interacting with your JAC app via the API will be covered
- Jaseci Studio will be introduced to visualize the imported graph data in the Jaseci graph.
Here's the recording for codelab-1: Jaseci AI Mentorship Sessions-20230220_113750-Meeting Recording.mp4
The first objective here is to get the jaseci-serv running. To do this, you'll run the following commands:
jsserv makemigrations base
jsserv migrate
In django, it's going to set up the necessary structures to run your JAC application.
Once that is set up, we need to create the superuser for your JAC application.
Run the following command:
jsserv createsuperuser
Enter your email and password as prompted.
Once the superuser is created, you can run your server:
jsserv runserver
Note: When the server is running, you should leave that terminal alone. Any other commands, should be executed in another terminal.
In a new terminal, run jsctl -m
This will start the jaseci shell, which will be used to login to the server.
Once you have the jaseci shell running, run the command:
jac build main.jac
Next, you'll login to the server:
login http://localhost:8000
Enter username and password of superuser created above.
If login successful, a token should be generated. We'll refer to this as my_token. This will be needed to make requests to the API via Postman. See the Postman section below for more information.
Now, you are reaady to register the sentinel:
sentinel register -name main -mode ir main.jir
Note: sentinel register should only be executed once. sentinel set should be used for every subsequent change and recompilation.
We'll refer to the sentinel's jid as my_sentinel_id. This will also be needed to make requests to the API via Postman.
Download and install the latest version of the Jaseci Studio application, based on your Operating System.
Once Jaseci Studio is running, you'll need to enter host, port, email and password (for the superuser) and then click 'Test Connection'. If it's successful, you can click 'Connect'.
Once connected, on the left navigation menu, click on the icon that looks like a graph.
You should see the graph with the root node and app_root node. Click on app_root node, followed by the 'Expand Recursively' button to see the posts node.
Everytime a change is made to the code, you must run the following two commands:
jac build main.jac
sentinel set -snt active:sentinel -mode ir main.jir
This walker:
- deletes the existing post nodes from the graph, if any.
- creates the posts nodes using data from the JSON file.
To run this walker, enter the following command in the jaseci terminal:
walker run import_news_data -ctx "{\"file_path\": \"news_posts.json\" }"
You should get a similar result like this:
Now, let's see the updated graph:
You can also execute the walkers via Postman.
Download and install the latest version of the Postman application, based on your Operating System.
Once Postman is running, create a request.
Select method POST
Enter "http://localhost:8000/js/walker_run" as request URL.
Click on headers tab
Add Authorization as key
Enter "token my_token" as authorization value; ensure there is 1 space between token and the token you copied.
Under body tab in postman, select raw and change type to JSON
Copy and paste the below example in the body.
Replace "snt" value with my_sentinel_id
Send the request
The result should look like this:
{
"name": "import_news_data",
"ctx": {"file_path": "./news_posts.json"},
"_req_ctx": {},
"snt": "my_sentinel_id",
"profiling": false,
"is_async": false
}