Pipelines/docker_pipeline.py

41 lines
1.7 KiB
Python
Raw Normal View History

2025-02-04 12:27:17 -08:00
import os
import requests
from typing import Literal, List, Optional
from blueprints.function_calling_blueprint import Pipeline as FunctionCallingBlueprint
class Pipeline(FunctionCallingBlueprint):
class Tools:
def __init__(self, pipeline) -> None:
self.pipeline = pipeline
2025-02-11 09:35:06 -08:00
def call_docker(
self,image: str,command: Optional[str] = None):
2025-02-04 12:27:17 -08:00
"""
2025-02-11 09:35:06 -08:00
Run a Docker container tool with the specified image and an optional command.
:param image: The Docker image name to run
:param command: Optional command to run in the container (default: None)
:return: The output from running the Docker container
2025-02-04 12:27:17 -08:00
"""
2025-02-11 09:35:06 -08:00
docker_cmd = f"docker run {image}"
if command:
docker_cmd += f" {command}"
2025-02-11 10:04:38 -08:00
return docker_cmd #os.system(docker_cmd)
2025-02-04 12:27:17 -08:00
def __init__(self):
2025-02-11 09:38:56 -08:00
super().__init__()
2025-02-04 12:27:17 -08:00
# Optionally, you can set the id and name of the pipeline.
# Best practice is to not specify the id so that it can be automatically inferred from the filename, so that users can install multiple versions of the same pipeline.
# The identifier must be unique across all pipelines.
# The identifier must be an alphanumeric string that can include underscores or hyphens. It cannot contain spaces, special characters, slashes, or backslashes.
2025-02-11 09:35:06 -08:00
# self.id = "my_tools_pipeline"
2025-02-11 09:38:56 -08:00
self.name = "Docker Tool Pipeline"
self.valves = self.Valves(
**{
**self.valves.model_dump(),
"pipelines": ["pipeline-testmodel"], # Connect to all pipelines
},
)
self.tools = self.Tools(self)