Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
49f02a3
fix url scraper
strickvl Jan 31, 2025
c51ab4a
update requirements
strickvl Jan 31, 2025
0bec7d4
fix outdated code
strickvl Jan 31, 2025
a7105fb
Update ZenML model version and fix vector store metadata access
strickvl Jan 31, 2025
22291fd
Upgrade ZenML requirement to version 0.73.0
strickvl Jan 31, 2025
5b392fe
Change default index type to Postgres in index generator
strickvl Jan 31, 2025
7b23505
update constants
strickvl Jan 31, 2025
38a5b7c
Add log_metadata import from ZenML in evaluation step
strickvl Jan 31, 2025
f66335e
Suppress FutureWarning and refactor logging in eval and index steps
strickvl Jan 31, 2025
85fb182
formatting
strickvl Jan 31, 2025
4261dc5
run evals in parallel
strickvl Jan 31, 2025
90907f3
Add tenacity to requirements for improved retry handling
strickvl Jan 31, 2025
b82f6cf
run tests in parallel
strickvl Jan 31, 2025
4e2aaa3
Add LLM-judged evaluation function for RAG tests
strickvl Jan 31, 2025
969faa8
Add metadata logging for comprehensive evaluation metrics
strickvl Jan 31, 2025
7100c07
Clean up imports and remove unused imports in evaluation steps
strickvl Jan 31, 2025
31403b2
Remove commented section in RAG configuration file
strickvl Jan 31, 2025
35f6634
Adjust default temperature for OpenAI model completion
strickvl Jan 31, 2025
af301c6
make query via CLI work again
strickvl Jan 31, 2025
da289e2
Update deployment command in README for simplified RAG pipeline deplo…
strickvl Jan 31, 2025
6759c4a
Add type safety for ZenML secrets in Hugging Face deployment
strickvl Jan 31, 2025
ca00f7f
Add Elasticsearch and Tenacity to project requirements
strickvl Jan 31, 2025
fff3b36
Update ZenML chatbot model constants and improve vector store retrieval
strickvl Jan 31, 2025
bf2270d
Fix deployment :)
strickvl Jan 31, 2025
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
10 changes: 2 additions & 8 deletions llm-complete-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use for the LLM.
When you're ready to make the query, run the following command:

```shell
python run.py query "how do I use a custom materializer inside my own zenml steps? i.e. how do I set it? inside the @step decorator?" --model=gpt4
python run.py query --query-text "how do I use a custom materializer inside my own zenml steps? i.e. how do I set it? inside the @step decorator?" --model=gpt4
```

Alternative options for LLMs to use include:
Expand Down Expand Up @@ -147,13 +147,7 @@ export ZENML_HF_SPACE_NAME=<YOUR_HF_SPACE_NAME> # optional, defaults to "llm-com
To deploy the RAG pipeline, you can use the following command:

```shell
python run.py --deploy
```

Alternatively, you can run the basic RAG pipeline *and* deploy it in one go:

```shell
python run.py --rag --deploy
python run.py deploy
```

This will open a Hugging Face space in your browser where you can interact with
Expand Down
1 change: 0 additions & 1 deletion llm-complete-guide/configs/dev/rag.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
enable_cache: False

# environment configuration
settings:
docker:
requirements:
Expand Down
6 changes: 3 additions & 3 deletions llm-complete-guide/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import os

