Skip to content

Commit

Permalink
Merge pull request #1515 from Jaseci-Labs/littleX_doc
Browse files Browse the repository at this point in the history
Jaseci cookbook
  • Loading branch information
marsninja authored Jan 14, 2025
2 parents 2318a8c + b6f38b8 commit 8ae56fd
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import:py from jac_cloud {FastAPI}

walker post_no_body {}

walker post_with_body {
has a: str;
}

walker get_no_body {
obj __specs__ {
static has methods: list = ["get"];
}
}

walker get_with_query {
has a: str;

obj __specs__ {
static has methods: list = ["get"], as_query: list = ["a"];
}
}

walker get_all_query {
has a: str;
has b: str;

obj __specs__ {
static has methods: list = ["get"], as_query: list = "*", auth: bool = False;
}
}

walker post_path_var {
has a: str;

obj __specs__ {
static has path: str = "/{a}", methods: list = ["post", "get"];
}
}

walker combination1 {
has a: str;
has b: str;
has c: str;

obj __specs__ {
static has methods: list = ["post", "get"], as_query: list = ["a", "b"];
}
}


walker combination2 {
has a: str;
has b: str;
has c: str;

obj __specs__ {
static has path: str = "/{a}", methods: list = ["post", "get", "put", "patch", "delete", "head", "trace", "options"], as_query: list = ["b"];
}
}

