File size: 4,206 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pytest  # noqa F401
from dotenv import load_dotenv

from neollm import MyLLM
from neollm.types import Messages, Response
from neollm.utils.inference import execute_parallel

env_file_path = "project/.env"
assert load_dotenv(env_file_path, override=True)


class SampleMyLLM(MyLLM[str, str]):
    def _preprocess(self, inputs: str) -> Messages:
        messages: Messages = [
            {"role": "system", "content": ("1+1={int}")},
            {"role": "user", "content": str(inputs) + "\n{int}"},
        ]
        return messages

    def _postprocess(self, response: Response) -> str:
        return response.choices[0].message.content or ""


class TestMyLLM:
    def call_myllm(self, model: str, platform: str) -> None:
        myllm = SampleMyLLM(model=model, platform=platform, llm_settings={"max_tokens": 1})
        myllm("1+1")

    def call_stream_myllm(self, model: str, platform: str) -> None:
        myllm = SampleMyLLM(model=model, platform=platform)
        myllm.call_stream("1+1")

    def test_azure(self) -> None:
        kwargs = [
            {"model": model, "platform": "azure"}
            for model in [
                # "gpt-4o-2024-05-13", # 2024/05/15時点、AOAIで使用不可(リージョン不明)
                # "gpt-4-turbo-2024-04-09", # スウェーデンにない
                # "gpt-3.5-turbo-0125",# スウェーデンにない
                # "gpt-4-turbo-0125",# スウェーデンにない
                "gpt-3.5-turbo-1106",
                "gpt-4-turbo-1106",
                # "gpt-4v-turbo-1106", # スウェーデンにない
                "gpt-3.5-turbo-0613",
                "gpt-3.5-turbo-16k-0613",
                "gpt-4-0613",
                "gpt-4-32k-0613",
                # w/o date
                "gpt-4-turbo",
                "gpt-3.5-turbo",
                # "gpt-4v-turbo", # スウェーデンにない
                "gpt-3.5-turbo-16k",
                "gpt-4",
                "gpt-4-32k",
            ]
        ]
        execute_parallel(self.call_myllm, kwargs, max_workers=10)
        execute_parallel(self.call_stream_myllm, kwargs, max_workers=10)

    def test_openai(self) -> None:
        kwargs = [
            {"model": model, "platform": "openai"}
            for model in [
                "gpt-4o-2024-05-13",
                "gpt-4-turbo-2024-04-09",
                "gpt-3.5-turbo-0125",
                "gpt-4-turbo-0125",
                "gpt-3.5-turbo-1106",
                "gpt-4-turbo-1106",
                "gpt-4v-turbo-1106",
                "gpt-3.5-turbo-0613",
                "gpt-3.5-turbo-16k-0613",
                "gpt-4-0613",
                # "gpt-4-32k-0613", # 使えなくなってる
                # w/o date
                "gpt-4-turbo",
                "gpt-3.5-turbo",
                "gpt-4v-turbo",
                "gpt-3.5-turbo-16k",
                "gpt-4",
                # "gpt-4-32k", # 使えなくなってる
            ]
        ]
        execute_parallel(self.call_myllm, kwargs, max_workers=10)
        execute_parallel(self.call_stream_myllm, kwargs, max_workers=10)

    def test_anthropic(self) -> None:
        kwargs = [
            {"model": model, "platform": "anthropic"}
            for model in [
                "claude-3-opus",
                "claude-3-sonnet",
                "claude-3-haiku",
                "claude-3-opus-20240229",
                "claude-3-sonnet-20240229",
                "claude-3-haiku-20240307",
            ]
        ]
        execute_parallel(self.call_myllm, kwargs, max_workers=10)
        execute_parallel(self.call_stream_myllm, kwargs, max_workers=10)

    # TODO! google
    def _test_gcp(self) -> None:
        kwargs = [
            {"model": model, "platform": "gcp"}
            for model in [
                "claude-3-opus",
                "claude-3-sonnet",
                "claude-3-haiku",
                "claude-3-opus@20240229",
                "claude-3-sonnet@20240229",
                "claude-3-haiku@20240307",
            ]
        ]
        execute_parallel(self.call_myllm, kwargs, max_workers=10)
        execute_parallel(self.call_stream_myllm, kwargs, max_workers=10)