File size: 28,035 Bytes
4304c6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import os
from collections.abc import Generator

import pytest

from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk, LLMResultChunkDelta
from core.model_runtime.entities.message_entities import (
    AssistantPromptMessage,
    ImagePromptMessageContent,
    SystemPromptMessage,
    TextPromptMessageContent,
    UserPromptMessage,
)
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.model_runtime.model_providers.ollama.llm.llm import OllamaLargeLanguageModel


def test_validate_credentials():
    model = OllamaLargeLanguageModel()

    with pytest.raises(CredentialsValidateFailedError):
        model.validate_credentials(
            model='mistral:text',
            credentials={
                'base_url': 'http://localhost:21434',
                'mode': 'chat',
                'context_size': 2048,
                'max_tokens': 2048,
            }
        )

    model.validate_credentials(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'chat',
            'context_size': 2048,
            'max_tokens': 2048,
        }
    )


def test_invoke_model():
    model = OllamaLargeLanguageModel()

    response = model.invoke(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'chat',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            UserPromptMessage(
                content='Who are you?'
            )
        ],
        model_parameters={
            'temperature': 1.0,
            'top_k': 2,
            'top_p': 0.5,
            'num_predict': 10
        },
        stop=['How'],
        stream=False
    )

    assert isinstance(response, LLMResult)
    assert len(response.message.content) > 0


def test_invoke_stream_model():
    model = OllamaLargeLanguageModel()

    response = model.invoke(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'chat',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            SystemPromptMessage(
                content='You are a helpful AI assistant.',
            ),
            UserPromptMessage(
                content='Who are you?'
            )
        ],
        model_parameters={
            'temperature': 1.0,
            'top_k': 2,
            'top_p': 0.5,
            'num_predict': 10
        },
        stop=['How'],
        stream=True
    )

    assert isinstance(response, Generator)

    for chunk in response:
        assert isinstance(chunk, LLMResultChunk)
        assert isinstance(chunk.delta, LLMResultChunkDelta)
        assert isinstance(chunk.delta.message, AssistantPromptMessage)


def test_invoke_completion_model():
    model = OllamaLargeLanguageModel()

    response = model.invoke(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'completion',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            UserPromptMessage(
                content='Who are you?'
            )
        ],
        model_parameters={
            'temperature': 1.0,
            'top_k': 2,
            'top_p': 0.5,
            'num_predict': 10
        },
        stop=['How'],
        stream=False
    )

    assert isinstance(response, LLMResult)
    assert len(response.message.content) > 0


def test_invoke_stream_completion_model():
    model = OllamaLargeLanguageModel()

    response = model.invoke(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'completion',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            SystemPromptMessage(
                content='You are a helpful AI assistant.',
            ),
            UserPromptMessage(
                content='Who are you?'
            )
        ],
        model_parameters={
            'temperature': 1.0,
            'top_k': 2,
            'top_p': 0.5,
            'num_predict': 10
        },
        stop=['How'],
        stream=True
    )

    assert isinstance(response, Generator)

    for chunk in response:
        assert isinstance(chunk, LLMResultChunk)
        assert isinstance(chunk.delta, LLMResultChunkDelta)
        assert isinstance(chunk.delta.message, AssistantPromptMessage)


