Pipelines/docker_pipeline.py

39 lines
1.6 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}"
return os.system(docker_cmd)
2025-02-04 12:27:17 -08:00
def __init__(self):
2025-02-04 12:35:42 -08:00
self.valves = self.Valves(
**{
2025-02-11 09:35:06 -08:00
"pipelines": ["pipeline-testmodel"], # Connect to test pipeline
2025-02-04 12:35:42 -08:00
}
)
2025-02-04 12:40:12 -08:00
self.tools = self.Tools(self)
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"