8
8
9
9
CONST_MODEL_NAME = "odsc-vllm"
10
10
CONST_ENDPOINT = "https://oci.endpoint/ocid/predict"
11
- CONST_PROMPT_FOR_COMPLETION = "This is a prompt."
11
+ CONST_PROMPT = "This is a prompt."
12
12
CONST_COMPLETION = "This is a completion."
13
13
CONST_COMPLETION_RESPONSE = {
14
- "choices" : [{"index" : 0 , "text" : CONST_COMPLETION }],
14
+ "choices" : [
15
+ {
16
+ "index" : 0 ,
17
+ "text" : CONST_COMPLETION ,
18
+ "logprobs" : 0.1 ,
19
+ "finish_reason" : "length" ,
20
+ }
21
+ ],
15
22
}
16
23
CONST_COMPLETION_RESPONSE_TGI = {"generated_text" : CONST_COMPLETION }
17
24
CONST_STREAM_TEMPLATE = (
@@ -68,7 +75,7 @@ def text(self):
68
75
prompt = payload .get ("prompt" )
69
76
is_tgi = False
70
77
71
- if prompt == CONST_PROMPT_FOR_COMPLETION :
78
+ if prompt == CONST_PROMPT :
72
79
if is_tgi :
73
80
return MockResponse (json_data = CONST_COMPLETION_RESPONSE_TGI )
74
81
return MockResponse (json_data = CONST_COMPLETION_RESPONSE )
@@ -91,7 +98,7 @@ async def mocked_async_streaming_response(*args, **kwargs):
91
98
def test_invoke_vllm (mock_post , mock_auth ) -> None :
92
99
"""Tests invoking vLLM endpoint."""
93
100
llm = OCIModelDeploymentVLLM (endpoint = CONST_ENDPOINT , model = CONST_MODEL_NAME )
94
- output = llm .invoke (CONST_PROMPT_FOR_COMPLETION )
101
+ output = llm .invoke (CONST_PROMPT )
95
102
assert output == CONST_COMPLETION
96
103
97
104
@@ -105,7 +112,7 @@ def test_stream_tgi(mock_post, mock_auth) -> None:
105
112
)
106
113
output = ""
107
114
count = 0
108
- for chunk in llm .stream (CONST_PROMPT_FOR_COMPLETION ):
115
+ for chunk in llm .stream (CONST_PROMPT ):
109
116
output += chunk
110
117
count += 1
111
118
assert count == 4
@@ -120,7 +127,7 @@ def test_generate_tgi(mock_post, mock_auth) -> None:
120
127
llm = OCIModelDeploymentTGI (
121
128
endpoint = CONST_ENDPOINT , api = "/generate" , model = CONST_MODEL_NAME
122
129
)
123
- output = llm .invoke (CONST_PROMPT_FOR_COMPLETION )
130
+ output = llm .invoke (CONST_PROMPT )
124
131
assert output == CONST_COMPLETION
125
132
126
133
@@ -144,5 +151,5 @@ async def test_stream_async(mock_auth):
144
151
mock .MagicMock (return_value = mocked_async_streaming_response ()),
145
152
):
146
153
147
- chunks = [chunk async for chunk in llm .astream (CONST_PROMPT_FOR_COMPLETION )]
154
+ chunks = [chunk async for chunk in llm .astream (CONST_PROMPT )]
148
155
assert "" .join (chunks ).strip () == CONST_COMPLETION
0 commit comments