Skip to content

Commit c319ef7

Browse files
authored
Merge pull request #47 from VinciGit00/ollama-support
Ollama support
2 parents 72859d5 + a601695 commit c319ef7

34 files changed

+443
-1945
lines changed

.streamlit/config.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.streamlit/credentials.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.8'
2+
services:
3+
ollama:
4+
image: ollama/ollama
5+
container_name: ollama
6+
ports:
7+
- "11434:11434"
8+
volumes:
9+
- ollama_volume:/root/.ollama
10+
restart: unless-stopped
11+
12+
volumes:
13+
ollama_volume:

examples/.env.example

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
OPENAI_APIKEY="your openai.com api key"
2-
GOOGLE_APIKEY="your google.com api key"
1+
OPENAI_APIKEY="your openai api key"
2+
GOOGLE_APIKEY="your google api key"
3+
AZURE_OPENAI_API_KEY="your azure api key"
4+
AZURE_OPENAI_ENDPOINT="https://<your-endpoint>.openai.azure.com/"

examples/custom_graph_gemini.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
from scrapegraphai.models import Gemini
88
from scrapegraphai.graphs import BaseGraph
99
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
10-
10+
from scrapegraphai.helpers import models_tokens
1111
load_dotenv()
12-
gemini_key = os.getenv("GOOGLE_APIKEY")
1312

13+
# ************************************************
1414
# Define the configuration for the graph
15+
# ************************************************
16+
17+
gemini_key = os.getenv("GOOGLE_APIKEY")
18+
1519
graph_config = {
1620
"llm": {
1721
"api_key": gemini_key,
@@ -21,6 +25,10 @@
2125
},
2226
}
2327

28+
# ************************************************
29+
# Define the graph nodes
30+
# ************************************************
31+
2432
llm_model = Gemini(graph_config["llm"])
2533

2634
# define the nodes for the graph
@@ -31,19 +39,23 @@
3139
parse_node = ParseNode(
3240
input="doc",
3341
output=["parsed_doc"],
42+
node_config={"chunk_size": 4096}
3443
)
3544
rag_node = RAGNode(
3645
input="user_prompt & (parsed_doc | doc)",
3746
output=["relevant_chunks"],
38-
model_config={"llm_model": llm_model},
47+
node_config={"llm": llm_model},
3948
)
4049
generate_answer_node = GenerateAnswerNode(
4150
input="user_prompt & (relevant_chunks | parsed_doc | doc)",
4251
output=["answer"],
43-
model_config={"llm_model": llm_model},
52+
node_config={"llm": llm_model},
4453
)
4554

