Skip to content

Commit b16dab6

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/add-more-evaluation
2 parents 3711479 + 2bcc135 commit b16dab6

File tree

8 files changed

+259
-12
lines changed

8 files changed

+259
-12
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Production LLM-COMPLETE
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- 'llm-complete-guide/**'
8+
concurrency:
9+
# New commit on branch cancels running workflows of the same branch
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
run-staging-workflow:
15+
runs-on: ubuntu-latest
16+
env:
17+
ZENML_HOST: ${{ secrets.ZENML_HOST }}
18+
ZENML_API_KEY: ${{ secrets.ZENML_API_KEY }}
19+
ZENML_PRODUCTION_STACK : 51a49786-b82a-4646-bde7-a460efb0a9c5
20+
ZENML_GITHUB_SHA: ${{ github.event.pull_request.head.sha }}
21+
ZENML_GITHUB_URL_PR: ${{ github.event.pull_request._links.html.href }}
22+
ZENML_DEBUG: true
23+
ZENML_ANALYTICS_OPT_IN: false
24+
ZENML_LOGGING_VERBOSITY: INFO
25+
ZENML_PROJECT_SECRET_NAME: llm-complete
26+
ZENML_DISABLE_CLIENT_SERVER_MISMATCH_WARNING: True
27+
ZENML_ACTION_ID: 23a4d58c-bd2b-47d5-a41d-0a845d2982f8
28+
29+
steps:
30+
- name: Check out repository code
31+
uses: actions/checkout@v3
32+
33+
- uses: actions/setup-python@v4
34+
with:
35+
python-version: '3.11'
36+
37+
- name: Install requirements
38+
working-directory: ./llm-complete-guide
39+
run: |
40+
pip3 install -r requirements.txt
41+
pip3 install -r requirements-argilla.txt
42+
zenml integration install gcp -y
43+
44+
- name: Connect to ZenML server
45+
working-directory: ./llm-complete-guide
46+
run: |
47+
zenml init
48+
zenml connect --url $ZENML_HOST --api-key $ZENML_API_KEY
49+
50+
- name: Set stack (Production)
51+
working-directory: ./llm-complete-guide
52+
run: |
53+
zenml stack set ${{ env.ZENML_PRODUCTION_STACK }}
54+
55+
- name: Run pipeline, create pipeline, configure trigger (Production)
56+
working-directory: ./llm-complete-guide
57+
run: |
58+
python gh_action_rag.py --no-cache --create-template --action-id ${{ env.ZENML_ACTION_ID }} --config rag_gcp.yaml

.github/workflows/run_complete_llm.yml renamed to .github/workflows/staging_run_complete_llm.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ concurrency:
1010

1111
jobs:
1212
run-staging-workflow:
13+
runs-on: ubuntu-latest
1314
env:
1415
ZENML_HOST: ${{ secrets.ZENML_HOST }}
1516
ZENML_API_KEY: ${{ secrets.ZENML_API_KEY }}
@@ -20,6 +21,7 @@ jobs:
2021
ZENML_ANALYTICS_OPT_IN: false
2122
ZENML_LOGGING_VERBOSITY: INFO
2223
ZENML_PROJECT_SECRET_NAME: llm-complete
24+
ZENML_DISABLE_CLIENT_SERVER_MISMATCH_WARNING: True
2325

2426
steps:
2527
- name: Check out repository code
@@ -30,20 +32,24 @@ jobs:
3032
python-version: '3.11'
3133

