From 693f8bb2cc5409af36edc728b95a23d91e6f17ad Mon Sep 17 00:00:00 2001 From: Mofi Rahman Date: Thu, 26 Sep 2024 15:19:53 -0400 Subject: [PATCH 1/4] add yaml for gameadvisor --- game-advisor/.dockerignore | 1 + game-advisor/Dockerfile | 20 ++++++++++++++++ game-advisor/lib/index.js | 13 +++++++++++ game-advisor/lib/index.js.map | 2 +- game-advisor/src/index.ts | 29 ----------------------- k8s/game-advisor.yaml | 43 +++++++++++++++++++++++++++++++++++ k8s/ollama.yaml | 3 +++ k8s/service-account.yaml | 0 8 files changed, 81 insertions(+), 30 deletions(-) create mode 100644 game-advisor/.dockerignore create mode 100644 game-advisor/Dockerfile create mode 100644 k8s/game-advisor.yaml create mode 100644 k8s/service-account.yaml diff --git a/game-advisor/.dockerignore b/game-advisor/.dockerignore new file mode 100644 index 0000000..f83526d --- /dev/null +++ b/game-advisor/.dockerignore @@ -0,0 +1 @@ +**/node_modules/ \ No newline at end of file diff --git a/game-advisor/Dockerfile b/game-advisor/Dockerfile new file mode 100644 index 0000000..a287056 --- /dev/null +++ b/game-advisor/Dockerfile @@ -0,0 +1,20 @@ +FROM node:22 + +# Create app directory +WORKDIR /usr/src/app + +# Install dependencies +COPY package*.json ./ +RUN npm install + +# Bundle source code +COPY . . + +# Build the app +RUN npm run build + +# Expose the port the app listens on +EXPOSE 3400 + +# Start the app +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/game-advisor/lib/index.js b/game-advisor/lib/index.js index 38d3514..f5fd392 100644 --- a/game-advisor/lib/index.js +++ b/game-advisor/lib/index.js @@ -1,4 +1,17 @@ "use strict"; +// Copyright 2024 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. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); diff --git a/game-advisor/lib/index.js.map b/game-advisor/lib/index.js.map index 8bd7546..17bafb4 100644 --- a/game-advisor/lib/index.js.map +++ b/game-advisor/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AAEzB,gDAAgD;AAChD,sCAAyC;AACzC,0CAAkD;AAClD,0CAA+D;AAC/D,kDAA+C;AAC/C,mDAAuC;AACvC,oDAA4D;AAC5D,4CAAuE;AACvE,wDAAwD;AAMxD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,uBAAuB,CAAC;AAE7E,IAAA,mBAAa,EAAC;IACZ,UAAU,EAAE,IAAA,wBAAkB,GAAE;CACjC,CAAC,CAAC;AAEH,MAAM,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;AAG1B,IAAA,sBAAe,EAAC;IACd,OAAO,EAAE;QAEP,IAAA,mBAAQ,EAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;QAClC,IAAA,uBAAM,EAAC;YACL,MAAM,EAAE;gBACN;oBACE,IAAI,EAAE,cAAc;oBACpB,IAAI,EAAE,UAAU;iBACjB;aACF;YACD,aAAa,EAAE,cAAc;SAC9B,CAAC;QACF,IAAA,qBAAS,GAAE;KACZ;IACD,mCAAmC;IACnC,QAAQ,EAAE,OAAO;IACjB,qEAAqE;IACrE,uBAAuB,EAAE,IAAI;CAC9B,CAAC,CAAC;AAEH,yEAAyE;AAC5D,QAAA,kBAAkB,GAAG,IAAA,iBAAU,EAC1C;IACE,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;IACvB,YAAY,EAAE,CAAC,CAAC,MAA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C,MAAM,EAAE;IACvB,YAAY,EAAE,uBAAuB;CACtC,EACD,KAAK,EAAE,MAAM,EAAE,EAAE;IAEf,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,UAAU,CAAC,eAAe,CAAC;aAClD,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC;aAC7B,GAAG,EAAE,CAAC;QAET,MAAM,MAAM,GAAsB,EAAE,CAAC;QACrC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACrB,MAAM,CAAC,IAAI,iBAAG,EAAE,EAAE,GAAG,CAAC,EAAE,IAAK,GAAG,CAAC,IAAI,EAAE,EAAG,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;QAEzD,8CAA8C;QAEhD,oDAAoD;QAClD,MAAM,MAAM,GAAG,IAAA,qBAAS,EAAC,SAAS,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,EAAC,OAAO,EAAE,OAAO,EAAC,EAAC,CAAC,CAAC;QAChE,6BAA6B;QAC7B,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;IACjD,CAAC;AACD,CAAC,CACF,CAAA;AAED,6EAA6E;AAC7E,gFAAgF;AAChF,4EAA4E;AAC5E,iFAAiF;AACjF,IAAA,uBAAgB,GAAE,CAAC"} \ No newline at end of file diff --git a/game-advisor/src/index.ts b/game-advisor/src/index.ts index 68102ad..824c260 100644 --- a/game-advisor/src/index.ts +++ b/game-advisor/src/index.ts @@ -15,7 +15,6 @@ import * as z from 'zod'; // Import the Genkit core libraries and plugins. -import { generate } from '@genkit-ai/ai'; import { configureGenkit } from '@genkit-ai/core'; import { defineFlow, startFlowsServer } from '@genkit-ai/flow'; import { vertexAI } from '@genkit-ai/vertexai'; @@ -24,10 +23,6 @@ import { dotprompt, promptRef } from '@genkit-ai/dotprompt'; import { initializeApp, applicationDefault } from 'firebase-admin/app'; import { getFirestore } from 'firebase-admin/firestore'; -// Import models from the Vertex AI plugin. The Vertex AI API provides access to -// several generative models. Here, we import Gemini 1.5 Flash. -import { gemini15Flash } from '@genkit-ai/vertexai'; - const OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS || 'http://localhost:8080'; initializeApp({ @@ -58,30 +53,6 @@ configureGenkit({ enableTracingAndMetrics: true, }); -// Define a simple flow that prompts an LLM to generate menu suggestions. -export const menuSuggestionFlow = defineFlow( - { - name: 'menuSuggestionFlow', - inputSchema: z.string(), - outputSchema: z.string(), - }, - async (subject) => { - // Construct a request and send it to the model API. - const llmResponse = await generate({ - prompt: `Suggest an item for the menu of a ${subject} themed restaurant`, - model: 'ollama/llama3.1:70b', - config: { - temperature: 1, - }, - }); - - // Handle the response from the model API. In this sample, we just convert - // it to a string, but more complicated flows might coerce the response into - // structured output or chain the response into another LLM call, etc. - return llmResponse.text(); - } -); - const gameSummaryOutputSchema = z.object({ headline: z.string(), analysis: z.string(), diff --git a/k8s/game-advisor.yaml b/k8s/game-advisor.yaml new file mode 100644 index 0000000..acbc536 --- /dev/null +++ b/k8s/game-advisor.yaml @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: game-advisor +spec: + selector: + matchLabels: + app: game-advisor + template: + metadata: + labels: + app: game-advisor + spec: + serviceAccount: genkit + containers: + - name: game-advisor + image: us-docker.pkg.dev/backlogged-ai/llm/game-advisor:v2.0.0 + resources: + limits: + memory: "4Gi" + cpu: "2" + env: + - name: OLLAMA_ADDRESS + value: "http://ollama-service:8080" + ports: + - containerPort: 3400 + name: http + protocol: TCP + +--- +apiVersion: v1 +kind: Service +metadata: + name: game-advisor +spec: + selector: + app: game-advisor + type: ClusterIP + ports: + - port: 8080 + targetPort: 3400 + protocol: TCP + name: http diff --git a/k8s/ollama.yaml b/k8s/ollama.yaml index 2532a28..b7ec2f4 100644 --- a/k8s/ollama.yaml +++ b/k8s/ollama.yaml @@ -29,6 +29,9 @@ spec: memory: "80Gi" ephemeral-storage: "100Gi" nvidia.com/gpu: "2" + nodeSelector: + cloud.google.com/gke-accelerator: nvidia-h100-80gb + cloud.google.com/gke-gpu-driver-version: latest --- apiVersion: v1 kind: Service diff --git a/k8s/service-account.yaml b/k8s/service-account.yaml new file mode 100644 index 0000000..e69de29 From 8c2152d9c67515855c263d88341e95b464fab477 Mon Sep 17 00:00:00 2001 From: Mofi Rahman Date: Thu, 26 Sep 2024 15:21:35 -0400 Subject: [PATCH 2/4] add copyright --- game-advisor/Dockerfile | 14 ++++++++++++++ k8s/llama3-70b.yaml | 14 ++++++++++++++ k8s/ollama.yaml | 14 ++++++++++++++ k8s/service-account.yaml | 0 ollama/Dockerfile | 14 ++++++++++++++ 5 files changed, 56 insertions(+) delete mode 100644 k8s/service-account.yaml diff --git a/game-advisor/Dockerfile b/game-advisor/Dockerfile index a287056..732ffa8 100644 --- a/game-advisor/Dockerfile +++ b/game-advisor/Dockerfile @@ -1,3 +1,17 @@ +# Copyright 2024 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 node:22 # Create app directory diff --git a/k8s/llama3-70b.yaml b/k8s/llama3-70b.yaml index 3f18b9d..c21a987 100644 --- a/k8s/llama3-70b.yaml +++ b/k8s/llama3-70b.yaml @@ -1,3 +1,17 @@ +# Copyright 2024 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: diff --git a/k8s/ollama.yaml b/k8s/ollama.yaml index b7ec2f4..db4e766 100644 --- a/k8s/ollama.yaml +++ b/k8s/ollama.yaml @@ -1,3 +1,17 @@ +# Copyright 2024 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: diff --git a/k8s/service-account.yaml b/k8s/service-account.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/ollama/Dockerfile b/ollama/Dockerfile index 595d116..454e853 100644 --- a/ollama/Dockerfile +++ b/ollama/Dockerfile @@ -1,3 +1,17 @@ +# Copyright 2024 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 ollama/ollama:0.3.12 # Listen on all interfaces, port 8080 From 53b0ddebf70bf86181d4dd3e554be685967795c3 Mon Sep 17 00:00:00 2001 From: Mofi Rahman Date: Thu, 26 Sep 2024 15:23:53 -0400 Subject: [PATCH 3/4] remove lib --- game-advisor/.gitignore | 2 +- game-advisor/lib/index.js | 129 ---------------------------------- game-advisor/lib/index.js.map | 1 - 3 files changed, 1 insertion(+), 131 deletions(-) delete mode 100644 game-advisor/lib/index.js delete mode 100644 game-advisor/lib/index.js.map diff --git a/game-advisor/.gitignore b/game-advisor/.gitignore index c3af857..e336fb6 100644 --- a/game-advisor/.gitignore +++ b/game-advisor/.gitignore @@ -1 +1 @@ -lib/ +**/lib/ diff --git a/game-advisor/lib/index.js b/game-advisor/lib/index.js deleted file mode 100644 index f5fd392..0000000 --- a/game-advisor/lib/index.js +++ /dev/null @@ -1,129 +0,0 @@ -"use strict"; -// Copyright 2024 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. -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.gameSummaryFlow = exports.menuSuggestionFlow = void 0; -const z = __importStar(require("zod")); -// Import the Genkit core libraries and plugins. -const ai_1 = require("@genkit-ai/ai"); -const core_1 = require("@genkit-ai/core"); -const flow_1 = require("@genkit-ai/flow"); -const vertexai_1 = require("@genkit-ai/vertexai"); -const genkitx_ollama_1 = require("genkitx-ollama"); -const dotprompt_1 = require("@genkit-ai/dotprompt"); -const app_1 = require("firebase-admin/app"); -const firestore_1 = require("firebase-admin/firestore"); -const OLLAMA_ADDRESS = process.env.OLLAMA_ADDRESS || 'http://localhost:8080'; -(0, app_1.initializeApp)({ - credential: (0, app_1.applicationDefault)() -}); -const db = (0, firestore_1.getFirestore)(); -(0, core_1.configureGenkit)({ - plugins: [ - (0, vertexai_1.vertexAI)({ location: 'us-west4' }), - (0, genkitx_ollama_1.ollama)({ - models: [ - { - name: 'llama3.1:70b', - type: 'generate', - }, - ], - serverAddress: OLLAMA_ADDRESS - }), - (0, dotprompt_1.dotprompt)() - ], - // Log debug output to tbe console. - logLevel: 'debug', - // Perform OpenTelemetry instrumentation and enable trace collection. - enableTracingAndMetrics: true, -}); -// Define a simple flow that prompts an LLM to generate menu suggestions. -exports.menuSuggestionFlow = (0, flow_1.defineFlow)({ - name: 'menuSuggestionFlow', - inputSchema: z.string(), - outputSchema: z.string(), -}, async (subject) => { - // Construct a request and send it to the model API. - const llmResponse = await (0, ai_1.generate)({ - prompt: `Suggest an item for the menu of a ${subject} themed restaurant`, - model: 'ollama/llama3.1:70b', - config: { - temperature: 1, - }, - }); - // Handle the response from the model API. In this sample, we just convert - // it to a string, but more complicated flows might coerce the response into - // structured output or chain the response into another LLM call, etc. - return llmResponse.text(); -}); -const gameSummaryOutputSchema = z.object({ - headline: z.string(), - analysis: z.string(), - tips: z.array(z.string()), - grade: z.string(), -}); -exports.gameSummaryFlow = (0, flow_1.defineFlow)({ - name: 'gameSummaryFlow', - inputSchema: z.string(), - outputSchema: gameSummaryOutputSchema -}, async (gameId) => { - try { - const snapshot = await db.collection('AllGameEvents') - .where('GameId', '==', gameId) - .get(); - const events = []; - snapshot.forEach(doc => { - events.push(Object.assign({ id: doc.id }, doc.data())); - }); - let content = JSON.stringify(events).replace(/"/g, '\\"'); - // console.log(`stringified log: ${content}`); - // Construct a request and send it to the model API. - const prompt = (0, dotprompt_1.promptRef)("summary"); - const resp = await prompt.generate({ input: { gameLog: content } }); - // console.log(resp.output()) - return resp.output(); - } - catch (error) { - console.error('Error fetching events:', error); - } -}); -// Start a flow server, which exposes your flows as HTTP endpoints. This call -// must come last, after all of your plug-in configuration and flow definitions. -// You can optionally specify a subset of flows to serve, and configure some -// HTTP server options, but by default, the flow server serves all defined flows. -(0, flow_1.startFlowsServer)(); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/game-advisor/lib/index.js.map b/game-advisor/lib/index.js.map deleted file mode 100644 index 17bafb4..0000000 --- a/game-advisor/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4BAA4B;AAC5B,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;AAEjC,uCAAyB;AAEzB,gDAAgD;AAChD,sCAAyC;AACzC,0CAAkD;AAClD,0CAA+D;AAC/D,kDAA+C;AAC/C,mDAAuC;AACvC,oDAA4D;AAC5D,4CAAuE;AACvE,wDAAwD;AAMxD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,uBAAuB,CAAC;AAE7E,IAAA,mBAAa,EAAC;IACZ,UAAU,EAAE,IAAA,wBAAkB,GAAE;CACjC,CAAC,CAAC;AAEH,MAAM,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;AAG1B,IAAA,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cluster.sh | 11 ++++++++++- k8s/game-advisor.yaml | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/k8s/cluster.sh b/k8s/cluster.sh index c1838a9..c47af5a 100644 --- a/k8s/cluster.sh +++ b/k8s/cluster.sh @@ -1,5 +1,6 @@ gcloud config set project backlogged-ai export PROJECT_ID=$(gcloud config get project) +export PROJECT_NUMBER= export REGION=us-west4 export ZONE=us-west4-a export CLUSTER_NAME=gemma @@ -27,4 +28,12 @@ gcloud beta container --project=${PROJECT_ID} node-pools create "gpu" \ kubectl create secret generic hf-secret \ --from-literal=hf_api_token=$HF_TOKEN \ ---dry-run=client -o yaml | kubectl apply -f - \ No newline at end of file +--dry-run=client -o yaml | kubectl apply -f - + +kubectl create serviceaccount genkit \ + --namespace default + +gcloud projects add-iam-policy-binding projects/backlogged-ai \ + --role=roles/firebase.admin \ + --member=principal://iam.googleapis.com/projects/${PROJECT_NUMBER}/locations/global/workloadIdentityPools/backlogged-ai.svc.id.goog/subject/ns/default/sa/genkit \ + --condition=None \ No newline at end of file diff --git a/k8s/game-advisor.yaml b/k8s/game-advisor.yaml index acbc536..90fcb42 100644 --- a/k8s/game-advisor.yaml +++ b/k8s/game-advisor.yaml @@ -1,3 +1,17 @@ +# Copyright 2024 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: @@ -21,7 +35,7 @@ spec: cpu: "2" env: - name: OLLAMA_ADDRESS - value: "http://ollama-service:8080" + value: "http:#ollama-service:8080" ports: - containerPort: 3400 name: http