46-
# create the graph by defining the nodes and their connections
55+
# ************************************************
56+
# Create the graph by defining the connections
57+
# ************************************************
58+
4759
graph = BaseGraph(
4860
nodes={
4961
fetch_node,
@@ -59,7 +71,10 @@
5971
entry_point=fetch_node
6072
)
6173

62-
# execute the graph
74+
# ************************************************
75+
# Execute the graph
76+
# ************************************************
77+
6378
result = graph.execute({
6479
"user_prompt": "List me the projects with their description",
6580
"url": "https://perinim.github.io/projects/"

examples/custom_graph_openai.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
from scrapegraphai.models import OpenAI
88
from scrapegraphai.graphs import BaseGraph
99
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
10-
10+
from scrapegraphai.helpers import models_tokens
1111
load_dotenv()
12-
openai_key = os.getenv("OPENAI_APIKEY")
1312

13+
# ************************************************
1414
# Define the configuration for the graph
15+
# ************************************************
16+
17+
openai_key = os.getenv("OPENAI_APIKEY")
18+
1519
graph_config = {
1620
"llm": {
1721
"api_key": openai_key,
@@ -21,6 +25,10 @@
2125
},
2226
}
2327

28+
# ************************************************
29+
# Define the graph nodes
30+
# ************************************************
31+
2432
llm_model = OpenAI(graph_config["llm"])
2533

2634
# define the nodes for the graph
@@ -31,19 +39,23 @@
3139
parse_node = ParseNode(
3240
input="doc",
3341
output=["parsed_doc"],
42+
node_config={"chunk_size": 4096}
3443
)
3544
rag_node = RAGNode(
3645
input="user_prompt & (parsed_doc | doc)",
3746
output=["relevant_chunks"],
38-
model_config={"llm_model": llm_model},
47+
node_config={"llm": llm_model},
3948
)
4049
generate_answer_node = GenerateAnswerNode(
4150
input="user_prompt & (relevant_chunks | parsed_doc | doc)",
4251
output=["answer"],
43-
model_config={"llm_model": llm_model},
52+
node_config={"llm": llm_model},
4453
)
4554

46-
# create the graph by defining the nodes and their connections
55+
# ************************************************
56+
# Create the graph by defining the connections
57+
# ************************************************
58+
4759
graph = BaseGraph(
4860
nodes={
4961
fetch_node,
@@ -59,7 +71,10 @@
5971
entry_point=fetch_node
6072
)
6173

62-
# execute the graph
74+
# ************************************************
75+
# Execute the graph
76+
# ************************************************
77+
6378
result = graph.execute({
6479
"user_prompt": "List me the projects with their description",
6580
"url": "https://perinim.github.io/projects/"

examples/graph_evaluation_example.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

examples/scrape_plain_text.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,40 @@
66
from dotenv import load_dotenv
77
from scrapegraphai.graphs import SmartScraperGraph
88
from scrapegraphai.utils import convert_to_csv, convert_to_json
9-
109
load_dotenv()
11-
openai_key = os.getenv("OPENAI_APIKEY")
1210

11+
# ************************************************
12+
# Read the text file
13+
# ************************************************
14+
15+
FILE_NAME = "inputs/plain_html_example.txt"
16+
curr_dir = os.path.dirname(os.path.realpath(__file__))
17+
file_path = os.path.join(curr_dir, FILE_NAME)
18+
19+
# It could be also a http request using the request model
20+
with open(file_path, 'r', encoding="utf-8") as file:
21+
text = file.read()
22+
23+
# ************************************************
1324
# Define the configuration for the graph
25+
# ************************************************
26+
27+
openai_key = os.getenv("OPENAI_APIKEY")
28+
1429
graph_config = {
1530
"llm": {
1631
"api_key": openai_key,
1732
"model": "gpt-3.5-turbo",
1833
},
1934
}
2035

36+
# ************************************************
37+
# Create the SmartScraperGraph instance and run it
38+
# ************************************************
2139

22-
# It could be also a http request using the request model
23-
text = open('inputs/plain_html_example.txt', 'r', encoding="utf-8")
24-
25-
# Create the SmartScraperGraph instance
2640
smart_scraper_graph = SmartScraperGraph(
2741
prompt="List me all the news with their description.",
28-
file_source=str(text),
42+
source=text,
2943
config=graph_config
3044
)
3145

examples/scrape_xml_document.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,39 @@
66
from dotenv import load_dotenv
77
from scrapegraphai.graphs import SmartScraperGraph
88
from scrapegraphai.utils import convert_to_csv, convert_to_json
9-
109
load_dotenv()
11-
openai_key = os.getenv("OPENAI_APIKEY")
1210

11+
# ************************************************
12+
# Read the XML file
13+
# ************************************************
14+
15+
FILE_NAME = "inputs/books.xml"
16+
curr_dir = os.path.dirname(os.path.realpath(__file__))
17+
file_path = os.path.join(curr_dir, FILE_NAME)
18+
19+
with open(file_path, 'r', encoding="utf-8") as file:
20+
text = file.read()
21+
22+
# ************************************************
1323
# Define the configuration for the graph
24+
# ************************************************
25+
26+
openai_key = os.getenv("OPENAI_APIKEY")
27+
1428
graph_config = {
1529
"llm": {
1630
"api_key": openai_key,
1731
"model": "gpt-3.5-turbo",
1832
},
1933
}
2034

21-
# Read the XML file
22-
with open('inputs/books.xml', 'r', encoding="utf-8") as file:
23-
text = file.read()
35+
# ************************************************
36+
# Create the SmartScraperGraph instance and run it
37+
# ************************************************
2438

25-
# Create the SmartScraperGraph instance
2639
smart_scraper_graph = SmartScraperGraph(
2740
prompt="List me all the authors, title and genres of the books",
28-
file_source=text, # Pass the content of the file, not the file object
41+
source=text, # Pass the content of the file, not the file object
2942
config=graph_config
3043
)
3144

examples/search_graph_example.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,30 @@
66
from dotenv import load_dotenv
77
from scrapegraphai.graphs import SearchGraph
88
from scrapegraphai.utils import convert_to_csv, convert_to_json
9-
109
load_dotenv()
11-
openai_key = os.getenv("OPENAI_APIKEY")
1210

11+
# ************************************************
1312
# Define the configuration for the graph
13+
# ************************************************
14+
15+
openai_key = os.getenv("OPENAI_APIKEY")
16+
1417
graph_config = {
1518
"llm": {
19+
"model": "ollama/mistral",
20+
"temperature": 0,
21+
"format": "json", # Ollama needs the format to be specified explicitly
22+
},
23+
"embeddings": {
1624
"api_key": openai_key,
1725
"model": "gpt-3.5-turbo",
18-
"temperature": 0,
1926
},
2027
}
2128

22-
# Create the SmartScraperGraph instance
29+
# ************************************************
30+
# Create the SearchGraph instance and run it
31+
# ************************************************
32+
2333
search_graph = SearchGraph(
2434
prompt="List me all the regions of Italy.",
2535
config=graph_config

examples/smart_scraper_example.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,30 @@
55
import os
66
from dotenv import load_dotenv
77
from scrapegraphai.graphs import SmartScraperGraph
8-
98
load_dotenv()
10-
openai_key = os.getenv("OPENAI_APIKEY")
119

10+
11+
# ************************************************
1212
# Define the configuration for the graph
13+
# ************************************************
14+
15+
openai_key = os.getenv("OPENAI_APIKEY")
16+
1317
graph_config = {
1418
"llm": {
1519
"api_key": openai_key,
1620
"model": "gpt-3.5-turbo",
1721
},
1822
}
1923

20-
# Create the SmartScraperGraph instance
24+
# ************************************************
25+
# Create the SmartScraperGraph instance and run it
26+
# ************************************************
27+
2128
smart_scraper_graph = SmartScraperGraph(
2229
prompt="List me all the news with their description.",
2330
# also accepts a string with the already downloaded HTML code
24-
file_source="https://www.wired.com",
31+
source="https://www.wired.com",
2532
config=graph_config
2633
)
2734

0 commit comments

Comments
 (0)