|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 2 | +# contributor license agreements. See the NOTICE file distributed with |
| 3 | +# this work for additional information regarding copyright ownership. |
| 4 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 5 | +# (the "License"); you may not use this file except in compliance with |
| 6 | +# the License. You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +fixtures: |
| 17 | + - name: mock_pipeline |
| 18 | + type: unittest.mock.patch |
| 19 | + config: |
| 20 | + target: transformers.pipeline |
| 21 | + |
| 22 | +pipelines: |
| 23 | + - pipeline: |
| 24 | + type: chain |
| 25 | + transforms: |
| 26 | + - type: Create |
| 27 | + config: |
| 28 | + elements: |
| 29 | + - text: "Hello world" |
| 30 | + - text: "Bye world" |
| 31 | + - type: RunInference |
| 32 | + config: |
| 33 | + model_handler: |
| 34 | + type: "HuggingFacePipeline" |
| 35 | + config: |
| 36 | + task: "text-classification" |
| 37 | + model: "unused" |
| 38 | + inference_fn: |
| 39 | + callable: | |
| 40 | + def mock_inference(batch, pipeline, inference_args): |
| 41 | + return [[dict(label='POSITIVE', score=0.9)] for _ in batch] |
| 42 | + preprocess: |
| 43 | + callable: 'lambda x: x.text' |
| 44 | + - type: MapToFields |
| 45 | + config: |
| 46 | + language: python |
| 47 | + fields: |
| 48 | + text: text |
| 49 | + inference: |
| 50 | + callable: | |
| 51 | + def get_json(x): |
| 52 | + import json |
| 53 | + return json.dumps(x.inference.inference, indent=0).strip() |
| 54 | + - type: AssertEqual |
| 55 | + config: |
| 56 | + elements: |
| 57 | + - text: "Hello world" |
| 58 | + inference: "[\n{\n\"label\": \"POSITIVE\",\n\"score\": 0.9\n}\n]" |
| 59 | + - text: "Bye world" |
| 60 | + inference: "[\n{\n\"label\": \"POSITIVE\",\n\"score\": 0.9\n}\n]" |
| 61 | + options: |
| 62 | + yaml_experimental_features: ['ML'] |
0 commit comments