Skip to content

Jaseci-Labs/inr-codelabs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Codelab-1

Summary

  • 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.

Recording

Here's the recording for codelab-1: Jaseci AI Mentorship Sessions-20230220_113750-Meeting Recording.mp4

Build and Test it!

The first objective here is to get the jaseci-serv running. To do this, you'll run the following commands:

jsserv makemigrations base

alt text

jsserv migrate

alt text

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.

alt text

Once the superuser is created, you can run your server:

jsserv runserver

alt text

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

alt text

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

alt text

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.

alt text

Now, you are reaady to register the sentinel:

sentinel register -name main -mode ir main.jir

alt text

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.

Visualizing the graph using Jaseci Studio

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'.

alt text

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.

alt text

Rebuilding and updating sentinel

Everytime a change is made to the code, you must run the following two commands:

jac build main.jac

alt text

sentinel set -snt active:sentinel -mode ir main.jir

alt text

Execute import_news_data walker

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\" }"

alt text

You should get a similar result like this:

alt text

Updated Graph

Now, let's see the updated graph:

alt text

alt text

Postman

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.

alt text

Select method POST

alt text

Enter "http://localhost:8000/js/walker_run" as request URL.

alt text

Click on headers tab

alt text

Add Authorization as key

alt text

Enter "token my_token" as authorization value; ensure there is 1 space between token and the token you copied.

alt text

Under body tab in postman, select raw and change type to JSON

alt text

Copy and paste the below example in the body.

alt text

Replace "snt" value with my_sentinel_id

alt text

Send the request

alt text

The result should look like this:

alt text

Example of sending request through Postman

{
    "name": "import_news_data",
    "ctx": {"file_path": "./news_posts.json"},
    "_req_ctx": {},
    "snt": "my_sentinel_id",
    "profiling": false,
    "is_async": false
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published