From 222dc9982cd1d79df1bd35ef2d73e6aa8aacdbbb Mon Sep 17 00:00:00 2001 From: cybermaggedon Date: Fri, 4 Oct 2024 15:47:46 +0100 Subject: [PATCH] Feature/azure openai templates (#104) * Azure OpenAI LLM templates * Bump version, fix package versions * Add azure-openai to template generation --- Makefile | 4 +- templates/all-patterns.jsonnet | 1 + templates/components.jsonnet | 1 + templates/components/azure-openai.jsonnet | 95 +++++++++++++++++++++ templates/generate-all | 4 +- templates/patterns/llm-azure-openai.jsonnet | 32 +++++++ 6 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 templates/components/azure-openai.jsonnet create mode 100644 templates/patterns/llm-azure-openai.jsonnet diff --git a/Makefile b/Makefile index 5593faa7..e1c752b4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # VERSION=$(shell git describe | sed 's/^v//') -VERSION=0.11.19 +VERSION=0.12.0 DOCKER=podman @@ -16,7 +16,7 @@ wheels: pip3 wheel --no-deps --wheel-dir dist trustgraph-embeddings-hf/ pip3 wheel --no-deps --wheel-dir dist trustgraph-cli/ -packages: +packages: update-package-versions rm -rf dist/ cd trustgraph-base && python3 setup.py sdist --dist-dir ../dist/ cd trustgraph-flow && python3 setup.py sdist --dist-dir ../dist/ diff --git a/templates/all-patterns.jsonnet b/templates/all-patterns.jsonnet index 29384d1e..47622939 100644 --- a/templates/all-patterns.jsonnet +++ b/templates/all-patterns.jsonnet @@ -7,6 +7,7 @@ import "patterns/triple-store-neo4j.jsonnet", import "patterns/graph-rag.jsonnet", import "patterns/llm-azure.jsonnet", + import "patterns/llm-azure-openai.jsonnet", import "patterns/llm-bedrock.jsonnet", import "patterns/llm-claude.jsonnet", import "patterns/llm-cohere.jsonnet", diff --git a/templates/components.jsonnet b/templates/components.jsonnet index 8ed2da0e..b52e305b 100644 --- a/templates/components.jsonnet +++ b/templates/components.jsonnet @@ -1,5 +1,6 @@ { "azure": import "components/azure.jsonnet", + "azure-openai": import "components/azure-openai.jsonnet", "bedrock": import "components/bedrock.jsonnet", "claude": import "components/claude.jsonnet", "cohere": import "components/cohere.jsonnet", diff --git a/templates/components/azure-openai.jsonnet b/templates/components/azure-openai.jsonnet new file mode 100644 index 00000000..31e19720 --- /dev/null +++ b/templates/components/azure-openai.jsonnet @@ -0,0 +1,95 @@ +local base = import "base/base.jsonnet"; +local images = import "values/images.jsonnet"; +local url = import "values/url.jsonnet"; +local prompts = import "prompts/mixtral.jsonnet"; + +{ + + "azure-openai-token":: "${AZURE_OPENAI_TOKEN}", + "azure-openai-model":: "GPT-3.5-Turbo", + "azure-openai-max-output-tokens":: 4192, + "azure-openai-temperature":: 0.0, + + "text-completion" +: { + + create:: function(engine) + + local container = + engine.container("text-completion") + .with_image(images.trustgraph) + .with_command([ + "text-completion-azure-openai", + "-p", + url.pulsar, + "-k", + $["azure-openai-token"], + "-m", + $["azure-openai-model"], + "-x", + std.toString($["azure-openai-max-output-tokens"]), + "-t", + std.toString($["azure-openai-temperature"]), + ]) + .with_limits("0.5", "128M") + .with_reservations("0.1", "128M"); + + local containerSet = engine.containers( + "text-completion", [ container ] + ); + + local service = + engine.internalService(containerSet) + .with_port(8000, 8000, "metrics"); + + engine.resources([ + containerSet, + service, + ]) + + }, + + "text-completion-rag" +: { + + create:: function(engine) + + local container = + engine.container("text-completion-rag") + .with_image(images.trustgraph) + .with_command([ + "text-completion-azure", + "-p", + url.pulsar, + "-k", + $["azure-openai-token"], + "-e", + $["azure-openai-model"], + "-x", + std.toString($["azure-openai-max-output-tokens"]), + "-t", + std.toString($["azure-openai-temperature"]), + "-i", + "non-persistent://tg/request/text-completion-rag", + "-o", + "non-persistent://tg/response/text-completion-rag-response", + ]) + .with_limits("0.5", "128M") + .with_reservations("0.1", "128M"); + + local containerSet = engine.containers( + "text-completion-rag", [ container ] + ); + + local service = + engine.internalService(containerSet) + .with_port(8000, 8000, "metrics"); + + engine.resources([ + containerSet, + service, + ]) + + + } + +} + prompts + diff --git a/templates/generate-all b/templates/generate-all index 948b811f..8b59ce03 100755 --- a/templates/generate-all +++ b/templates/generate-all @@ -122,8 +122,8 @@ def generate_all(output, version): "docker-compose", "minikube-k8s", "gcp-k8s" ]: for model in [ - "azure", "bedrock", "claude", "cohere", "llamafile", "ollama", - "openai", "vertexai" + "azure", "azure-openai", "bedrock", "claude", "cohere", + "llamafile", "ollama", "openai", "vertexai" ]: for graph in [ "cassandra", "neo4j" ]: diff --git a/templates/patterns/llm-azure-openai.jsonnet b/templates/patterns/llm-azure-openai.jsonnet new file mode 100644 index 00000000..06e1a3f5 --- /dev/null +++ b/templates/patterns/llm-azure-openai.jsonnet @@ -0,0 +1,32 @@ +{ + pattern: { + name: "azure-openai", + icon: "🤖💬", + title: "Add Azure OpenAI LLM endpoint for text completion", + description: "This pattern integrates an Azure OpenAI LLM endpoint hosted in the Azure cloud for text completion operations. You need an Azure subscription to be able to use this service.", + requires: ["pulsar", "trustgraph"], + features: ["llm"], + args: [ + { + name: "azure-openai-max-output-tokens", + label: "Maximum output tokens", + type: "integer", + description: "Limit on number tokens to generate", + default: 4096, + required: true, + }, + { + name: "azure-openai-temperature", + label: "Temperature", + type: "slider", + description: "Controlling predictability / creativity balance", + min: 0, + max: 1, + step: 0.05, + default: 0.5, + }, + ], + category: [ "llm" ], + }, + module: "components/azure.jsonnet", +}