text-generation-inference/router/src
drbh c99ecd77ec
Handle images in chat api (#1828)
This PR allows for messages to be formatted as simple strings, or as an
array of objects including image urls. This is done by formatting
content arrays into a simple string.

Example using `llava-hf/llava-v1.6-mistral-7b-hf` 

```bash
curl localhost: 3000/v1/chat/completions \
-X POST \
-H 'Content-Type: application/json' \
-d '{
    "model": "tgi",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Whats in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png"
                    }
                }
            ]
        }
    ],
    "stream": false,
    "max_tokens": 20,
    "seed": 42
}'
```

is equivlant to this more simple request

```bash
curl localhost: 3000/v1/chat/completions \
-X POST \
-H 'Content-Type: application/json' \
-d '{
    "model": "tgi",
    "messages": [
        {
            "role": "user",
            "content": "Whats in this image?\n![](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/rabbit.png)"
        }
    ],
    "stream": false,
    "max_tokens": 20,
    "seed": 42
}'
```

output
```
# {"id":"","object":"text_completion","created":1714406985,"model":"llava-hf/llava-v1.6-mistral-7b-hf","system_fingerprint":"2.0.1-native","choices":[{"index":0,"message":{"role":"assistant","content":" This is an illustration of an anthropomorphic rabbit in a spacesuit, standing on what"},"logprobs":null,"finish_reason":"length"}],"usage":{"prompt_tokens":2945,"completion_tokens":20,"total_tokens":2965}}%
```

---------

Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
2024-04-30 12:18:32 +02:00
..
config.rs Idefics2. (#1756) 2024-04-23 23:04:44 +02:00
health.rs Outlines guided generation (#1539) 2024-02-15 10:28:10 +01:00
infer.rs feat: improve tools to include name and add tests (#1693) 2024-04-16 09:02:46 -04:00
lib.rs Handle images in chat api (#1828) 2024-04-30 12:18:32 +02:00
main.rs Adding support for HF_HUB_OFFLINE support in the router. (#1789) 2024-04-23 23:38:30 +02:00
queue.rs Improve the defaults for the launcher (#1727) 2024-04-12 14:20:31 +02:00
server.rs Use the generation config. (#1808) 2024-04-25 19:41:50 +02:00
validation.rs Idefics2. (#1756) 2024-04-23 23:04:44 +02:00