File size: 2,642 Bytes
88435ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from typing import Literal

from neollm.types._model import DictableBaseModel

PrintColor = Literal["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]


class TimeInfo(DictableBaseModel):
    total: float = 0.0
    """処理時間合計 preprocess + main + postprocess"""
    preprocess: float = 0.0
    """前処理時間"""
    main: float = 0.0
    """メイン処理時間"""
    postprocess: float = 0.0
    """後処理時間"""

    def __repr__(self) -> str:
        return (
            f"TimeInfo(total={self.total:.3f}, preprocess={self.preprocess:.3f}, main={self.main:.3f}, "
            f"postprocess={self.postprocess:.3f})"
        )


class TokenInfo(DictableBaseModel):
    input: int
    """入力部分のトークン数"""
    output: int
    """出力部分のトークン数"""
    total: int
    """合計トークン数"""

    def __add__(self, other: "TokenInfo") -> "TokenInfo":
        if not isinstance(other, TokenInfo):
            raise TypeError(f"{other} is not TokenInfo")
        return TokenInfo(
            input=self.input + other.input, output=self.output + other.output, total=self.total + other.total
        )

    def __iadd__(self, other: "TokenInfo") -> "TokenInfo":
        if not isinstance(other, TokenInfo):
            raise TypeError(f"{other} is not TokenInfo")
        self.input += other.input
        self.output += other.output
        self.total += other.total
        return self


class PriceInfo(DictableBaseModel):
    input: float
    """入力部分の費用 (USD)"""
    output: float
    """出力部分の費用 (USD)"""
    total: float
    """合計費用 (USD)"""

    def __add__(self, other: "PriceInfo") -> "PriceInfo":
        if not isinstance(other, PriceInfo):
            raise TypeError(f"{other} is not PriceInfo")
        return PriceInfo(
            input=self.input + other.input, output=self.output + other.output, total=self.total + other.total
        )

    def __iadd__(self, other: "PriceInfo") -> "PriceInfo":
        if not isinstance(other, PriceInfo):
            raise TypeError(f"{other} is not PriceInfo")
        self.input += other.input
        self.output += other.output
        self.total += other.total
        return self

    def __repr__(self) -> str:
        return f"PriceInfo(input={self.input:.3f}, output={self.output:.3f}, total={self.total:.3f})"


class APIPricing(DictableBaseModel):
    """APIの価格設定に関する情報を表すクラス。"""

    input: float
    """入力 1k tokens 当たりのAPI利用料 (USD)"""
    output: float
    """出力 1k tokens 当たりのAPI利用料 (USD)"""