cohere-python

Форк
0
38 строк · 1.4 Кб
1
# This file was auto-generated by Fern from our API Definition.
2

3
import typing
4

5
# File typing inspired by the flexibility of types within the httpx library
6
# https://github.com/encode/httpx/blob/master/httpx/_types.py
7
FileContent = typing.Union[typing.IO[bytes], bytes, str]
8
File = typing.Union[
9
    # file (or bytes)
10
    FileContent,
11
    # (filename, file (or bytes))
12
    typing.Tuple[typing.Optional[str], FileContent],
13
    # (filename, file (or bytes), content_type)
14
    typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str]],
15
    # (filename, file (or bytes), content_type, headers)
16
    typing.Tuple[typing.Optional[str], FileContent, typing.Optional[str], typing.Mapping[str, str]],
17
]
18

19

20
def convert_file_dict_to_httpx_tuples(
21
    d: typing.Dict[str, typing.Union[File, typing.List[File]]]
22
) -> typing.List[typing.Tuple[str, File]]:
23
    """
24
    The format we use is a list of tuples, where the first element is the
25
    name of the file and the second is the file object. Typically HTTPX wants
26
    a dict, but to be able to send lists of files, you have to use the list
27
    approach (which also works for non-lists)
28
    https://github.com/encode/httpx/pull/1032
29
    """
30

31
    httpx_tuples = []
32
    for key, file_like in d.items():
33
        if isinstance(file_like, list):
34
            for file_like_item in file_like:
35
                httpx_tuples.append((key, file_like_item))
36
        else:
37
            httpx_tuples.append((key, file_like))
38
    return httpx_tuples
39

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.