Skip to content

Commit 5c40088

Browse files
authored
Feature/update complete llm (#140)
* Removed new-line * Fixed github action * Fixed workflow * Fixed github action * Ignore server mismatch * Ignore server mismatch * Added all requirements * Fixed gh action * More fine grained control over configs * Added defaults * fixed config path * Automate trigger update
1 parent e82b37b commit 5c40088

File tree

8 files changed

+225
-12
lines changed

8 files changed

+225
-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 scripts/gh_action_rag.py --no-cache --create-template --action-id ${{ env.ZENML_ACTION_ID }}

.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 scripts/gh_action_rag.py --no-cache

llm-complete-guide/configs/rag_gcp.yaml

Lines changed: 8 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,13 @@ 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+
# generate_embeddings:
25+
# step_operator: "terraform-gcp-6c0fd52233ca"
26+
# settings:
27+
# step_operator.vertex:
28+
# accelerator_type: "NVIDIA_TESLA_P100"
29+
# accelerator_count: 1
30+
# machine_type: "n1-standard-8"
3031

3132
# configuration of the Model Control Plane
3233
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

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:
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
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+
from zenml.client import Client
25+
26+
from pipelines import llm_basic_rag
27+
28+
29+
@click.command(
30+
help="""
31+
ZenML LLM Complete - Rag Pipeline
32+
"""
33+
)
34+
@click.option(
35+
"--no-cache",
36+
"no_cache",
37+
is_flag=True,
38+
default=False,
39+
help="Disable cache.",
40+
)
41+
42+
@click.option(
43+
"--create-template",
44+
"create_template",
45+
is_flag=True,
46+
default=False,
47+
help="Create a run template.",
48+
)
49+
@click.option(
50+
"--config",
51+
"config",
52+
default="rag_local_dev.yaml",
53+
help="Specify a configuration file"
54+
)
55+
@click.option(
56+
"--action-id",
57+
"action_id",
58+
default=None,
59+
help="Specify an action ID"
60+
)
61+
def main(
62+
no_cache: bool = False,
63+
config: Optional[str]= "rag_local_dev.yaml",
64+
create_template: bool = False,
65+
action_id: Optional[str] = None
66+
):
67+
"""
68+
Executes the pipeline to train a basic RAG model.
69+
70+
Args:
71+
no_cache (bool): If `True`, cache will be disabled.
72+
config (str): The path to the configuration file.
73+
create_template (bool): If `True`, a run template will be created.
74+
action_id (str): The action ID.
75+
"""
76+
client = Client()
77+
config_path = Path(__file__).parent.parent / "configs" / config
78+
79+
if create_template:
80+
# run pipeline
81+
run = llm_basic_rag.with_options(
82+
config_path=str(config_path),
83+
enable_cache=not no_cache
84+
)()
85+
# create new run template
86+
rt = client.create_run_template(
87+
name=f"production-llm-complete-{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}",
88+
deployment_id=run.deployment_id
89+
)
90+
# update the action with the new template
91+
client.update_action(
92+
name_id_or_prefix=UUID(action_id),
93+
configuration={
94+
"template_id": str(rt.id)
95+
}
96+
)
97+
98+
else:
99+
llm_basic_rag.with_options(
100+
config_path=str(config_path),
101+
enable_cache=not no_cache
102+
)()
103+
104+
105+
if __name__ == "__main__":
106+
main()

0 commit comments

Comments
 (0)