walker post_with_file {
has single: UploadFile;
has multiple: list[UploadFile];
has singleOptional: UploadFile | None = None;


can enter with `root entry {
print(self.single);
print(self.multiple);
print(self.singleOptional);
}

obj __specs__ {}
}

walker post_with_body_and_file {
has val: int;
has single: UploadFile;
has multiple: list[UploadFile];
has optional_val: int = 0;

can enter with `root entry {
print(self.val);
print(self.optional_val);
print(self.single);
print(self.multiple);
}

obj __specs__ {
static has auth: bool = False;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 30080
hostPort: 30080
protocol: TCP
32 changes: 32 additions & 0 deletions jac/support/jac-lang.org/docs/learn/littleX/src/mtllm_example.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import:py from mtllm.llms {Ollama}

glob llm = Ollama(host="http://127.0.0.1:11434", model_name="llama3.2:1b");

can 'Summarize latest trends, major events, and notable interactions from the recent tweets in one line.'
summarise_tweets(tweets: list[str]) -> 'Summarisation': str by llm();


with entry {
Tweets = ["Just finished a thrilling book that I couldn't put down! What's your latest page-turner? 📚 #BookRecommendations"

,"Movie nights are the best! What's a film that you can watch over and over? 🎬 #FilmLovers"

,"Diving into a new fantasy series this weekend—what genre do you love to escape into? 🧙‍♂️ #Reading"

,"Caught the latest blockbuster last night! What's your favorite film of the year so far? 🍿 #Cinema"

,"Nothing like curling up with a good book and a cup of tea. What's your ideal reading setup? ☕📖 #CozyVibes"

,"Just started a new hobby: film photography! What hobbies are you passionate about? 📸 #CreativeLife"

,"Books can transport us to different worlds. What fictional universe would you love to live in? 🌌 #BookLovers"

,"Anyone else binge-watching classic films lately? What's a must-see that everyone should experience? 🎥 #MovieMarathon"

,"Reading is my escape. What's a book that changed your perspective on life? 🌍 #ImpactfulReads",

"I love discovering indie films! What's an underrated gem you'd recommend? 🌟 #HiddenGems"];
print(summarise_tweets(Tweets));
}


142 changes: 138 additions & 4 deletions jac/support/jac-lang.org/docs/learn/littleX/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,143 @@ A **graph** is a mathematical structure used to model relationships between obje
edge follow {}
```





### **Jaclang Implementation**

=== "Jaclang Installation"
1. Install Jaclang
```bash
pip install jaclang, graphviz
```
2. Run code
```bash
jac run filename.jac
```
3. Visulalize Graph
```bash
jac dot filename.jac > filename.dot
```
4. Open the saved dot file and visualize

=== "Example 1"
```jac linenums="1"
--8<-- "examples/data_spatial/create_node.jac"
```

For more explanation [visit](../data_spatial/examples.md)

## **Introduction to Jac-cloud**

### **Walkers**
- Walkers are simply agents that can walk on a graph and do tasks where needed.
- Walkers also inherits from classes in jaclang, but they do not require initialization.
- Abilities can be defined to run on different types of nodes.
- Jaseci stack automatically converts walkers into RESTful API Endpoints

#### **Profile Management**
- `visit_profile`: Access or create a new user profile.
- `load_user_profiles`: Loads all user profiles from the database.
- `update_profile`: Updates a profile’s username.
- `get_profile`: Retrieves and logs profile information.
- `follow_request` / `un_follow_request`: Allows users to follow or unfollow other profiles.

#### **Tweet Management**
- `create_tweet`: Allows a user to post a new tweet.
- `update_tweet`: Updates an existing tweet’s content.
- `remove_tweet`: Deletes a user’s tweet.
- `load_tweets`: Fetches all tweets from a user, including:
- Comments.
- Likes.
- Content with timestamps.
- `like_tweet` / `remove_like`: Users can like or unlike tweets.
- `comment_tweet`: Users can comment on tweets.

#### **User Feed and Search**
- **`load_feed`:**
- Fetches the latest tweets from the user and their followees.
- Summarizes tweets using GPT-4o.
- Provides search functionality using query-based filtering with `cosine_similarity`.
- **`summarise_tweets`:**
- Summarizes major trends and events from fetched tweets in a concise line.
- **`search_tweets`:**
- Filters tweets relevant to a query using vector embeddings.

#### **Interaction Loaders**
- `load_likes`: Fetches likes on a tweet.
- `load_comments`: Fetches comments on a tweet.
- `load_tweet`: Fetches details of a specific tweet, including content and author.

### **Jac Cloud Implementation**

=== "Jac-cloud Installation"
1. Install Jaclang
```bash
pip install jac-cloud
```
2. Run code
```bash
jac serve filename.jac
```
3. Go to your browser and navigate to
```bash
http://localhost:8000/docs
```

=== "Example 1"
```jac linenums="1"
--8<-- "support\jac-lang.org\docs\learn\littleX\src\Jac_cloud_example.jac"
```
## **Introduction to MTLLM**
Integrates LLM into your existing application with minimal effort.

### **MTLLM Implementation**

=== "MTLLM Installation"
1. Install MTLLM with ollama
```bash
pip install mtllm[ollama]
```
2. Run code
```bash
jac run mtllm_example.jac
```

=== "Example 1"
```jac linenums="1"
--8<-- "support\jac-lang.org\docs\learn\littleX\src\mtllm_example.jac"
```

## **Introduction to Jac Splice Orchestrator**

**JAC Cloud Orchestrator** (jac-splice-orc) is a system designed to **dynamically import** any Python module, deploy it as a Kubernetes Pod, and expose it as an independent gRPC service. This enables any Python module to be used as a microservice, providing flexibility and scalability in a cloud environment.

### **Jac Splice Orchestrator Implementation**

=== "Jac-splice-orc Installation"
1. Install Jac Splice Orchestrator
```bash
pip install jac-splice-orc
```
2. Setup Configuration file and Create Cluster
```bash
kind create cluster --name cluster_name --config kind-config.yaml
```
3. Initialize Jac Splice Orchestrator
```bash
jac orc_initialize cluster_name
```
4. Run Jac file
```bash
jac run filename.jac
```

=== "kind-config.yaml"
```yaml linenums="1"
--8<-- "support\jac-lang.org\docs\learn\littleX\src\kind-config.yaml"
```

=== "Example"
```jac linenums="1"
--8<-- "support\jac-lang.org\docs\learn\littleX\src\mtllm_example.jac"
```


0 comments on commit 8ae56fd

Please sign in to comment.