3234
- name: Install requirements
35+
working-directory: ./llm-complete-guide
3336
run: |
3437
pip3 install -r requirements.txt
38+
pip3 install -r requirements-argilla.txt
3539
zenml integration install gcp -y
3640
3741
- name: Connect to ZenML server
42+
working-directory: ./llm-complete-guide
3843
run: |
44+
zenml init
3945
zenml connect --url $ZENML_HOST --api-key $ZENML_API_KEY
4046
4147
- name: Set stack (Staging)
42-
if: ${{ github.base_ref == 'staging' }}
48+
working-directory: ./llm-complete-guide
4349
run: |
4450
zenml stack set ${{ env.ZENML_STAGING_STACK }}
4551
4652
- name: Run pipeline (Staging)
47-
if: ${{ github.base_ref == 'staging' }}
53+
working-directory: ./llm-complete-guide
4854
run: |
49-
python run.py --rag --evaluation --no-cache
55+
python gh_action_rag.py --no-cache --config rag_gcp.yaml

llm-complete-guide/configs/rag_gcp.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ settings:
1111
- psycopg2-binary
1212
- tiktoken
1313
- ratelimit
14+
- rerankers
1415
environment:
1516
ZENML_PROJECT_SECRET_NAME: llm_complete
1617
ZENML_ENABLE_RICH_TRACEBACK: FALSE
@@ -20,13 +21,16 @@ steps:
2021
url_scraper:
2122
parameters:
2223
docs_url: https://docs.zenml.io
23-
generate_embeddings:
24-
step_operator: "terraform-gcp-6c0fd52233ca"
25-
settings:
26-
step_operator.vertex:
27-
accelerator_type: "NVIDIA_TESLA_P100"
28-
accelerator_count: 1
29-
machine_type: "n1-standard-8"
24+
repo_url: https://github.com/zenml-io/zenml
25+
website_url: https://zenml.io
26+
27+
# generate_embeddings:
28+
# step_operator: "terraform-gcp-6c0fd52233ca"
29+
# settings:
30+
# step_operator.vertex:
31+
# accelerator_type: "NVIDIA_TESLA_P100"
32+
# accelerator_count: 1
33+
# machine_type: "n1-standard-8"
3034

3135
# configuration of the Model Control Plane
3236
model:

llm-complete-guide/configs/rag_local_dev.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ settings:
1313
- psycopg2-binary
1414
- tiktoken
1515
- ratelimit
16+
- rerankers
1617
environment:
1718
ZENML_PROJECT_SECRET_NAME: llm_complete
1819
ZENML_ENABLE_RICH_TRACEBACK: FALSE
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Apache Software License 2.0
2+
#
3+
# Copyright (c) ZenML GmbH 2024. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
import json
18+
from datetime import datetime
19+
from pathlib import Path
20+
from typing import Optional
21+
from uuid import UUID
22+
23+
import click
24+
import yaml
25+
from zenml.client import Client
26+
27+
from pipelines.llm_basic_rag import llm_basic_rag
28+
29+
30+
@click.command(
31+
help="""
32+
ZenML LLM Complete - Rag Pipeline
33+
"""
34+
)
35+
@click.option(
36+
"--no-cache",
37+
"no_cache",
38+
is_flag=True,
39+
default=False,
40+
help="Disable cache.",
41+
)
42+
43+
@click.option(
44+
"--create-template",
45+
"create_template",
46+
is_flag=True,
47+
default=False,
48+
help="Create a run template.",
49+
)
50+
@click.option(
51+
"--config",
52+
"config",
53+
default="rag_local_dev.yaml",
54+
help="Specify a configuration file"
55+
)
56+
@click.option(
57+
"--action-id",
58+
"action_id",
59+
default=None,
60+
help="Specify an action ID"
61+
)
62+
def main(
63+
no_cache: bool = False,
64+
config: Optional[str]= "rag_local_dev.yaml",
65+
create_template: bool = False,
66+
action_id: Optional[str] = None
67+
):
68+
"""
69+
Executes the pipeline to train a basic RAG model.
70+
71+
Args:
72+
no_cache (bool): If `True`, cache will be disabled.
73+
config (str): The path to the configuration file.
74+
create_template (bool): If `True`, a run template will be created.
75+
action_id (str): The action ID.
76+
"""
77+
client = Client()
78+
config_path = Path(__file__).parent / "configs" / config
79+
80+
with (open(config_path,"r") as file):
81+
config = yaml.safe_load(file)
82+
83+
if create_template:
84+
# run pipeline
85+
run = llm_basic_rag.with_options(
86+
config_path=str(config_path),
87+
enable_cache=not no_cache
88+
)()
89+
# create new run template
90+
rt = client.create_run_template(
91+
name=f"production-llm-complete-{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}",
92+
deployment_id=run.deployment_id
93+
)
94+
# update the action with the new template
95+
client.update_action(
96+
name_id_or_prefix=UUID(action_id),
97+
configuration={
98+
"template_id": str(rt.id),
99+
"run_config": pop_restricted_configs(config)
100+
}
101+
)
102+
103+
else:
104+
llm_basic_rag.with_options(
105+
config_path=str(config_path),
106+
enable_cache=not no_cache
107+
)()
108+
109+
110+
def pop_restricted_configs(run_configuration: dict) -> dict:
111+
"""Removes restricted configuration items from a run configuration dictionary.
112+
113+
Args:
114+
run_configuration: Dictionary containing run configuration settings
115+
116+
Returns:
117+
Modified dictionary with restricted items removed
118+
"""
119+
# Pop top-level restricted items
120+
run_configuration.pop('parameters', None)
121+
run_configuration.pop('build', None)
122+
run_configuration.pop('schedule', None)
123+
124+
# Pop docker settings if they exist
125+
if 'settings' in run_configuration:
126+
run_configuration['settings'].pop('docker', None)
127+
128+
# Pop docker settings from steps if they exist
129+
if 'steps' in run_configuration:
130+
for step in run_configuration['steps'].values():
131+
if 'settings' in step:
132+
step['settings'].pop('docker', None)
133+
134+
return run_configuration
135+
136+
if __name__ == "__main__":
137+
main()

