Skip to content

Commit

Permalink
Merge branch 'dev' into feat/granite-modelcar-image
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarrata authored Oct 1, 2024
2 parents 04b0b57 + 057f210 commit 10006a2
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ spec:
WORKBENCH_NAME="my-workbench"
WORKBENCH_IMAGE="ic-workbench:1.2"
PIPELINE_ENGINE="Argo"
BRANCH_NAME="dev"
for i in $(seq 1 $user_count);
do
Expand Down Expand Up @@ -527,7 +528,7 @@ spec:
args:
- -ec
- |-
pod_name=\$(oc get pods --selector=app=$WORKBENCH_NAME -o jsonpath='{.items[0].metadata.name}') && oc exec \$pod_name -- git clone https://github.com/rh-aiservices-bu/parasol-insurance
pod_name=\$(oc get pods --selector=app=$WORKBENCH_NAME -o jsonpath='{.items[0].metadata.name}') && oc exec \$pod_name -- bash -c "git clone https://github.com/rh-aiservices-bu/parasol-insurance && cd parasol-insurance && git checkout $BRANCH_NAME"
restartPolicy: Never
EOF
Expand Down
18 changes: 8 additions & 10 deletions lab-materials/03/06/llm_usage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from langchain.llms import VLLMOpenAI
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.evaluation import load_evaluator
from langchain.embeddings import HuggingFaceEmbeddings
from langchain_huggingface import HuggingFaceEmbeddings
from langchain.prompts import PromptTemplate
from langchain_community.llms import VLLMOpenAI

INFERENCE_SERVER_URL = "http://llm.ic-shared-llm.svc.cluster.local:8000"
INFERENCE_SERVER_URL = "http://granite-7b-instruct-predictor.ic-shared-llm.svc.cluster.local:8080"
MAX_NEW_TOKENS = 512
TOP_P = 0.95
TEMPERATURE = 0.01
Expand All @@ -15,7 +13,7 @@ def infer_with_template(input_text, template):
llm = VLLMOpenAI(
openai_api_key="EMPTY",
openai_api_base= f"{INFERENCE_SERVER_URL}/v1",
model_name="mistralai/Mistral-7B-Instruct-v0.2",
model_name="granite-7b-instruct",
max_tokens=MAX_NEW_TOKENS,
top_p=TOP_P,
temperature=TEMPERATURE,
Expand All @@ -24,11 +22,11 @@ def infer_with_template(input_text, template):
verbose=False,
)

PROMPT = PromptTemplate.from_template(template)
prompt = PromptTemplate(input_variables=["car_claim"], template=template)

llm_chain = LLMChain(llm=llm, prompt=PROMPT)
conversation = prompt | llm

return llm_chain.run(input_text)
return conversation.invoke(input=input_text)

def similarity_metric(predicted_text, reference_text):
embedding_model = HuggingFaceEmbeddings()
Expand Down
10 changes: 7 additions & 3 deletions lab-materials/03/06/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
langchain==0.0.340
langchain==0.3.1
langchain-community==0.3.1
langchain-core==0.3.6
langchain-huggingface==0.1.0
langchain-text-splitters==0.3.0
text_generation==0.6.1
sentence_transformers==2.2.2
openai==1.13.3
sentence-transformers==3.1.1
openai==1.47.1
2 changes: 2 additions & 0 deletions lab-materials/03/06/summary_template.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<s>[INST] <<SYS>>
Summarize the below car insurance claim:
<</SYS>>
### TEXT:
{car_claim}
### ANSWER:
[/INST]
2 changes: 2 additions & 0 deletions lab-materials/03/06/test_responsetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def test_responsetime():
TEMPLATE = """<s>[INST] <<SYS>>
Answer below truthfully and in less than 10 words:
<</SYS>>
### QUESTION:
{silly_question}
### ANSWER:
[/INST]"""

start = time.perf_counter()
Expand Down
2 changes: 1 addition & 1 deletion lab-materials/03/06/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def test_security(endpoint, expected_id,):
}, f)