def test_invoke_completion_model_with_vision():
    model = OllamaLargeLanguageModel()

    result = model.invoke(
        model='llava',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'completion',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            UserPromptMessage(
                content=[
                    TextPromptMessageContent(
                        data='What is this in this picture?',
                    ),
                    ImagePromptMessageContent(
                        data='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE4AAABMCAYAAADDYoEWAAAMQGlDQ1BJQ0MgU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5qP85wFnIZrXQHgillpVesHh9QVaAWWAJccfo/VNrOcbmrbYn/vCR9gy2m1aUH2WOa/rv4UoKnhPODowC2Gx6jQo4Nox4ZinDL392ssIHFSZWa1rTZJD/wSy0Kn34eDpwZvP1w96+dmH25zrsQs4KSLP4GAawWSjhnFZZQFmUZxOZSTj/ne2yUhIHCjRIlFKcIU0x852RjZTGGlDdaQrkxk7MPrJr/gzg17r4vgJ3rMAk4/wmQDE7wJhg+fFV1xaMGiMqnXaFc5jd4FjCCIRAEmAO5aPE7lzsw0ZelHYJB0PCWscErqOJcsrbllGmhmzE/7mAXcPof544Wlqg6wTuORtvKQzjV2gVC+shaNMhc24v8iIloGmS3ogc7bD9sS884Oi0kEP89jFnDX++/hCtPVtT7kwaxOkZpmxQ/L9vgdj1r+NCtAwQ6/A9DXMXnBqZgoHDdXP7Wna/Id6PRCum7DiREqcg1UPw9Yp6MsLv/HwlM4Hp7WQ1/CGQhcgDsDNJtcgLsAdyYCZza7MO4C3JkInNnswrgLcGcicGazC+POBO7/AH5zPa/ivytzAAAAAElFTkSuQmCC'
                    )
                ]
            )
        ],
        model_parameters={
            'temperature': 0.1,
            'num_predict': 100
        },
        stream=False,
    )

    assert isinstance(result, LLMResult)
    assert len(result.message.content) > 0


def test_invoke_chat_model_with_vision():
    model = OllamaLargeLanguageModel()

    result = model.invoke(
        model='llava',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'chat',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            UserPromptMessage(
                content=[
                    TextPromptMessageContent(
                        data='What is this in this picture?',
                    ),
                    ImagePromptMessageContent(
                        data='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAE4AAABMCAYAAADDYoEWAAAMQGlDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnluSkEBoAQSkhN4EkRpASggt9I4gKiEJEEqMgaBiRxcVXLuIgA1dFVGwAmJBETuLYu+LBRVlXSzYlTcpoOu+8r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rTZJD/wSy0Kn34eDpwZvP1w96+dmH25zrsQs4KSLP4GAawWSjhnFZZQFmUZxOZSTj/ne2yUhIHCjRIlFKcIU0x852RjZTGGlDdaQrkxk7MPrJr/gzg17r4vgJ3rMAk4/wmQDE7wJhg+fFV1xaMGiMqnXaFc5jd4FjCCIRAEmAO5aPE7lzsw0ZelHYJB0PCWscErqOJcsrbllGmhmzE/7mAXcPof544Wlqg6wTuORtvKQzjV2gVC+shaNMhc24v8iIloGmS3ogc7bD9sS884Oi0kEP89jFnDX++/hCtPVtT7kwaxOkZpmxQ/L9vgdj1r+NCtAwQ6/A9DXMXnBqZgoHDdXP7Wna/Id6PRCum7DiREqcg1UPw9Yp6MsLv/HwlM4Hp7WQ1/CGQhcgDsDNJtcgLsAdyYCZza7MO4C3JkInNnswrgLcGcicGazC+POBO7/AH5zPa/ivytzAAAAAElFTkSuQmCC'
                    )
                ]
            )
        ],
        model_parameters={
            'temperature': 0.1,
            'num_predict': 100
        },
        stream=False,
    )

    assert isinstance(result, LLMResult)
    assert len(result.message.content) > 0


def test_get_num_tokens():
    model = OllamaLargeLanguageModel()

    num_tokens = model.get_num_tokens(
        model='mistral:text',
        credentials={
            'base_url': os.environ.get('OLLAMA_BASE_URL'),
            'mode': 'chat',
            'context_size': 2048,
            'max_tokens': 2048,
        },
        prompt_messages=[
            UserPromptMessage(
                content='Hello World!'
            )
        ]
    )

    assert isinstance(num_tokens, int)
    assert num_tokens == 6