From cc29e6a53c2b728c711a09df4f90d5898ee2fb50 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Mon, 14 Oct 2024 22:57:53 +0100 Subject: [PATCH] Updating templates --- templates/components/llamafile.jsonnet | 47 ++++++++++--------- .../model/text_completion/bedrock/llm.py | 5 +- .../model/text_completion/llamafile/llm.py | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/templates/components/llamafile.jsonnet b/templates/components/llamafile.jsonnet index 93163a14..d51cda61 100644 --- a/templates/components/llamafile.jsonnet +++ b/templates/components/llamafile.jsonnet @@ -6,12 +6,14 @@ local prompts = import "prompts/slm.jsonnet"; { "llamafile-model":: "LLaMA_CPP", - "llamafile-url":: "${LLAMAFILE_URL}", "text-completion" +: { create:: function(engine) + local envSecrets = engine.envSecrets("llamafile-credentials") + .with_env_var("LLAMAFILE_URL", "llamafile-url"); + local container = engine.container("text-completion") .with_image(images.trustgraph) @@ -21,27 +23,12 @@ local prompts = import "prompts/slm.jsonnet"; url.pulsar, "-m", $["llamafile-model"], - "-r", - $["llamafile-url"], ]) + .with_env_var_secrets(envSecrets) .with_limits("0.5", "128M") .with_reservations("0.1", "128M"); - local containerSet = engine.containers( - "text-completion", [ container ] - ); - - engine.resources([ - containerSet, - ]) - - }, - - "text-completion-rag" +: { - - create:: function(engine) - - local container = + local containerRag = engine.container("text-completion-rag") .with_image(images.trustgraph) .with_command([ @@ -50,26 +37,40 @@ local prompts = import "prompts/slm.jsonnet"; url.pulsar, "-m", $["llamafile-model"], - "-r", - $["llamafile-url"], "-i", "non-persistent://tg/request/text-completion-rag", "-o", "non-persistent://tg/response/text-completion-rag-response", ]) + .with_env_var_secrets(envSecrets) .with_limits("0.5", "128M") .with_reservations("0.1", "128M"); local containerSet = engine.containers( - "text-completion-rag", [ container ] + "text-completion", [ container ] ); + local containerSetRag = engine.containers( + "text-completion-rag", [ containerRag ] + ); + + local service = + engine.internalService(containerSet) + .with_port(8080, 8080, "metrics"); + + local serviceRag = + engine.internalService(containerSetRag) + .with_port(8080, 8080, "metrics"); + engine.resources([ + envSecrets, containerSet, + containerSetRag, + service, + serviceRag, ]) - - } + }, } + prompts diff --git a/trustgraph-bedrock/trustgraph/model/text_completion/bedrock/llm.py b/trustgraph-bedrock/trustgraph/model/text_completion/bedrock/llm.py index 99cdd1c6..f06d143e 100755 --- a/trustgraph-bedrock/trustgraph/model/text_completion/bedrock/llm.py +++ b/trustgraph-bedrock/trustgraph/model/text_completion/bedrock/llm.py @@ -22,7 +22,7 @@ default_input_queue = text_completion_request_queue default_output_queue = text_completion_response_queue default_subscriber = module default_model = 'mistral.mistral-large-2407-v1:0' -default_region = 'us-west-2' +default_region = os.getenv("AWS_REGION", 'us-west-2') default_temperature = 0.0 default_max_output = 2048 default_aws_id = os.getenv("AWS_ID_KEY") @@ -307,7 +307,7 @@ class Processor(ConsumerProducer): parser.add_argument( '-r', '--aws-region', - help=f'AWS Region (default: us-west-2)' + help=f'AWS Region' ) parser.add_argument( @@ -328,4 +328,3 @@ def run(): Processor.start(module, __doc__) - diff --git a/trustgraph-flow/trustgraph/model/text_completion/llamafile/llm.py b/trustgraph-flow/trustgraph/model/text_completion/llamafile/llm.py index 86427167..a25ad8ec 100755 --- a/trustgraph-flow/trustgraph/model/text_completion/llamafile/llm.py +++ b/trustgraph-flow/trustgraph/model/text_completion/llamafile/llm.py @@ -20,7 +20,7 @@ default_input_queue = text_completion_request_queue default_output_queue = text_completion_response_queue default_subscriber = module default_model = 'LLaMA_CPP' -default_llamafile = 'http://localhost:8080/v1' +default_llamafile = os.getenv("LLAMAFILE_URL", "http://localhost:8080/v1") default_temperature = 0.0 default_max_output = 4096