llm-complete-guide/pipelines/llm_basic_rag.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
# limitations under the License.
1616
#
1717

18+
from zenml import pipeline
19+
1820
from steps.populate_index import (
1921
generate_embeddings,
2022
index_generator,
2123
preprocess_documents,
2224
)
2325
from steps.url_scraper import url_scraper
2426
from steps.web_url_loader import web_url_loader
25-
from zenml import pipeline
2627

2728

2829
@pipeline

llm-complete-guide/pipelines/llm_eval.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16+
import os
17+
from pathlib import Path
18+
from typing import Optional
19+
20+
import click
1621

1722
from steps.eval_e2e import e2e_evaluation, e2e_evaluation_llm_judged
1823
from steps.eval_retrieval import (
@@ -64,3 +69,39 @@ def llm_eval() -> None:
6469
average_helpfulness_score,
6570
average_relevance_score,
6671
)
72+
73+
74+
@click.option(
75+
"--no-cache",
76+
"no_cache",
77+
is_flag=True,
78+
default=False,
79+
help="Disable cache.",
80+
)
81+
@click.option(
82+
"--config",
83+
"config",
84+
default="rag_local_dev.yaml",
85+
help="Specify a configuration file"
86+
)
87+
def main(
88+
no_cache: bool = False,
89+
config: Optional[str] = "rag_eval.yaml"
90+
):
91+
"""
92+
Executes the pipeline to train a basic RAG model.
93+
94+
Args:
95+
no_cache (bool): If `True`, cache will be disabled.
96+
config (str): The path to the configuration file.
97+
"""
98+
config_path = Path(__file__).parent.parent / "configs" / config
99+
100+
llm_eval.with_options(
101+
config_path=str(config_path),
102+
enable_cache=not no_cache
103+
)()
104+
105+
106+
if __name__ == "__main__":
107+
main()

llm-complete-guide/run.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ def main(
208208
rag_deployment.with_options(
209209
config_path=config_path, **pipeline_args
210210
)()
211-
212211
if deploy:
213212
rag_deployment.with_options(**pipeline_args)()
214213
if evaluation:

0 commit comments

Comments
 (0)