Skip to content

Commit 4bf975e

Browse files
committed
test: Added a unittest
1 parent 21d3da8 commit 4bf975e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/unittests/clients/studio/resources/conftest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pytest_mock import MockerFixture
33

44
from ai21.ai21_http_client import AI21HTTPClient
5+
from ai21.clients.studio.resources.chat import ChatCompletions
56
from ai21.clients.studio.resources.studio_answer import StudioAnswer
67
from ai21.clients.studio.resources.studio_chat import StudioChat
78
from ai21.clients.studio.resources.studio_completion import StudioCompletion
@@ -43,7 +44,13 @@
4344
SummarizeBySegmentResponse,
4445
SegmentSummary,
4546
)
47+
from ai21.models.chat import (
48+
ChatMessage as ChatCompletionChatMessage,
49+
ChatCompletionResponse,
50+
ChatCompletionResponseChoice,
51+
)
4652
from ai21.models.responses.segmentation_response import Segment
53+
from ai21.models.usage_info import UsageInfo
4754
from ai21.utils.typing import to_lower_camel_case
4855

4956

@@ -110,6 +117,45 @@ def get_studio_chat():
110117
)
111118

112119

120+
def get_chat_completions():
121+
_DUMMY_MODEL = "dummy-chat-model"
122+
_DUMMY_MESSAGES = [
123+
ChatCompletionChatMessage(content="Hello, I need help with a signup process.", role=RoleType.USER),
124+
ChatCompletionChatMessage(
125+
content="Hi Alice, I can help you with that. What seems to be the problem?",
126+
role=RoleType.ASSISTANT,
127+
),
128+
]
129+
130+
return (
131+
ChatCompletions,
132+
{"model": _DUMMY_MODEL, "messages": _DUMMY_MESSAGES},
133+
"chat/complete",
134+
{
135+
"model": _DUMMY_MODEL,
136+
"messages": [message.to_dict() for message in _DUMMY_MESSAGES],
137+
},
138+
ChatCompletionResponse(
139+
id="some-id",
140+
choices=[
141+
ChatCompletionResponseChoice(
142+
index=0,
143+
message=ChatCompletionChatMessage(
144+
content="Hello, I need help with a signup process.", role=RoleType.USER
145+
),
146+
finish_reason="dummy_reason",
147+
logprobs=None,
148+
)
149+
],
150+
usage=UsageInfo(
151+
prompt_tokens=10,
152+
completion_tokens=20,
153+
total_tokens=30,
154+
),
155+
),
156+
)
157+
158+
113159
def get_studio_completion(**kwargs):
114160
_DUMMY_MODEL = "dummy-completion-model"
115161
_DUMMY_PROMPT = "dummy-prompt"

tests/unittests/clients/studio/resources/test_studio_resources.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
get_studio_segmentation,
1818
get_studio_summarization,
1919
get_studio_summarize_by_segment,
20+
get_chat_completions,
2021
)
2122

2223
_BASE_URL = "https://test.api.ai21.com/studio/v1"
@@ -31,6 +32,7 @@ class TestStudioResources:
3132
ids=[
3233
"studio_answer",
3334
"studio_chat",
35+
"chat_completions",
3436
"studio_completion",
3537
"studio_completion_with_extra_args",
3638
"studio_embed",
@@ -45,6 +47,7 @@ class TestStudioResources:
4547
argvalues=[
4648
(get_studio_answer()),
4749
(get_studio_chat()),
50+
(get_chat_completions()),
4851
(get_studio_completion()),
4952
(get_studio_completion(temperature=0.5, max_tokens=50)),
5053
(get_studio_embed()),

0 commit comments

Comments
 (0)