Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Documentation v2 #1451

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c7e8360
Adding support for Jac features in type check
mgtm98 Nov 2, 2024
d95b7b2
Support DisconnectOp and spwan keyword
mgtm98 Nov 8, 2024
abb27ed
Adding AtomTrailer type info
mgtm98 Nov 11, 2024
92c96ff
Adding tests for root, node_dot, spawn, disconnectOp
mgtm98 Nov 11, 2024
de35e41
Adding support for EdgeRefTrailer type fusion
mgtm98 Nov 15, 2024
dff3c28
Change docs structure
savini98 Nov 18, 2024
9af08d1
Huge re-org. Setting up for contribution from the team.
ypkang Nov 18, 2024
15ca5e7
Merge branch 'main' into data_spatial_types_fix
mgtm98 Nov 19, 2024
67d4430
Merge branch 'main' into data_spatial_types_fix
mgtm98 Nov 19, 2024
a1c3678
Update types.md
ypkang Nov 19, 2024
b3a24f2
Update can_abilities.md
ypkang Nov 19, 2024
a81275c
Update import.md
ypkang Nov 19, 2024
705842e
Added Data spatial Pages ( for structure ) and updated mkdocs.yml
Anirudh02-sys Nov 21, 2024
ec9603b
Merge pull request #1460 from Jaseci-Labs/main
mgtm98 Nov 22, 2024
8d3681f
Merge pull request #1421 from Jaseci-Labs/data_spatial_types_fix
marsninja Dec 2, 2024
110bccb
Language basics update
savini98 Dec 9, 2024
9384f9f
cli and py integration
Jayanaka-98 Dec 9, 2024
17daf8c
Merge branch 'main' of https://github.com/Jaseci-Labs/jaseci
Jayanaka-98 Dec 17, 2024
ffc74c3
pyproject.toml replacement for setup.py (need decision)
Jayanaka-98 Dec 19, 2024
97da87e
Demo video for MTLLM landing
Jayanaka-98 Dec 19, 2024
d091aba
Outline for MTLLM
Jayanaka-98 Dec 19, 2024
817ff04
setup.py removed
Jayanaka-98 Dec 19, 2024
0734be6
Merge branch 'main' of https://github.com/Jaseci-Labs/jaseci into doc…
Jayanaka-98 Dec 20, 2024
8433487
Merge branch 'main' into doc_update
Jayanaka-98 Dec 20, 2024
7973a93
Whitespaces
Jayanaka-98 Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import:py streamlit as st;
import:py requests;

can bootstrap_frontend (token: str) {
st.write("Welcome to your Demo Agent!");

# Initialize chat history
if "messages" not in st.session_state {
st.session_state.messages = [];
}

for message in st.session_state.messages {
with st.chat_message(message["role"]) {
st.markdown(message["content"]);
}
}

if prompt := st.chat_input("What is up?") {
# Add user message to chat history
st.session_state.messages.append({"role": "user", "content": prompt});

# Display user message in chat message container
with st.chat_message("user") {
st.markdown(prompt);
}

# Display assistant response in chat message container
with st.chat_message("assistant") {

# Call walker API
response = requests.post("http://localhost:8000/walker/interact", json={"message": prompt, "session_id": "123"},
headers={"Authorization": f"Bearer {token}"}
);

if response.status_code == 200 {
response = response.json();
print(response);
st.write(response["reports"][0]["response"]);

# Add assistant response to chat history
st.session_state.messages.append({"role": "assistant", "content": response["reports"][0]["response"]});
}
}
}
}

with entry {

INSTANCE_URL = "http://localhost:8000";
TEST_USER_EMAIL = "[email protected]";
TEST_USER_PASSWORD = "password";

response = requests.post(
f"{INSTANCE_URL}/user/login",
json={"email": TEST_USER_EMAIL, "password": TEST_USER_PASSWORD}
);

if response.status_code != 200 {
# Try registering the user if login fails
response = requests.post(
f"{INSTANCE_URL}/user/register",
json={
"email": TEST_USER_EMAIL,
"password": TEST_USER_PASSWORD
}
);
assert response.status_code == 201;

response = requests.post(
f"{INSTANCE_URL}/user/login",
json={"email": TEST_USER_EMAIL, "password": TEST_USER_PASSWORD}
);
assert response.status_code == 200;
}

token = response.json()["token"];

print("Token:", token);

bootstrap_frontend(token);
}
Binary file not shown.
87 changes: 87 additions & 0 deletions jac/support/jac-lang.org/docs/examples/tutorial/solution/rag.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import: py os;
import: py from langchain_community.document_loaders {PyPDFDirectoryLoader}
import: py from langchain_text_splitters {RecursiveCharacterTextSplitter}
import: py from langchain.schema.document {Document}
import: py from langchain_community.embeddings.ollama {OllamaEmbeddings}
import: py from langchain_community.vectorstores.chroma {Chroma}


