Skip to content

Python scraper based on AI

docker compose working ollama implementation

EURAC\marperini6a83c2306d6d
diff --git a/.streamlit/config.toml b/.streamlit/config.toml
deleted file mode 100644
index 43a50cbc..00000000
--- a/.streamlit/config.toml
+++ /dev/null
@@ -1,6 +0,0 @@
-[theme]
-primaryColor="#0A2C37"
-backgroundColor="#FFFFFF"
-secondaryBackgroundColor="F5F5F5"
-textColor="#0A2C37"
-font="sans serif"
diff --git a/.streamlit/credentials.toml b/.streamlit/credentials.toml
deleted file mode 100644
index b87ca415..00000000
--- a/.streamlit/credentials.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-[general]
-email=""
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..abcceb27
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,13 @@
+version: '3.8'
+services:
+ ollama:
+ image: ollama/ollama
+ container_name: ollama
+ ports:
+ - "11434:11434"
+ volumes:
+ - ollama_volume:/root/.ollama
+ restart: unless-stopped
+
+volumes:
+ ollama_volume:
diff --git a/examples/graph_evaluation_example.py b/examples/graph_evaluation_example.py
deleted file mode 100644
index f5970de7..00000000
--- a/examples/graph_evaluation_example.py
+++ /dev/null
@@ -1,43 +0,0 @@
-"""
-Module for evaluating the graph
-"""
-import os
-from dotenv import load_dotenv
-from scrapegraphai.evaluators import TrulensEvaluator
-
-load_dotenv()
-openai_key = os.getenv("OPENAI_APIKEY")
-
-# Define the configuration for the graph
-graph_config = {
- "llm": {
- "api_key": openai_key,
- "model": "gpt-3.5-turbo",
- },
-}
-
-list_of_inputs = [
- (
- "List me all the titles and project descriptions",
- "https://perinim.github.io/projects/",
- graph_config
- ),
- (
- "Who is the author of the project?",
- "https://perinim.github.io/projects/",
- graph_config
- ),
- (
- "What are the projects about?",
- "https://perinim.github.io/projects/",
- graph_config
- ),
-]
-
-# Create the TrulensEvaluator instance
-trulens_evaluator = TrulensEvaluator(graph_config["llm"]["api_key"])
-# Evaluate SmartScraperGraph on the list of inputs
-(results_df, answer) = trulens_evaluator.evaluate(
- list_of_inputs, dashboard=True)
-
-print(answer)
diff --git a/examples/ollama-example.py b/examples/ollama-example.py
new file mode 100644
index 00000000..2b7e79a5
--- /dev/null
+++ b/examples/ollama-example.py
@@ -0,0 +1,7 @@
+from langchain_community.llms import Ollama
+
+llm = Ollama(model="llama2")
+
+answer = llm.invoke("Tell me a joke")
+
+print(answer)
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 7f53d3aa..28d73018 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -30,7 +30,6 @@ langchain_google_genai = "0.0.11"
html2text = "2020.1.16"
faiss-cpu = "1.7.4"
beautifulsoup4 = "4.12.3"
-trulens_eval = "0.23.0"
pandas = "2.0.3"
python-dotenv = "1.0.1"
tiktoken = {version = ">=0.5.2,<0.6.0"}
diff --git a/requirements.txt b/requirements.txt
index 3f387f1a..3197e199 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,4 +10,3 @@ pandas==2.0.3
python-dotenv==1.0.1
tiktoken>=0.5.2,<0.6.0
tqdm==4.66.1
-trulens_eval==0.23.0
diff --git a/scrapegraphai/evaluators/__init__.py b/scrapegraphai/evaluators/__init__.py
deleted file mode 100644
index 98d738f2..00000000
--- a/scrapegraphai/evaluators/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-"""
-__init__.py file for evaluetor folder
-"""
-from .trulens_evaluator import TrulensEvaluator
diff --git a/scrapegraphai/evaluators/trulens_evaluator.py b/scrapegraphai/evaluators/trulens_evaluator.py
deleted file mode 100644
index d6011a95..00000000
--- a/scrapegraphai/evaluators/trulens_evaluator.py
+++ /dev/null
@@ -1,88 +0,0 @@
-"""Module for making the RAG"""
-from trulens_eval import Feedback, OpenAI, Tru, Provider, Select, TruBasicApp
-from scrapegraphai.graphs import SmartScraperGraph
-
-
-class TrulensEvaluator:
- """
- Class for evaluating Trulens using SmartScraperGraph.
-
- Attributes:
-
- tru_llm_standalone_recorder: TruBasicApp instance for recording.
-
- Methods:
- evaluate: Evaluates Trulens using SmartScraperGraph.
- llm_standalone: Standalone function for Trulens evaluation.
- """
-
- def __init__(self, key: str):
- """
- Initialization of the class
- Arguments:
- - key (str): openai key
- """
- standalone = StandAlone()
- self.f_custom_function = Feedback(standalone.json_complaint).on(
- my_text_field=Select.RecordOutput
- )
- self.tru = Tru()
- self.tru.reset_database()
- self.openai = OpenAI(api_key=key)
- self.f_relevance = Feedback(self.openai.relevance).on_input_output()
- self.tru_llm_standalone_recorder = TruBasicApp(self.llm_standalone,
- app_id="smart_scraper_evaluator",
- feedbacks=[self.f_relevance,
- self.f_custom_function])
- self.graph_output = []
-
- def evaluate(self, graph_params: list[tuple[str, str, dict]], dashboard: bool = True):
- """
- Evaluates Trulens using SmartScraperGraph and starts the dashboard.
-
- Args:
- graph_params: List of tuples containing graph parameters.
-
- Returns:
- None
- """
-
- with self.tru_llm_standalone_recorder as recording:
- for params in graph_params:
- output = SmartScraperGraph(*params).run()
- self.tru_llm_standalone_recorder.app(params[0], output)
- self.graph_output.append(output)
-
- if dashboard:
- self.tru.run_dashboard()
-
- return (self.tru.get_records_and_feedback(app_ids=[])[0], self.graph_output)
-
- def llm_standalone(self, prompt, response):
- """
- Standalone function for Trulens evaluation. Private method.
-
- Args:
- prompt: Prompt for evaluation.
- response: Response from evaluation.
-
- Returns:
- str: Response as a string.
- """
- print(f"Prompt: {prompt}")
- return str(response)
-
-
-class StandAlone(Provider):
- """
- Class for standalone Trulens evaluation.
- """
-
- def json_complaint(self, my_text_field: str) -> float:
- """
- Args:
- - my_text_field (str): textfield
- """
- if '{' in my_text_field and '}' in my_text_field and ':' in my_text_field:
- return 1.0
- return 0.0
diff --git a/scrapegraphai/graphs/search_graph.py b/scrapegraphai/graphs/search_graph.py
index c5f3a6a5..88c3fc4d 100644
--- a/scrapegraphai/graphs/search_graph.py
+++ b/scrapegraphai/graphs/search_graph.py
@@ -1,7 +1,7 @@
"""
Module for making the search on the intenet
"""
-from ..models import OpenAI, Gemini
+from ..models import OpenAI, Gemini, Ollama
from .base_graph import BaseGraph
from ..nodes import (
SearchInternetNode,
@@ -33,6 +33,8 @@ class SearchGraph(AbstractGraph):
return OpenAI(llm_params)
elif "gemini" in llm_params["model"]:
return Gemini(llm_params)
+ elif "llama2" in llm_params["model"]:
+ return Ollama(llm_params)
else:
raise ValueError("Model not supported")
diff --git a/scrapegraphai/models/__init__.py b/scrapegraphai/models/__init__.py
index 985a9153..4d2d9134 100644
--- a/scrapegraphai/models/__init__.py
+++ b/scrapegraphai/models/__init__.py
@@ -6,3 +6,4 @@ from .openai import OpenAI
from .openai_itt import OpenAIImageToText
from .openai_tts import OpenAITextToSpeech
from .gemini import Gemini
+from .ollama import Ollama
diff --git a/scrapegraphai/models/ollama.py b/scrapegraphai/models/ollama.py
new file mode 100644
index 00000000..9636a257
--- /dev/null
+++ b/scrapegraphai/models/ollama.py
@@ -0,0 +1,19 @@
+"""
+openai configuration wrapper
+"""
+from langchain_community.chat_models import ChatOllama
+
+
+class Ollama(ChatOllama):
+ """Class for wrapping ollama module"""
+
+ def __init__(self, llm_config: dict):
+ """
+ A wrapper for the ChatOllama class that provides default configuration
+ and could be extended with additional methods if needed.
+
+ Args:
+ llm_config (dict): Configuration parameters for the language model.
+ """
+ # Initialize the superclass (ChatOllama) with provided config parameters
+ super().__init__(**llm_config)
diff --git a/scrapegraphai/nodes/search_internet_node.py b/scrapegraphai/nodes/search_internet_node.py
index 88297c1d..2d49b8f6 100644
--- a/scrapegraphai/nodes/search_internet_node.py
+++ b/scrapegraphai/nodes/search_internet_node.py
@@ -82,7 +82,8 @@ class SearchInternetNode(BaseNode):
search_template = """Given the following user prompt, return a query that can be
used to search the internet for relevant information. \n
- You should return only the query string. \n
+ You should return only the query string without any additional sentences. \n
+ You are taught to reply directly giving the search query. \n
User Prompt: {user_prompt}"""
search_prompt = PromptTemplate(