if __name__ == '__main__':
info_endpoint = "http://llm.ic-shared-llm.svc.cluster.local:8000" + "/v1/models"
info_endpoint = "http://granite-7b-instruct-predictor.ic-shared-llm.svc.cluster.local:8080" + "/v1/models"
expected_id = "modelperm" #This is just for the demo, in a real scenario you would input the model id here
test_security(info_endpoint, expected_id)
12 changes: 8 additions & 4 deletions lab-materials/05/05-05/container/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
langchain==0.0.340
langchain==0.3.1
langchain-community==0.3.1
langchain-core==0.3.6
langchain-huggingface==0.1.0
langchain-text-splitters==0.3.0
text_generation==0.6.1
sentence_transformers==2.2.2
sentence-transformers==3.1.1
openai==1.47.1
opencv-python-headless==4.8.1.78
python-dotenv==1.0.0
psycopg2-binary==2.9.9
boto3==1.26.165
openai==1.13.3
boto3==1.26.165
21 changes: 9 additions & 12 deletions lab-materials/05/05-05/llm_usage.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os

from langchain.llms import VLLMOpenAI
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.evaluation import load_evaluator
from langchain.embeddings import HuggingFaceEmbeddings
from langchain_huggingface import HuggingFaceEmbeddings
from langchain.prompts import PromptTemplate
from langchain_community.llms import VLLMOpenAI


INFERENCE_SERVER_URL = "http://llm.ic-shared-llm.svc.cluster.local:8000"
INFERENCE_SERVER_URL = "http://granite-7b-instruct-predictor.ic-shared-llm.svc.cluster.local:8080"
MAX_NEW_TOKENS = 512
TOP_P = 0.95
TEMPERATURE = 0.01
Expand All @@ -17,7 +14,7 @@ def infer_with_template(input_text, template):
llm = VLLMOpenAI(
openai_api_key="EMPTY",
openai_api_base= f"{INFERENCE_SERVER_URL}/v1",
model_name="mistralai/Mistral-7B-Instruct-v0.2",
model_name="granite-7b-instruct",
max_tokens=MAX_NEW_TOKENS,
top_p=TOP_P,
temperature=TEMPERATURE,
Expand All @@ -26,11 +23,11 @@ def infer_with_template(input_text, template):
verbose=False,
)

PROMPT = PromptTemplate.from_template(template)
prompt = PromptTemplate(input_variables=["car_claim"], template=template)

llm_chain = LLMChain(llm=llm, prompt=PROMPT)
conversation = prompt | llm

return llm_chain.run(input_text)
return conversation.invoke(input=input_text)

def similarity_metric(predicted_text, reference_text):
embedding_model = HuggingFaceEmbeddings()
Expand Down
21 changes: 13 additions & 8 deletions lab-materials/05/05-05/pipeline_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@dsl.container_component
def initialize():
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
Expand All @@ -30,17 +30,17 @@ def initialize():
@dsl.container_component
def get_claims(claim_ids: int):
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''claim_id="$0"
export claim_id=$claim_id
export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python get_claims.py
ls
''',
],
args=[claim_ids]
Expand All @@ -49,11 +49,12 @@ def get_claims(claim_ids: int):
@dsl.container_component
def get_accident_time():
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python get_accident_time.py
Expand All @@ -65,11 +66,12 @@ def get_accident_time():
@dsl.container_component
def get_location():
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python get_location.py
Expand All @@ -81,11 +83,12 @@ def get_location():
@dsl.container_component
def get_sentiment():
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python get_sentiment.py
Expand All @@ -97,13 +100,14 @@ def get_sentiment():
@dsl.container_component
def detect_objects(detection_endpoint: str):
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''detection_endpoint="$0"
export detection_endpoint=$detection_endpoint
export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python detect_objects.py
Expand All @@ -115,11 +119,12 @@ def detect_objects(detection_endpoint: str):
@dsl.container_component
def summarize_text():
return dsl.ContainerSpec(
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.1',
image='quay.io/rh-aiservices-bu/rhoai-lab-insurance-claim-processing-pipeline:1.2',
command=[
'sh',
'-c',
'''export POSTGRES_HOST=claimdb.$NAMESPACE.svc.cluster.local
export IMAGES_BUCKET=$NAMESPACE
cd /shared-data
cd parasol-insurance/lab-materials/05/05-05
python summarize_text.py
Expand Down
Loading

0 comments on commit 10006a2

Please sign in to comment.