obj RagEngine {
has file_path: str = "docs";
has chroma_path: str = "chroma";
can postinit {
documents: list = self.load_documents();
chunks: list = self.split_documents(documents);
self.add_to_chroma(chunks);
}
can load_documents {
document_loader = PyPDFDirectoryLoader(self.file_path);
return document_loader.load();
}

can split_documents(documents: list[Document]) {
text_splitter = RecursiveCharacterTextSplitter(chunk_size=800,
chunk_overlap=80,
length_function=len,
is_separator_regex=False);
return text_splitter.split_documents(documents);
}

can get_embedding_function {
embeddings = OllamaEmbeddings(model='nomic-embed-text');
return embeddings;
}
can add_chunk_id(chunks:str) {
last_page_id = None;
current_chunk_index = 0;

for chunk in chunks {
source = chunk.metadata.get('source');
page = chunk.metadata.get('page');
current_page_id = f'{source}:{page}';

if current_page_id == last_page_id {
current_chunk_index +=1;
} else {
current_chunk_index = 0;
}

chunk_id = f'{current_page_id}:{current_chunk_index}';
last_page_id = current_page_id;

chunk.metadata['id'] = chunk_id;
}

return chunks;
}
can add_to_chroma(chunks: list[Document]) {
db = Chroma(persist_directory=self.chroma_path, embedding_function=self.get_embedding_function());
chunks_with_ids = self.add_chunk_id(chunks);

existing_items = db.get(include=[]);
existing_ids = set(existing_items['ids']);

new_chunks = [];
for chunk in chunks_with_ids {
if chunk.metadata['id'] not in existing_ids {
new_chunks.append(chunk);
}
}

if len(new_chunks) {
print('adding new documents');
new_chunk_ids = [chunk.metadata['id'] for chunk in new_chunks];
db.add_documents(new_chunks, ids=new_chunk_ids);
} else {
print('no new documents to add');
}
}
can get_from_chroma(query: str,chunck_nos: int=5) {
db = Chroma(
persist_directory=self.chroma_path,
embedding_function=self.get_embedding_function()
);
results = db.similarity_search_with_score(query, k=chunck_nos);
return results;
}
}
107 changes: 107 additions & 0 deletions jac/support/jac-lang.org/docs/examples/tutorial/solution/server.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import:py from mtllm.llms {OpenAI}
import:jac from rag {RagEngine}

glob llm = OpenAI(model_name='gpt-4o');
glob rag_engine:RagEngine = RagEngine();

walker interact {
has message: str;
has session_id: str;

can init_session with `root entry {
visit [-->](`?Session)(?id == self.session_id) else {
session_node = here ++> Session(id=self.session_id, chat_history=[], status=1);
print("Session Node Created");

visit session_node;
}
}
}
node Session {
has id: str;
has chat_history: list[dict];
has status: int = 1;

can 'Respond to message using chat_history as context and agent_role as the goal of the agent'
llm_chat(
message:'current message':str,
chat_history: 'chat history':list[dict],
agent_role:'role of the agent responding':str,
context:'retrieved context from documents':list
) -> 'response':str by llm();

can chat with interact entry {
self.chat_history.append({"role": "user", "content": here.message});
response = infer(message=here.message, chat_history=self.chat_history) spawn root;
self.chat_history.append({"role": "assistant", "content": response.response});

report {
"response": response.response
};
}
}

enum ChatType {
RAG : 'Need to use Retrievable information in specific documents to respond' = "RAG",
QA : 'Given context is enough for an answer' = "user_qa"
}

node Router {
can 'route the query to the appropriate task type'
classify(message:'query from the user to be routed.':str) -> ChatType by llm(method="Reason", temperature=0.0);
}

