Skip to content

Commit

Permalink
clean read me
Browse files Browse the repository at this point in the history
  • Loading branch information
HomunMage committed Jun 20, 2024
1 parent f5082b5 commit 9ade246
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 238 deletions.
25 changes: 1 addition & 24 deletions 01 LangChain Hello World/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ Follow these steps to set up and run the `ollama` server:
python main.py
```

## Script Explanation

### Importing Libraries

The script starts by importing the necessary libraries from the `langchain` ecosystem:

```python
from langchain_community.chat_models import ChatOllama
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
```
## Core Explanation

### Specifying the Local Language Model

Expand Down Expand Up @@ -86,23 +76,10 @@ llm_chain = prompt | llm | StrOutputParser()
generation = llm_chain.invoke(formatted_prompt)
```

### Printing the Output

Print the generated output:

```python
print(generation)
```

## Running the Script

1. Ensure the `ollama` server is running as described in the [Setting Up the Ollama Server](#setting-up-the-ollama-server) section.
2. Run the Python script in another terminal:
```sh
python main.py
```

## Notes

- Ensure all dependencies are installed and the `ollama` server is running before executing the script.
- Adjust the prompt template and input question as needed to suit your use case.
39 changes: 4 additions & 35 deletions 02 LangGraph Hello World/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ This tutorials is refer to [Learn LangGraph - The Easy Way](https://www.youtube.

- Python 3.11
- `langgraph` library
- `ollama` server (if needed)

### Installing Dependencies

Expand All @@ -19,33 +18,11 @@ Install the necessary Python package:
pip install langgraph
```

### Setting Up the Ollama Server

If your project requires the `ollama` server, follow these steps to set up and run it:

1. Open a terminal and start the `ollama` server:
```sh
ollama serve
```

2. Open another terminal and run the Python script:
```sh
python main.py
```

## Script Explanation

### Importing Libraries

The script starts by importing the necessary library:

```python
from langgraph.graph import Graph
```
## Core Explanation

### Defining Functions

Define two simple functions to be used in the workflow:
Define two simple node to be used in the workflow:

```python
def function_1(input_1):
Expand Down Expand Up @@ -98,15 +75,7 @@ print(output)

## Running the Script

1. Ensure all dependencies are installed as described in the [Installing Dependencies](#installing-dependencies) section.
2. If required, ensure the `ollama` server is running as described in the [Setting Up the Ollama Server](#setting-up-the-ollama-server) section.
3. Run the Python script:
Run the Python script:
```sh
python main.py
```

## Notes

- Ensure all dependencies are installed and the `ollama` server is running before executing the script (if needed).
- Adjust the functions and workflow as needed to suit your use case.

```
35 changes: 35 additions & 0 deletions 03 Graph Chain Hello World/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 03 Graph Chain Hello World

This project demonstrates the use of the `langgraph` and `langchain-community` libraries to create a workflow graph that interacts with a local language model to generate and process content.

This tutorials is refer to [Learn LangGraph - The Easy Way](https://www.youtube.com/watch?v=R8KB-Zcynxc).

## Core Explanation


### Defining Functions

Because we use json format, we can parse that

```python
def Tool(input):
print("Tool Stage input:" + input)
# Parse the JSON input
data = json.loads(input)
# Extract the "content" and "filename" parts
content = data.get("content", "")
filename = data.get("filename", "output.md")
# Write the content to the specified filename
with open(filename, 'w') as file:
file.write(content)
return input
```

## Running the Script

1. Ensure all dependencies are installed as described in the [Installing Dependencies](#installing-dependencies) section.
2. If required, ensure the `ollama` server is running as described in the [Setting Up the Ollama Server](#setting-up-the-ollama-server) section.
3. Run the Python script:
```sh
python main.py
```
File renamed without changes.
154 changes: 0 additions & 154 deletions 03 Graph Chain Hello World1/README.md

This file was deleted.

27 changes: 3 additions & 24 deletions 04 State Graph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,10 @@ This tutorials is ref from
* [Learn LangGraph - The Easy Way](https://www.youtube.com/watch?v=R8KB-Zcynxc).
* [langgraph_code_assistant.ipynb](https://github.com/langchain-ai/langgraph/blob/main/examples/code_assistant/langgraph_code_assistant.ipynb)

## Environment Setup
## Core Explanation

### Prerequisites

- Python 3.11
- `langgraph` library

### Installing Dependencies

Install the necessary Python package:
```sh
pip install langgraph
```

## Script Explanation

### Importing Libraries

The script starts by importing the necessary libraries:

```python
from langgraph.graph import StateGraph, END
from typing import TypedDict, Literal, Union
import random
```
* We need State as global state machine to store info like chat history
* We need conditional edge to make the state machine able to swtich states

### Defining Node and Edge function

Expand Down
Loading

0 comments on commit 9ade246

Please sign in to comment.