text-generation-inference/router/src
drbh c5e3357293 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-06-10 14:05:29 +03:00
..
config.rs Idefics2. (#1756) 2024-06-10 09:29:08 +03:00
health.rs Outlines guided generation (#1539) 2024-04-24 14:57:37 +03:00
infer.rs feat: improve tools to include name and add tests (#1693) 2024-06-03 15:39:47 +03:00
lib.rs Handle images in chat api (#1828) 2024-06-10 14:05:29 +03:00
main.rs Adding support for HF_HUB_OFFLINE support in the router. (#1789) 2024-06-10 09:49:33 +03:00
queue.rs Improve the defaults for the launcher (#1727) 2024-04-26 07:22:04 +00:00
server.rs Use the generation config. (#1808) 2024-06-10 09:53:00 +03:00
validation.rs Idefics2. (#1756) 2024-06-10 09:29:08 +03:00