diff --git a/containers/Containerfile.base b/containers/Containerfile.base index b4f5bbbf..4d28b26d 100644 --- a/containers/Containerfile.base +++ b/containers/Containerfile.base @@ -4,14 +4,16 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS base +FROM docker.io/fedora:42 AS base ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp && \ - dnf clean all - -RUN pip3 install --no-cache-dir pulsar-client==3.5.0 +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + dnf clean all # ---------------------------------------------------------------------------- # Build a container which contains the built Python packages. The build diff --git a/containers/Containerfile.bedrock b/containers/Containerfile.bedrock index 21819973..2885080d 100644 --- a/containers/Containerfile.bedrock +++ b/containers/Containerfile.bedrock @@ -4,14 +4,16 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS base +FROM docker.io/fedora:42 AS base ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp \ - python3-rdflib - -RUN pip3 install --no-cache-dir boto3 pulsar-client==3.5.0 +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + dnf clean all # ---------------------------------------------------------------------------- # Build a container which contains the built Python packages. The build diff --git a/containers/Containerfile.flow b/containers/Containerfile.flow index 352e5ac5..d4015c8c 100644 --- a/containers/Containerfile.flow +++ b/containers/Containerfile.flow @@ -4,21 +4,25 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS base +FROM docker.io/fedora:42 AS base ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp \ - python3-rdflib +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp rdflib && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + dnf clean all RUN pip3 install --no-cache-dir \ anthropic cohere mistralai openai google-generativeai \ ollama \ - langchain==0.3.13 langchain-core==0.3.28 \ - langchain-text-splitters==0.3.4 \ - langchain-community==0.3.13 \ + langchain==0.3.25 langchain-core==0.3.60 \ + langchain-text-splitters==0.3.8 \ + langchain-community==0.3.24 \ pymilvus \ - pulsar-client==3.5.0 cassandra-driver pyyaml \ + pulsar-client==3.7.0 cassandra-driver pyyaml \ neo4j tiktoken falkordb && \ pip3 cache purge diff --git a/containers/Containerfile.hf b/containers/Containerfile.hf index 4076db28..dcc91632 100644 --- a/containers/Containerfile.hf +++ b/containers/Containerfile.hf @@ -4,22 +4,26 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS ai +FROM docker.io/fedora:42 AS ai ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp \ - python3-rdflib +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + dnf clean all RUN pip3 install torch==2.5.1+cpu \ --index-url https://download.pytorch.org/whl/cpu RUN pip3 install --no-cache-dir \ - langchain==0.3.13 langchain-core==0.3.28 langchain-huggingface==0.1.2 \ - langchain-community==0.3.13 \ - sentence-transformers==3.4.0 transformers==4.47.1 \ - huggingface-hub==0.27.0 \ - pulsar-client==3.5.0 + langchain==0.3.25 langchain-core==0.3.60 langchain-huggingface==0.2.0 \ + langchain-community==0.3.24 \ + sentence-transformers==4.1.0 transformers==4.51.3 \ + huggingface-hub==0.31.2 \ + pulsar-client==3.7.0 # Most commonly used embeddings model, just build it into the container # image diff --git a/containers/Containerfile.ocr b/containers/Containerfile.ocr index 8a454008..661b8e17 100644 --- a/containers/Containerfile.ocr +++ b/containers/Containerfile.ocr @@ -4,14 +4,16 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS base +FROM docker.io/fedora:42 AS base ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp \ - python3-rdflib tesseract poppler poppler-utils - -RUN pip3 install --no-cache-dir pytesseract pulsar-client==3.5.0 +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + dnf clean all # ---------------------------------------------------------------------------- # Build a container which contains the built Python packages. The build diff --git a/containers/Containerfile.vertexai b/containers/Containerfile.vertexai index 72d21bde..9d7028c0 100644 --- a/containers/Containerfile.vertexai +++ b/containers/Containerfile.vertexai @@ -4,15 +4,17 @@ # like to avoid re-doing this. # ---------------------------------------------------------------------------- -FROM docker.io/fedora:40 AS base +FROM docker.io/fedora:42 AS base ENV PIP_BREAK_SYSTEM_PACKAGES=1 -RUN dnf install -y python3 python3-pip python3-wheel python3-aiohttp \ - python3-rdflib - -RUN pip3 install --no-cache-dir \ - google-cloud-aiplatform pulsar-client==3.5.0 +RUN dnf install -y python3.12 && \ + alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ + python -m ensurepip --upgrade && \ + pip3 install --no-cache-dir wheel aiohttp && \ + pip3 install --no-cache-dir pulsar-client==3.7.0 && \ + pip3 install --no-cache-dir google-cloud-aiplatform && \ + dnf clean all # ---------------------------------------------------------------------------- # Build a container which contains the built Python packages. The build @@ -47,5 +49,3 @@ RUN \ WORKDIR / - - diff --git a/trustgraph-base/trustgraph/api/flow.py b/trustgraph-base/trustgraph/api/flow.py index ba330ab7..8c872fd1 100644 --- a/trustgraph-base/trustgraph/api/flow.py +++ b/trustgraph-base/trustgraph/api/flow.py @@ -24,7 +24,7 @@ class Flow: else: return self.api.request(f"flow", request) - def id(self, id="0000"): + def id(self, id="default"): return FlowInstance(api=self, id=id) def list_classes(self): diff --git a/trustgraph-base/trustgraph/api/knowledge.py b/trustgraph-base/trustgraph/api/knowledge.py index 724ac79c..3c625057 100644 --- a/trustgraph-base/trustgraph/api/knowledge.py +++ b/trustgraph-base/trustgraph/api/knowledge.py @@ -39,7 +39,7 @@ class Knowledge: self.request(request = input) - def load_kg_core(self, id, user="trustgraph", flow="0000", + def load_kg_core(self, id, user="trustgraph", flow="default", collection="default"): # The input consists of system and prompt strings @@ -53,7 +53,7 @@ class Knowledge: self.request(request = input) - def unload_kg_core(self, id, user="trustgraph", flow="0000"): + def unload_kg_core(self, id, user="trustgraph", flow="default"): # The input consists of system and prompt strings input = { diff --git a/trustgraph-base/trustgraph/api/library.py b/trustgraph-base/trustgraph/api/library.py index c67bfeda..fad13f8d 100644 --- a/trustgraph-base/trustgraph/api/library.py +++ b/trustgraph-base/trustgraph/api/library.py @@ -208,7 +208,7 @@ class Library: return {} def start_processing( - self, id, document_id, flow="0000", + self, id, document_id, flow="default", user="trustgraph", collection="default", tags=[], ): diff --git a/trustgraph-base/trustgraph/base/request_response_spec.py b/trustgraph-base/trustgraph/base/request_response_spec.py index 7b8b1be8..e4763a13 100644 --- a/trustgraph-base/trustgraph/base/request_response_spec.py +++ b/trustgraph-base/trustgraph/base/request_response_spec.py @@ -127,8 +127,12 @@ class RequestResponseSpec(Spec): rr = self.impl( client = processor.pulsar_client, + + # Make subscription names unique, so that all subscribers get + # to see all response messages subscription = ( - processor.id + "--" + flow.name + "--" + self.request_name + processor.id + "--" + flow.name + "--" + self.request_name + + "--" + str(uuid.uuid4()) ), consumer_name = flow.id, request_topic = definition[self.request_name], diff --git a/trustgraph-bedrock/setup.py b/trustgraph-bedrock/setup.py index a0f7d544..606e0375 100644 --- a/trustgraph-bedrock/setup.py +++ b/trustgraph-bedrock/setup.py @@ -34,7 +34,7 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", "pulsar-client", "prometheus-client", "boto3", diff --git a/trustgraph-cli/scripts/tg-graph-to-turtle b/trustgraph-cli/scripts/tg-graph-to-turtle index a7607986..6a504f8d 100755 --- a/trustgraph-cli/scripts/tg-graph-to-turtle +++ b/trustgraph-cli/scripts/tg-graph-to-turtle @@ -71,8 +71,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-invoke-agent b/trustgraph-cli/scripts/tg-invoke-agent index 8a148d00..32408164 100755 --- a/trustgraph-cli/scripts/tg-invoke-agent +++ b/trustgraph-cli/scripts/tg-invoke-agent @@ -110,8 +110,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-invoke-document-rag b/trustgraph-cli/scripts/tg-invoke-document-rag index 9f70b1dc..7600988b 100755 --- a/trustgraph-cli/scripts/tg-invoke-document-rag +++ b/trustgraph-cli/scripts/tg-invoke-document-rag @@ -39,8 +39,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-invoke-graph-rag b/trustgraph-cli/scripts/tg-invoke-graph-rag index 85652d74..0c2311fc 100755 --- a/trustgraph-cli/scripts/tg-invoke-graph-rag +++ b/trustgraph-cli/scripts/tg-invoke-graph-rag @@ -47,8 +47,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-invoke-llm b/trustgraph-cli/scripts/tg-invoke-llm index 86c8d60f..d0f88510 100755 --- a/trustgraph-cli/scripts/tg-invoke-llm +++ b/trustgraph-cli/scripts/tg-invoke-llm @@ -47,8 +47,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) args = parser.parse_args() diff --git a/trustgraph-cli/scripts/tg-invoke-prompt b/trustgraph-cli/scripts/tg-invoke-prompt index 49697090..d8cc71e8 100755 --- a/trustgraph-cli/scripts/tg-invoke-prompt +++ b/trustgraph-cli/scripts/tg-invoke-prompt @@ -42,8 +42,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-load-doc-embeds b/trustgraph-cli/scripts/tg-load-doc-embeds index 567ccb68..c89f620c 100755 --- a/trustgraph-cli/scripts/tg-load-doc-embeds +++ b/trustgraph-cli/scripts/tg-load-doc-embeds @@ -191,8 +191,8 @@ async def main(running): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-load-kg-core b/trustgraph-cli/scripts/tg-load-kg-core index 2ecdc588..b50cec82 100755 --- a/trustgraph-cli/scripts/tg-load-kg-core +++ b/trustgraph-cli/scripts/tg-load-kg-core @@ -13,7 +13,7 @@ from trustgraph.api import Api import json default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') -default_flow = "0000" +default_flow = "default" default_collection = "default" def load_kg_core(url, user, id, flow, collection): diff --git a/trustgraph-cli/scripts/tg-load-pdf b/trustgraph-cli/scripts/tg-load-pdf index a9fa4ce1..93771379 100755 --- a/trustgraph-cli/scripts/tg-load-pdf +++ b/trustgraph-cli/scripts/tg-load-pdf @@ -86,8 +86,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-load-sample-documents b/trustgraph-cli/scripts/tg-load-sample-documents index 2bbad89f..880fb9e8 100755 --- a/trustgraph-cli/scripts/tg-load-sample-documents +++ b/trustgraph-cli/scripts/tg-load-sample-documents @@ -40,8 +40,7 @@ documents = [ "id": "https://trustgraph.ai/doc/challenger-report-vol-1", "title": "Report of the Presidential Commission on the Space Shuttle Challenger Accident, Volume 1", "comments": "The findings of the Commission regarding the circumstances surrounding the Challenger accident are reported and recommendations for corrective action are outlined", -# "url": "https://ntrs.nasa.gov/api/citations/19860015255/downloads/19860015255.pdf", - "url": "file://19860015255.pdf", + "url": "https://ntrs.nasa.gov/api/citations/19860015255/downloads/19860015255.pdf", "kind": "application/pdf", "date": datetime.datetime.now().date(), "tags": ["nasa", "safety-engineering", "space-shuttle"], @@ -740,10 +739,3 @@ def main(): main() - - - -# https://warwick.ac.uk/fac/soc/pais/people/aldrich/publications/beyond.pdf - -# https://www.ialeia.org/docs/Psychology_of_Intelligence_Analysis.pdf - diff --git a/trustgraph-cli/scripts/tg-load-text b/trustgraph-cli/scripts/tg-load-text index d00548ad..e1752324 100755 --- a/trustgraph-cli/scripts/tg-load-text +++ b/trustgraph-cli/scripts/tg-load-text @@ -88,8 +88,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-load-turtle b/trustgraph-cli/scripts/tg-load-turtle index 3cf24a7d..ba92067e 100755 --- a/trustgraph-cli/scripts/tg-load-turtle +++ b/trustgraph-cli/scripts/tg-load-turtle @@ -113,8 +113,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-save-doc-embeds b/trustgraph-cli/scripts/tg-save-doc-embeds index 07dc5f26..9e86ce6b 100755 --- a/trustgraph-cli/scripts/tg-save-doc-embeds +++ b/trustgraph-cli/scripts/tg-save-doc-embeds @@ -161,8 +161,8 @@ async def main(running): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-show-flow-state b/trustgraph-cli/scripts/tg-show-flow-state index 7b8b1a42..0c430959 100755 --- a/trustgraph-cli/scripts/tg-show-flow-state +++ b/trustgraph-cli/scripts/tg-show-flow-state @@ -63,8 +63,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-show-graph b/trustgraph-cli/scripts/tg-show-graph index 3690a8b8..bfe68de6 100755 --- a/trustgraph-cli/scripts/tg-show-graph +++ b/trustgraph-cli/scripts/tg-show-graph @@ -39,8 +39,8 @@ def main(): parser.add_argument( '-f', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)' + default="default", + help=f'Flow ID (default: default)' ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-start-library-processing b/trustgraph-cli/scripts/tg-start-library-processing index b03ae08d..aa59606b 100755 --- a/trustgraph-cli/scripts/tg-start-library-processing +++ b/trustgraph-cli/scripts/tg-start-library-processing @@ -54,8 +54,8 @@ def main(): parser.add_argument( '-i', '--flow-id', - default="0000", - help=f'Flow ID (default: 0000)', + default="default", + help=f'Flow ID (default: default)', ) parser.add_argument( diff --git a/trustgraph-cli/scripts/tg-unload-kg-core b/trustgraph-cli/scripts/tg-unload-kg-core index 7227942d..b24dc231 100755 --- a/trustgraph-cli/scripts/tg-unload-kg-core +++ b/trustgraph-cli/scripts/tg-unload-kg-core @@ -13,7 +13,7 @@ from trustgraph.api import Api import json default_url = os.getenv("TRUSTGRAPH_URL", 'http://localhost:8088/') -default_flow = "0000" +default_flow = "default" default_collection = "default" def unload_kg_core(url, user, id, flow): diff --git a/trustgraph-cli/setup.py b/trustgraph-cli/setup.py index b555eb92..ed26511e 100644 --- a/trustgraph-cli/setup.py +++ b/trustgraph-cli/setup.py @@ -34,7 +34,7 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", "requests", "pulsar-client", "aiohttp", diff --git a/trustgraph-embeddings-hf/setup.py b/trustgraph-embeddings-hf/setup.py index a01a9f11..10f72df6 100644 --- a/trustgraph-embeddings-hf/setup.py +++ b/trustgraph-embeddings-hf/setup.py @@ -34,8 +34,8 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", - "trustgraph-flow>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", + "trustgraph-flow>=1.0,<1.1", "torch", "urllib3", "transformers", diff --git a/trustgraph-flow/scripts/text-completion-tgi b/trustgraph-flow/scripts/text-completion-tgi new file mode 100755 index 00000000..c1e856f8 --- /dev/null +++ b/trustgraph-flow/scripts/text-completion-tgi @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +from trustgraph.model.text_completion.tgi import run + +run() + diff --git a/trustgraph-flow/setup.py b/trustgraph-flow/setup.py index b4598b64..a4d4f7a0 100644 --- a/trustgraph-flow/setup.py +++ b/trustgraph-flow/setup.py @@ -34,7 +34,7 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", "aiohttp", "anthropic", "cassandra-driver", @@ -42,7 +42,7 @@ setuptools.setup( "cryptography", "falkordb", "fastembed", - "google-generativeai", + "google-genai", "ibis", "jsonschema", "langchain", @@ -117,6 +117,7 @@ setuptools.setup( "scripts/text-completion-mistral", "scripts/text-completion-ollama", "scripts/text-completion-openai", + "scripts/text-completion-tgi", "scripts/triples-query-cassandra", "scripts/triples-query-falkordb", "scripts/triples-query-memgraph", diff --git a/trustgraph-flow/trustgraph/gateway/dispatch/librarian.py b/trustgraph-flow/trustgraph/gateway/dispatch/librarian.py index d33138ac..364ba1c2 100644 --- a/trustgraph-flow/trustgraph/gateway/dispatch/librarian.py +++ b/trustgraph-flow/trustgraph/gateway/dispatch/librarian.py @@ -65,8 +65,6 @@ class LibrarianRequestor(ServiceRequestor): def from_response(self, message): - print(message) - response = {} if message.document_metadata: diff --git a/trustgraph-flow/trustgraph/gateway/dispatch/mux.py b/trustgraph-flow/trustgraph/gateway/dispatch/mux.py index e2c5a921..463d6dc9 100644 --- a/trustgraph-flow/trustgraph/gateway/dispatch/mux.py +++ b/trustgraph-flow/trustgraph/gateway/dispatch/mux.py @@ -149,7 +149,6 @@ class Mux: break try: - print(id, svc, request) await self.start_request_task( self.ws, id, flow, svc, request, workers diff --git a/trustgraph-flow/trustgraph/gateway/dispatch/requestor.py b/trustgraph-flow/trustgraph/gateway/dispatch/requestor.py index b8a84644..35c41c8f 100644 --- a/trustgraph-flow/trustgraph/gateway/dispatch/requestor.py +++ b/trustgraph-flow/trustgraph/gateway/dispatch/requestor.py @@ -82,8 +82,6 @@ class ServiceRequestor: resp, fin = self.from_response(resp) - print(resp, fin, flush=True) - if responder: await responder(resp, fin) diff --git a/trustgraph-flow/trustgraph/gateway/dispatch/streamer.py b/trustgraph-flow/trustgraph/gateway/dispatch/streamer.py index 60d4aff2..54674906 100644 --- a/trustgraph-flow/trustgraph/gateway/dispatch/streamer.py +++ b/trustgraph-flow/trustgraph/gateway/dispatch/streamer.py @@ -76,8 +76,6 @@ class ServiceRequestor: resp, fin = self.from_inbound(resp) - print(resp, fin) - await self.receiver(resp, fin) if fin: break diff --git a/trustgraph-flow/trustgraph/gateway/dispatch/triples_query.py b/trustgraph-flow/trustgraph/gateway/dispatch/triples_query.py index 5db84abd..7c3a5fc9 100644 --- a/trustgraph-flow/trustgraph/gateway/dispatch/triples_query.py +++ b/trustgraph-flow/trustgraph/gateway/dispatch/triples_query.py @@ -48,7 +48,6 @@ class TriplesQueryRequestor(ServiceRequestor): ) def from_response(self, message): - print(message) return { "response": serialize_subgraph(message.triples) }, True diff --git a/trustgraph-flow/trustgraph/gateway/endpoint/constant_endpoint.py b/trustgraph-flow/trustgraph/gateway/endpoint/constant_endpoint.py index eda9da4d..1e1d9d28 100644 --- a/trustgraph-flow/trustgraph/gateway/endpoint/constant_endpoint.py +++ b/trustgraph-flow/trustgraph/gateway/endpoint/constant_endpoint.py @@ -47,10 +47,8 @@ class ConstantEndpoint: data = await request.json() - print(data) - async def responder(x, fin): - print(x) + pass resp = await self.dispatcher.process(data, responder) diff --git a/trustgraph-flow/trustgraph/gateway/endpoint/variable_endpoint.py b/trustgraph-flow/trustgraph/gateway/endpoint/variable_endpoint.py index 8813165c..4a131d9d 100644 --- a/trustgraph-flow/trustgraph/gateway/endpoint/variable_endpoint.py +++ b/trustgraph-flow/trustgraph/gateway/endpoint/variable_endpoint.py @@ -47,10 +47,8 @@ class VariableEndpoint: data = await request.json() - print(data) - async def responder(x, fin): - print(x) + pass resp = await self.dispatcher.process( data, responder, request.match_info diff --git a/trustgraph-flow/trustgraph/model/text_completion/googleaistudio/llm.py b/trustgraph-flow/trustgraph/model/text_completion/googleaistudio/llm.py index 051e2fe5..ec568e61 100644 --- a/trustgraph-flow/trustgraph/model/text_completion/googleaistudio/llm.py +++ b/trustgraph-flow/trustgraph/model/text_completion/googleaistudio/llm.py @@ -4,10 +4,18 @@ Simple LLM service, performs text prompt completion using GoogleAIStudio. Input is prompt, output is response. """ -import google.generativeai as genai -from google.generativeai.types import HarmCategory, HarmBlockThreshold +# +# Using this SDK: +# https://googleapis.github.io/python-genai/genai.html#module-genai.client +# +# Seems to have simpler dependencies on the 'VertexAI' service, which +# TrustGraph implements in the trustgraph-vertexai package. +# + +from google import genai +from google.genai import types +from google.genai.types import HarmCategory, HarmBlockThreshold from google.api_core.exceptions import ResourceExhausted -from prometheus_client import Histogram import os from .... exceptions import TooManyRequests @@ -15,7 +23,7 @@ from .... base import LlmService, LlmResult default_ident = "text-completion" -default_model = 'gemini-1.5-flash-002' +default_model = 'gemini-2.0-flash-001' default_temperature = 0.0 default_max_output = 8192 default_api_key = os.getenv("GOOGLE_AI_STUDIO_KEY") @@ -40,58 +48,56 @@ class Processor(LlmService): } ) - genai.configure(api_key=api_key) + self.client = genai.Client(api_key=api_key) self.model = model self.temperature = temperature self.max_output = max_output - self.generation_config = { - "temperature": temperature, - "top_p": 1, - "top_k": 40, - "max_output_tokens": max_output, - "response_mime_type": "text/plain", - } - block_level = HarmBlockThreshold.BLOCK_ONLY_HIGH - self.safety_settings={ - HarmCategory.HARM_CATEGORY_HATE_SPEECH: block_level, - HarmCategory.HARM_CATEGORY_HARASSMENT: block_level, - HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: block_level, - HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: block_level, + self.safety_settings = [ + types.SafetySetting( + category = HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold = block_level, + ), + types.SafetySetting( + category = HarmCategory.HARM_CATEGORY_HARASSMENT, + threshold = block_level, + ), + types.SafetySetting( + category = HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, + threshold = block_level, + ), + types.SafetySetting( + category = HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold = block_level, + ), # There is a documentation conflict on whether or not # CIVIC_INTEGRITY is a valid category # HarmCategory.HARM_CATEGORY_CIVIC_INTEGRITY: block_level, - } - - self.llm = genai.GenerativeModel( - model_name=model, - generation_config=self.generation_config, - safety_settings=self.safety_settings, - system_instruction="You are a helpful AI assistant.", - ) + ] print("Initialised", flush=True) async def generate_content(self, system, prompt): - # FIXME: There's a system prompt above. Maybe if system changes, - # then reset self.llm? It shouldn't do, because system prompt - # is set system wide? - - # Or... could keep different LLM structures for different system - # prompts? - - prompt = system + "\n\n" + prompt + generation_config = types.GenerateContentConfig( + temperature = self.temperature, + top_p = 1, + top_k = 40, + max_output_tokens = self.max_output, + response_mime_type = "text/plain", + system_instruction = system, + safety_settings = self.safety_settings, + ) try: - chat_session = self.llm.start_chat( - history=[ - ] + response = self.client.models.generate_content( + model=self.model, + config=generation_config, + contents=prompt, ) - response = chat_session.send_message(prompt) resp = response.text inputtokens = int(response.usage_metadata.prompt_token_count) @@ -158,3 +164,4 @@ class Processor(LlmService): def run(): Processor.launch(default_ident, __doc__) + diff --git a/trustgraph-flow/trustgraph/model/text_completion/tgi/__init__.py b/trustgraph-flow/trustgraph/model/text_completion/tgi/__init__.py new file mode 100644 index 00000000..f2017af8 --- /dev/null +++ b/trustgraph-flow/trustgraph/model/text_completion/tgi/__init__.py @@ -0,0 +1,3 @@ + +from . llm import * + diff --git a/trustgraph-flow/trustgraph/model/text_completion/tgi/__main__.py b/trustgraph-flow/trustgraph/model/text_completion/tgi/__main__.py new file mode 100755 index 00000000..91342d2d --- /dev/null +++ b/trustgraph-flow/trustgraph/model/text_completion/tgi/__main__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +from . llm import run + +if __name__ == '__main__': + run() + diff --git a/trustgraph-flow/trustgraph/model/text_completion/tgi/llm.py b/trustgraph-flow/trustgraph/model/text_completion/tgi/llm.py new file mode 100755 index 00000000..fa7c15c0 --- /dev/null +++ b/trustgraph-flow/trustgraph/model/text_completion/tgi/llm.py @@ -0,0 +1,137 @@ + +""" +Simple LLM service, performs text prompt completion using HuggingFace TGI +Input is prompt, output is response. +""" + +import os +import aiohttp + +from .... exceptions import TooManyRequests +from .... base import LlmService, LlmResult + +default_ident = "text-completion" + +default_temperature = 0.0 +default_max_output = 2048 +default_base_url = os.getenv("TGI_BASE_URL") + +if default_base_url == "" or default_base_url is None: + default_base_url = "http://tgi-service:8899/v1" + +class Processor(LlmService): + + def __init__(self, **params): + + base_url = params.get("url", default_base_url) + temperature = params.get("temperature", default_temperature) + max_output = params.get("max_output", default_max_output) + + super(Processor, self).__init__( + **params | { + "temperature": temperature, + "max_output": max_output, + "url": base_url, + } + ) + + self.base_url = base_url + self.temperature = temperature + self.max_output = max_output + + self.session = aiohttp.ClientSession() + + print("Using TGI service at", base_url) + + print("Initialised", flush=True) + + async def generate_content(self, system, prompt): + + headers = { + "Content-Type": "application/json", + } + + request = { + "model": "tgi", + "messages": [ + { + "role": "system", + "content": system, + }, + { + "role": "user", + "content": prompt, + } + ], + "max_tokens": self.max_output, + "temperature": self.temperature, + } + + try: + + url = f"{self.base_url}/chat/completions" + + async with self.session.post( + url, + headers=headers, + json=request, + ) as response: + + if response.status != 200: + raise RuntimeError("Bad status: " + str(response.status)) + + resp = await response.json() + + inputtokens = resp["usage"]["prompt_tokens"] + outputtokens = resp["usage"]["completion_tokens"] + ans = resp["choices"][0]["message"]["content"] + print(f"Input Tokens: {inputtokens}", flush=True) + print(f"Output Tokens: {outputtokens}", flush=True) + print(ans, flush=True) + + resp = LlmResult( + text = ans, + in_token = inputtokens, + out_token = outputtokens, + model = "tgi", + ) + + return resp + + # FIXME: Assuming TGI won't produce rate limits? + + except Exception as e: + + # Apart from rate limits, treat all exceptions as unrecoverable + + print(f"Exception: {type(e)} {e}") + raise e + + @staticmethod + def add_args(parser): + + LlmService.add_args(parser) + + parser.add_argument( + '-u', '--url', + default=default_base_url, + help=f'TGI service base URL (default: {default_base_url})' + ) + + parser.add_argument( + '-t', '--temperature', + type=float, + default=default_temperature, + help=f'LLM temperature parameter (default: {default_temperature})' + ) + + parser.add_argument( + '-x', '--max-output', + type=int, + default=default_max_output, + help=f'LLM max output tokens (default: {default_max_output})' + ) + +def run(): + + Processor.launch(default_ident, __doc__) diff --git a/trustgraph-ocr/setup.py b/trustgraph-ocr/setup.py index 5e2531fe..182b0f85 100644 --- a/trustgraph-ocr/setup.py +++ b/trustgraph-ocr/setup.py @@ -34,7 +34,7 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", "pulsar-client", "prometheus-client", "boto3", diff --git a/trustgraph-vertexai/setup.py b/trustgraph-vertexai/setup.py index 5381c043..bb624d6f 100644 --- a/trustgraph-vertexai/setup.py +++ b/trustgraph-vertexai/setup.py @@ -34,7 +34,7 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", "pulsar-client", "google-cloud-aiplatform", "prometheus-client", diff --git a/trustgraph-vertexai/trustgraph/model/text_completion/vertexai/llm.py b/trustgraph-vertexai/trustgraph/model/text_completion/vertexai/llm.py index 854be961..c6d869e6 100755 --- a/trustgraph-vertexai/trustgraph/model/text_completion/vertexai/llm.py +++ b/trustgraph-vertexai/trustgraph/model/text_completion/vertexai/llm.py @@ -4,13 +4,26 @@ Simple LLM service, performs text prompt completion using VertexAI on Google Cloud. Input is prompt, output is response. """ +# +# Somewhat perplexed by the Google Cloud SDK choices. We're going off this +# one, which uses the google-cloud-aiplatform library: +# https://cloud.google.com/python/docs/reference/vertexai/1.94.0 +# It seems it is possible to invoke VertexAI from the google-genai +# SDK too: +# https://googleapis.github.io/python-genai/genai.html#module-genai.client +# That would make this code look very much like the GoogleAIStudio +# code. And maybe not reliant on the google-cloud-aiplatform library? +# +# This module's imports bring in a lot of libraries. + from google.oauth2 import service_account import google import vertexai -from vertexai.preview.generative_models import ( +# Why is preview here? +from vertexai.generative_models import ( Content, FunctionDeclaration, GenerativeModel, GenerationConfig, - HarmCategory, HarmBlockThreshold, Part, Tool, + HarmCategory, HarmBlockThreshold, Part, Tool, SafetySetting, ) from .... exceptions import TooManyRequests @@ -18,7 +31,7 @@ from .... base import LlmService, LlmResult default_ident = "text-completion" -default_model = 'gemini-1.0-pro-001' +default_model = 'gemini-2.0-flash-001' default_region = 'us-central1' default_temperature = 0.0 default_max_output = 8192 @@ -59,12 +72,24 @@ class Processor(LlmService): block_level = HarmBlockThreshold.BLOCK_ONLY_HIGH # block_level = HarmBlockThreshold.BLOCK_NONE - self.safety_settings = { - HarmCategory.HARM_CATEGORY_HARASSMENT: block_level, - HarmCategory.HARM_CATEGORY_HATE_SPEECH: block_level, - HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: block_level, - HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: block_level, - } + self.safety_settings = [ + SafetySetting( + category = HarmCategory.HARM_CATEGORY_HARASSMENT, + threshold = block_level, + ), + SafetySetting( + category = HarmCategory.HARM_CATEGORY_HATE_SPEECH, + threshold = block_level, + ), + SafetySetting( + category = HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, + threshold = block_level, + ), + SafetySetting( + category = HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, + threshold = block_level, + ), + ] print("Initialise VertexAI...", flush=True) @@ -101,8 +126,8 @@ class Processor(LlmService): prompt = system + "\n\n" + prompt response = self.llm.generate_content( - prompt, generation_config=self.generation_config, - safety_settings=self.safety_settings + prompt, generation_config = self.generation_config, + safety_settings = self.safety_settings, ) resp = LlmResult( diff --git a/trustgraph/setup.py b/trustgraph/setup.py index bf846295..866be9fe 100644 --- a/trustgraph/setup.py +++ b/trustgraph/setup.py @@ -34,12 +34,12 @@ setuptools.setup( python_requires='>=3.8', download_url = "https://github.com/trustgraph-ai/trustgraph/archive/refs/tags/v" + version + ".tar.gz", install_requires=[ - "trustgraph-base>=0.23,<0.24", - "trustgraph-bedrock>=0.23,<0.24", - "trustgraph-cli>=0.23,<0.24", - "trustgraph-embeddings-hf>=0.23,<0.24", - "trustgraph-flow>=0.23,<0.24", - "trustgraph-vertexai>=0.23,<0.24", + "trustgraph-base>=1.0,<1.1", + "trustgraph-bedrock>=1.0,<1.1", + "trustgraph-cli>=1.0,<1.1", + "trustgraph-embeddings-hf>=1.0,<1.1", + "trustgraph-flow>=1.0,<1.1", + "trustgraph-vertexai>=1.0,<1.1", ], scripts=[ ]