walker infer {
has message:str;
has chat_history: list[dict];

can init_router with `root entry {
visit [-->](`?Router) else {
router_node = here ++> Router();
router_node ++> RagChat();
router_node ++> QAChat();
visit router_node;
}
}
can route with Router entry {
classification = here.classify(message = self.message);
visit [-->](`?Chat)(?chat_type==classification);
}
}

node Chat {
has chat_type: ChatType;
}

node RagChat :Chat: {
has chat_type: ChatType = ChatType.RAG;

can respond with infer entry {
print("Responding to the message");
can 'Respond to message using chat_history as context and agent_role as the goal of the agent'
respond_with_llm( message:'current message':str,
chat_history: 'chat history':list[dict],
agent_role:'role of the agent responding':str,
context:'retirved context from documents':list
) -> 'response':str by llm();
data = rag_engine.get_from_chroma(query=here.message);
print("Data:", data);
here.response = respond_with_llm(here.message, here.chat_history, "You are a conversation agent designed to help users with their queries based on the documents provided", data);
print("Here:", here);
}
}

node QAChat :Chat: {
has chat_type: ChatType = ChatType.QA;

can respond with infer entry {
print("Responding to the message");
can 'Respond to message using chat_history as context and agent_role as the goal of the agent'
respond_with_llm( message:'current message':str,
chat_history: 'chat history':list[dict],
agent_role:'role of the agent responding':str
) -> 'response':str by llm();
here.response = respond_with_llm(here.message, here.chat_history, agent_role="You are a conversation agent designed to help users with their queries");
print("Here:", here);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Connecting Nodes

## <span style="color: orange"> How to print connections ( tentative ) </span>

## <span style="color: orange">How to view graph using dotgen</span>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Data Spatial Programming

## <span style="color: orange">Why Data-spatial</span>

## <span style="color: orange">Nodes and Edges</span>

## <span style="color: orange">Walkers and how to visit walkers?</span>

## <span style="color: orange">Abilities</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Edge Filtering

### <span style="color: orange">Why? </span>

### <span style="color: orange">How? </span>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Introduction to Data Spatial Primitives: Nodes and Edges
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Walkers

### <span style="color: orange">Introduction</span>

### <span style="color: orange">Visit primitive</span>

### <span style="color: orange">Examples ( Maybe a basic graph algorithm , will be able to differentiate traversal in jaclang from every other language)</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Why Data-spatial


## <span style="color: orange">Why Data-spatial</span>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <span style="color: orange; font-weight: bold">Getting Started with Jac-Lang</span>
# <span style="color: orange; font-weight: bold">Getting Started</span>

If you know python, there's near zero learning curve to get started.

Expand All @@ -12,15 +12,15 @@ If you know python, there's near zero learning curve to get started.

<!-- [:octicons-arrow-right-24: Getting started](#) -->

[Setup Now](start/installation.md){ .md-button }
[Setup Now](../getting_started/installation.md){ .md-button }

- __Jac in a FLASH__

---

*If you are already a fluent pythonista jump into learning by going through a step-by-step transformation from python to jac-lang and BEYOND!*

[Get Started](start/jac_in_a_flash.md){ .md-button .md-button--primary }
[Get Started](../getting_started/jac_in_a_flash.md){ .md-button .md-button--primary }

</div>

Expand Down
36 changes: 36 additions & 0 deletions jac/support/jac-lang.org/docs/for_coders/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<h1 style="color: orange; font-weight: bold; text-align: center;">Welcome to Jac</h1>

**Jac** combines the power and flexibility of Python's ecosystem and 'pythonic' coding style with a unique 'jactastic' approach to programming. It draws inspiration from a variety of programming languages to improve upon Python to create an engaging, productive, and intuitive coding experience, giving the coder all of python's power, plus superpowers. Additionally, Jac introduces a keystone innovation that may prove to be a monumental advancement in programming languages called the **Data Spatial Programming Model**.

Just as Object-Oriented Programming (OOP) brought a higher level of abstraction to C and Fortran's functions offered a new way to manage assembly code, Jac introduces Data Spatial Programming constructs expanding on the concept of OOP. This new model is a higher-level abstraction that lets programmers rethink how they interact with data structures, and enable new ways of thinking and being productive.

That being said, Jac was meticulously designed to provide a seamless gradient of expressiveness allowing coders to code in a familiar pythonic style, while using as much or as little data spatial semantics as they'd like.

Join us on this exciting journey. Let's make code art with Jac.

# Content

- [**Introduction to Jac**](getting_started.md)
- [**Why Jac**](why_jac.md)
<!-- - [**Get Started with Jac**](../start.md) -->
- [**Language Basics**](language_basics.md)
- ['```can```' abilities](language_basics.md#can-abilities)
- [Object types](language_basics.md#object-type)
- [Import](language_basics.md#imports)
- [Main entry point](language_basics.md#main-entry-point)
- [Separate implementation from declaration](language_basics.md#seperate-implementation-from-declaration)
- [Enforced type hinting](language_basics.md#enforced-type-hinting)

- [**Data Spatial Programming**](data_spatial/dataspatial.md)
- [Why Data Spatial Programming?](data_spatial/dataspatial.md#why-data-spatial)
- [Nodes and Edges](data_spatial/dataspatial.md#nodes-and-edges)
- [Walkers and how to visit walkers?](data_spatial/dataspatial.md#walkers-and-how-to-visit-walkers)
- [Abilities](data_spatial/dataspatial.md#abilities)
- [**Python Integration**](python_integration.md)
- [How to use Python Libraries?](python_integration.md#how-to-use-python-libraries)
- [Integrate jac into existing python programs](python_integration.md#integrate-jac-into-existing-python-programs)
- [**MTLLM - Programming with LLMs**](mtllm/with_llm.md)
- [**Jac colud - Full Stack Deployment**](jac-cloud/jac_cloud.md)
- **Jac Tools**
- [Testing](tools/testing.md)
- [Jac-stramelit](tools/jac_streamlit.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# GenAI Models

- Remote model APIs
- Local model APIs
- Creating your own model interface
Loading
Loading