Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new shopping-assistant-service based on recommendation service,… #2407

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions kubernetes-manifests/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ resources:
- paymentservice.yaml
- productcatalogservice.yaml
- recommendationservice.yaml
- shoppingassistantservice.yaml
- redis.yaml
- shippingservice.yaml
# components:
Expand Down
67 changes: 67 additions & 0 deletions kubernetes-manifests/shoppingassistantservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
name: shoppingassistantservice
labels:
app: shoppingassistantservice
spec:
selector:
matchLabels:
app: shoppingassistantservice
template:
metadata:
labels:
app: shoppingassistantservice
spec:
serviceAccountName: default
terminationGracePeriodSeconds: 5
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
containers:
- name: server
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
image: shoppingassistantservice
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
name: shoppingassistantservice
labels:
app: shoppingassistantservice
spec:
type: ClusterIP
selector:
app: shoppingassistantservice
ports:
- name: http
port: 8080
70 changes: 70 additions & 0 deletions release/kubernetes-manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,61 @@ spec:
cpu: 200m
memory: 450Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: shoppingassistantservice
spec:
selector:
matchLabels:
app: shoppingassistantservice
template:
metadata:
labels:
app: shoppingassistantservice
spec:
serviceAccountName: default
terminationGracePeriodSeconds: 5
securityContext:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
containers:
- name: server
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
image: northamerica-northeast1-docker.pkg.dev/cooking-with-duet-6/local-images/shoppingassistantservice:v0.9.3
ports:
- containerPort: 8080
readinessProbe:
periodSeconds: 5
grpc:
port: 8080
livenessProbe:
periodSeconds: 5
grpc:
port: 8080
env:
- name: PORT
value: "8080"
- name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:3550"
- name: DISABLE_PROFILER
value: "1"
resources:
requests:
cpu: 100m
memory: 220Mi
limits:
cpu: 200m
memory: 450Mi
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -225,6 +280,19 @@ spec:
port: 8080
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: shoppingassistantservice
spec:
type: ClusterIP
selector:
app: shoppingassistantservice
ports:
- name: grpc
port: 8080
targetPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -285,6 +353,8 @@ spec:
value: "cartservice:7070"
- name: RECOMMENDATION_SERVICE_ADDR
value: "recommendationservice:8080"
- name: SHOPPING_ASSISTANT_SERVICE_ADDR
value: "shoppingassistantservice:8080"
- name: SHIPPING_SERVICE_ADDR
value: "shippingservice:50051"
- name: CHECKOUT_SERVICE_ADDR
Expand Down
2 changes: 2 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ build:
context: src/productcatalogservice
- image: recommendationservice
context: src/recommendationservice
- image: shoppingassistantservice
context: src/shoppingassistantservice
- image: shippingservice
context: src/shippingservice
- image: checkoutservice
Expand Down
1 change: 1 addition & 0 deletions src/shoppingassistantservice/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
45 changes: 45 additions & 0 deletions src/shoppingassistantservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.12.2-slim@sha256:5c73034c2bc151596ee0f1335610735162ee2b148816710706afec4757ad5b1e as base

FROM base as builder

RUN apt-get -qq update \
&& apt-get install -y --no-install-recommends \
wget g++ \
&& rm -rf /var/lib/apt/lists/*

# get packages
COPY requirements.txt .
RUN pip install -r requirements.txt

FROM base
# Enable unbuffered logging
ENV PYTHONUNBUFFERED=1

# get packages
WORKDIR /shoppingassistantservice

# Grab packages from builder
COPY --from=builder /usr/local/lib/python3.12/ /usr/local/lib/python3.12/

# Add the application
COPY . .

# set listen port
ENV PORT "8080"
EXPOSE 8080

ENTRYPOINT ["python", "shoppingassistantservice.py"]
2 changes: 2 additions & 0 deletions src/shoppingassistantservice/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask==3.0.2
langchain-google-genai==0.0.9
37 changes: 37 additions & 0 deletions src/shoppingassistantservice/shoppingassistantservice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/python
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from langchain_google_genai import ChatGoogleGenerativeAI

from flask import Flask
from flask import request
def create_app():
app = Flask(__name__)

@app.route("/", methods=['GET'])
def hello():
prompt = request.args.get('prompt')
llm = ChatGoogleGenerativeAI(model="gemini-pro")
response = llm.invoke(prompt)
return "Hello, World!" + prompt

return app


if __name__ == "__main__":
# Create an instance of flask server when called directly
app = create_app()
app.run()