|
| 1 | +# Model Pipelines |
| 2 | + |
| 3 | +Ansible AI Connect is becoming feature rich. |
| 4 | + |
| 5 | +It supports API for the following features: |
| 6 | +- Code completions |
| 7 | +- Content match |
| 8 | +- Playbook Generation |
| 9 | +- Role Generation |
| 10 | +- Playbook Explanation |
| 11 | +- Chat Bot |
| 12 | + |
| 13 | +"Model Pipelines" provides a mechanism to support different _pipelines_ and configuration for each of these features for different providers. Different providers require different configuration information. |
| 14 | + |
| 15 | +## Pipelines |
| 16 | + |
| 17 | +A pipeline can exist for each feature for each type of provider. |
| 18 | + |
| 19 | +Types of provider are: |
| 20 | +- `grpc` |
| 21 | +- `http` |
| 22 | +- `dummy` |
| 23 | +- `wca` |
| 24 | +- `wca-onprem` |
| 25 | +- `wca-dummy` |
| 26 | +- `ollama` |
| 27 | +- `llamacpp` |
| 28 | +- `nop` |
| 29 | + |
| 30 | +### Implementing pipelines |
| 31 | + |
| 32 | +Implementations of a pipeline, for a particular provider, for a particular feature should extend the applicable base class; implementing the `invoke(..)` method accordingly: |
| 33 | +- `ModelPipelineCompletions` |
| 34 | +- `ModelPipelineContentMatch` |
| 35 | +- `ModelPipelinePlaybookGeneration` |
| 36 | +- `ModelPipelineRoleGeneration` |
| 37 | +- `ModelPipelinePlaybookExplanation` |
| 38 | +- `ModelPipelineChatBot` |
| 39 | + |
| 40 | +### Registering pipelines |
| 41 | + |
| 42 | +Implementations of pipelines, per provider, per feature are dynamically registered. To register a pipeline the implementing class should be decorated with `@Register(api_type="<type>")`. |
| 43 | + |
| 44 | +In addition to the supported features themselves implementations for the following must also be provided and registered: |
| 45 | +- `MetaData` |
| 46 | + |
| 47 | + A class providing basic meta-data for all features for the applicable provider. |
| 48 | + |
| 49 | + For example API Key, Model ID, Timeout etc. |
| 50 | + |
| 51 | + |
| 52 | +- `PipelineConfiguration` |
| 53 | + |
| 54 | + A class representing the pipelines configuration parameters. |
| 55 | + |
| 56 | + |
| 57 | +- `Serializer` |
| 58 | + |
| 59 | + A class that can deserialise configuration JSON/YAML into the target `PipelineConfiguration` class. |
| 60 | + |
| 61 | +### Default implementations |
| 62 | + |
| 63 | +A "No Operation" pipeline is registered by default for each provider and each feature where a concrete implementation is not explicitly available. |
| 64 | + |
| 65 | +### Lookup |
| 66 | + |
| 67 | +A registry is constructed at start-up, containing information of configured pipelines for all providers for all features. |
| 68 | +``` |
| 69 | +REGISTRY = { |
| 70 | + "http": { |
| 71 | + MetaData: <Implementing class>, |
| 72 | + ModelPipelineCompletions: <Implementing class> |
| 73 | + ModelPipelineContentMatch: <Implementing class> |
| 74 | + ModelPipelinePlaybookGeneration: <Implementing class> |
| 75 | + ModelPipelineRoleGeneration: <Implementing class> |
| 76 | + ModelPipelinePlaybookExplanation: <Implementing class> |
| 77 | + ModelPipelineChatBot: <Implementing class> |
| 78 | + PipelineConfiguration: <Implementing class> |
| 79 | + Serializer: <Implementing class> |
| 80 | + } |
| 81 | + ... |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +To invoke a pipeline for a particular feature the instance for the configured provider can be retrieved from the `ai` Django application: |
| 86 | +``` |
| 87 | +pipeline: ModelPipelinePlaybookGeneration = |
| 88 | + apps |
| 89 | + .get_app_config("ai") |
| 90 | + .get_model_pipeline(ModelPipelinePlaybookGeneration) |
| 91 | +``` |
| 92 | +The pipeline can then be invoked: |
| 93 | +``` |
| 94 | +playbook, outline, warnings = pipeline.invoke( |
| 95 | + PlaybookGenerationParameters.init( |
| 96 | + request=request, |
| 97 | + text=self.validated_data["text"], |
| 98 | + custom_prompt=self.validated_data["customPrompt"], |
| 99 | + create_outline=self.validated_data["createOutline"], |
| 100 | + outline=self.validated_data["outline"], |
| 101 | + generation_id=self.validated_data["generationId"], |
| 102 | + model_id=self.req_model_id, |
| 103 | + ) |
| 104 | +) |
| 105 | +``` |
| 106 | +The code is identical irrespective of which provider is configured. |
| 107 | + |
| 108 | +### Configuration |
| 109 | + |
| 110 | +Refer to the [examples](../../../../docs/config). |
0 commit comments