# Vector Store constants
CHUNK_SIZE = 2000
CHUNK_SIZE = 1000
CHUNK_OVERLAP = 50
EMBEDDING_DIMENSIONALITY = (
384 # Update this to match the dimensionality of the new model
Expand All @@ -35,8 +35,8 @@
MODEL_NAME_MAP = {
"gpt4": "gpt-4",
"gpt35": "gpt-3.5-turbo",
"claude3": "claude-3-opus-20240229",
"claudehaiku": "claude-3-haiku-20240307",
"claude3": "claude-3-5-sonnet-latest",
"claudehaiku": "claude-3-5-haiku-latest",
}

# CHUNKING_METHOD = "split-by-document"
Expand Down
14 changes: 6 additions & 8 deletions llm-complete-guide/gh_action_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

import click
import yaml
from zenml.enums import PluginSubType

from pipelines.llm_index_and_evaluate import llm_index_and_evaluate
from zenml.client import Client
from zenml import Model
from zenml.exceptions import ZenKeyError
from zenml.client import Client
from zenml.enums import PluginSubType


@click.command(
Expand Down Expand Up @@ -89,7 +87,7 @@ def main(
zenml_model_name: Optional[str] = "zenml-docs-qa-rag",
zenml_model_version: Optional[str] = None,
):
"""
"""
Executes the pipeline to train a basic RAG model.

Args:
Expand All @@ -108,14 +106,14 @@ def main(
config = yaml.safe_load(file)

# Read the model version from a file in the root of the repo
# called "ZENML_VERSION.txt".
# called "ZENML_VERSION.txt".
if zenml_model_version == "staging":
postfix = "-rc0"
elif zenml_model_version == "production":
postfix = ""
else:
postfix = "-dev"

if Path("ZENML_VERSION.txt").exists():
with open("ZENML_VERSION.txt", "r") as file:
zenml_model_version = file.read().strip()
Expand Down Expand Up @@ -177,7 +175,7 @@ def main(
service_account_id=service_account_id,
auth_window=0,
flavor="builtin",
action_type=PluginSubType.PIPELINE_RUN
action_type=PluginSubType.PIPELINE_RUN,
).id
client.create_trigger(
name="Production Trigger LLM-Complete",
Expand Down
2 changes: 1 addition & 1 deletion llm-complete-guide/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
from pipelines.generate_chunk_questions import generate_chunk_questions
from pipelines.llm_basic_rag import llm_basic_rag
from pipelines.llm_eval import llm_eval
from pipelines.llm_index_and_evaluate import llm_index_and_evaluate
from pipelines.rag_deployment import rag_deployment
from pipelines.llm_index_and_evaluate import llm_index_and_evaluate
1 change: 0 additions & 1 deletion llm-complete-guide/pipelines/finetune_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# or implied. See the License for the specific language governing
# permissions and limitations under the License.

from constants import EMBEDDINGS_MODEL_NAME_ZENML
from steps.finetune_embeddings import (
evaluate_base_model,
evaluate_finetuned_model,
Expand Down
1 change: 0 additions & 1 deletion llm-complete-guide/pipelines/llm_basic_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from litellm import config_path

from steps.populate_index import (
generate_embeddings,
Expand Down
3 changes: 2 additions & 1 deletion llm-complete-guide/pipelines/llm_index_and_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# limitations under the License.
#

from pipelines import llm_basic_rag, llm_eval
from zenml import pipeline

from pipelines import llm_basic_rag, llm_eval


@pipeline
def llm_index_and_evaluate() -> None:
Expand Down
3 changes: 2 additions & 1 deletion llm-complete-guide/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
zenml[server]
zenml[server]>=0.73.0
ratelimit
pgvector
psycopg2-binary
Expand All @@ -21,6 +21,7 @@ torch
gradio
huggingface-hub
elasticsearch
tenacity

# optional requirements for S3 artifact store
# s3fs>2022.3.0
Expand Down
18 changes: 13 additions & 5 deletions llm-complete-guide/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
generate_synthetic_data,
llm_basic_rag,
llm_eval,
rag_deployment,
llm_index_and_evaluate,
rag_deployment,
)
from structures import Document
from zenml.materializers.materializer_registry import materializer_registry
from zenml import Model
from zenml.materializers.materializer_registry import materializer_registry

logger = get_logger(__name__)

Expand Down Expand Up @@ -136,6 +136,12 @@
default=None,
help="Path to config",
)
@click.option(
"--query-text",
"query_text",
default=None,
help="Query text",
)
def main(
pipeline: str,
query_text: Optional[str] = None,
Expand Down Expand Up @@ -169,9 +175,9 @@ def main(
}
},
}

# Read the model version from a file in the root of the repo
# called "ZENML_VERSION.txt".
# called "ZENML_VERSION.txt".
if zenml_model_version == "staging":
postfix = "-rc0"
elif zenml_model_version == "production":
Expand Down Expand Up @@ -264,7 +270,9 @@ def main(

elif pipeline == "embeddings":
finetune_embeddings.with_options(
model=zenml_model, config_path=config_path, **embeddings_finetune_args
model=zenml_model,
config_path=config_path,
**embeddings_finetune_args,
)()

elif pipeline == "chunks":
Expand Down
35 changes: 20 additions & 15 deletions llm-complete-guide/steps/eval_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,17 @@

import json
import logging
import warnings
from typing import Annotated, Callable, Tuple

# Suppress the specific FutureWarning about clean_up_tokenization_spaces
warnings.filterwarnings(
"ignore",
message=".*clean_up_tokenization_spaces.*",
category=FutureWarning,
module="transformers.tokenization_utils_base",
)

from datasets import load_dataset
from litellm import completion
from pydantic import BaseModel, conint
Expand Down Expand Up @@ -315,13 +324,11 @@ def run_simple_tests(test_data: list, test_function: Callable) -> float:


@step
def e2e_evaluation() -> (
Tuple[
Annotated[float, "failure_rate_bad_answers"],
Annotated[float, "failure_rate_bad_immediate_responses"],
Annotated[float, "failure_rate_good_responses"],
]
):
def e2e_evaluation() -> Tuple[
Annotated[float, "failure_rate_bad_answers"],
Annotated[float, "failure_rate_bad_immediate_responses"],
Annotated[float, "failure_rate_good_responses"],
]:
"""Executes the end-to-end evaluation step."""
logging.info("Testing bad answers...")
failure_rate_bad_answers = run_simple_tests(
Expand Down Expand Up @@ -352,14 +359,12 @@ def e2e_evaluation() -> (


@step
def e2e_evaluation_llm_judged() -> (
Tuple[
Annotated[float, "average_toxicity_score"],
Annotated[float, "average_faithfulness_score"],
Annotated[float, "average_helpfulness_score"],
Annotated[float, "average_relevance_score"],
]
):
def e2e_evaluation_llm_judged() -> Tuple[
Annotated[float, "average_toxicity_score"],
Annotated[float, "average_faithfulness_score"],
Annotated[float, "average_helpfulness_score"],
Annotated[float, "average_relevance_score"],
]:
"""Executes the end-to-end evaluation step.

Returns:
Expand Down
Loading
Loading