Pipeline
Installation
# you can use a Conda environment
pip install --extra-index-url https://oauth2accesstoken:$(gcloud auth print-access-token)@glsdk.gdplabs.id/gen-ai-internal/simple/ "gllm-pipeline"# you can use a Conda environment
$token = (gcloud auth print-access-token)
pip install --extra-index-url "https://oauth2accesstoken:$token@glsdk.gdplabs.id/gen-ai-internal/simple/" "gllm-pipeline"# you can use a Conda environment
FOR /F "tokens=*" %T IN ('gcloud auth print-access-token') DO pip install --extra-index-url "gllm-pipeline"Quickstart
1
from typing import TypedDict # Optional, only for custom states
from gllm_pipeline.pipeline.pipeline import Pipeline
from gllm_pipeline.steps._func import step, transform, bundle, log, subgraph2
class MiniState(TypedDict):
text: str
text_upper: str
text_len: int
summary: dict # summary bundle3
def to_upper(data: dict) -> str:
return data["text"].upper()
def count_chars(data: dict) -> int:
return len(data["text_upper"])
pipe = Pipeline(
steps=[
transform(to_upper, input_map=["text"], output_state="text_upper"),
transform(count_chars, input_map=["text_upper"], output_state="text_len"),
bundle(["text", "text_upper", "text_len"], output_state="summary"),
],
state_type=MiniState,
)4
import asyncio
initial: MiniState = {
"text": "hello world",
"text_upper": "",
"text_len": 0,
"summary": {},
}
final = asyncio.run(pipe.invoke(initial))
print(final){'text': 'hello world', 'text_upper': 'HELLO WORLD', 'text_len': 11,
'summary': {'text': 'hello world', 'text_upper': 'HELLO WORLD', 'text_len': 11}}The Pipe Operator
Appending a Step
Merge Two Pipelines
Placeholder Pipelines
Visualizing the Pipeline
Runtime Configuration
Input and Output Schema
Using TypedDict for Simple Schemas
Using Pydantic for Validation
Converting to a Tool
Using the Debug State
Using a Pipeline as a Subgraph
Using the Leftshift (<<) Operator
Last updated
Was this helpful?