Skip to content

Commit 3814e57

Browse files
authored
fix: Removed answer_length and mode from answer (#65)
* fix: Removed answer_length and mode from answer * test: Fixed test
1 parent fcd2746 commit 3814e57

File tree

10 files changed

+8
-53
lines changed

10 files changed

+8
-53
lines changed

ai21/clients/common/answer_base.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from abc import ABC
2-
from typing import Optional, Any, Dict
2+
from typing import Any, Dict
33

4-
from ai21.models import Mode, AnswerLength, AnswerResponse
4+
from ai21.models import AnswerResponse
55

66

77
class Answer(ABC):
@@ -11,17 +11,12 @@ def create(
1111
self,
1212
context: str,
1313
question: str,
14-
*,
15-
answer_length: Optional[AnswerLength] = None,
16-
mode: Optional[Mode] = None,
1714
**kwargs,
1815
) -> AnswerResponse:
1916
"""
2017
2118
:param context: A string containing the document context for which the question will be answered
2219
:param question: A string containing the question to be answered based on the provided context.
23-
:param answer_length: Approximate length of the answer in words.
24-
:param mode:
2520
:param kwargs:
2621
:return:
2722
"""
@@ -34,7 +29,5 @@ def _create_body(
3429
self,
3530
context: str,
3631
question: str,
37-
answer_length: Optional[AnswerLength],
38-
mode: Optional[str],
3932
) -> Dict[str, Any]:
40-
return {"context": context, "question": question, "answerLength": answer_length, "mode": mode}
33+
return {"context": context, "question": question}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
from typing import Optional
2-
31
from ai21.clients.common.answer_base import Answer
42
from ai21.clients.sagemaker.resources.sagemaker_resource import SageMakerResource
5-
from ai21.models import AnswerResponse, AnswerLength, Mode
3+
from ai21.models import AnswerResponse
64

75

86
class SageMakerAnswer(SageMakerResource, Answer):
97
def create(
108
self,
119
context: str,
1210
question: str,
13-
*,
14-
answer_length: Optional[AnswerLength] = None,
15-
mode: Optional[Mode] = None,
1611
**kwargs,
1712
) -> AnswerResponse:
18-
body = self._create_body(context=context, question=question, answer_length=answer_length, mode=mode)
13+
body = self._create_body(context=context, question=question)
1914
response = self._invoke(body)
2015

2116
return self._json_to_response(response)

ai21/clients/studio/resources/studio_answer.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
from typing import Optional
2-
31
from ai21.clients.common.answer_base import Answer
42
from ai21.clients.studio.resources.studio_resource import StudioResource
5-
from ai21.models import AnswerLength, Mode, AnswerResponse
3+
from ai21.models import AnswerResponse
64

75

86
class StudioAnswer(StudioResource, Answer):
97
def create(
108
self,
119
context: str,
1210
question: str,
13-
*,
14-
answer_length: Optional[AnswerLength] = None,
15-
mode: Optional[Mode] = None,
1611
**kwargs,
1712
) -> AnswerResponse:
1813
url = f"{self._client.get_base_url()}/{self._module_name}"
1914

20-
body = self._create_body(context=context, question=question, answer_length=answer_length, mode=mode)
15+
body = self._create_body(context=context, question=question)
2116

2217
response = self._post(url=url, body=body)
2318

ai21/clients/studio/resources/studio_library.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from ai21.ai21_http_client import AI21HTTPClient
44
from ai21.clients.studio.resources.studio_resource import StudioResource
5-
from ai21.models import Mode, AnswerLength, FileResponse, LibraryAnswerResponse, LibrarySearchResponse
5+
from ai21.models import FileResponse, LibraryAnswerResponse, LibrarySearchResponse
66

77

88
class StudioLibrary(StudioResource):
@@ -107,8 +107,6 @@ def create(
107107
path: Optional[str] = None,
108108
field_ids: Optional[List[str]] = None,
109109
labels: Optional[List[str]] = None,
110-
answer_length: Optional[AnswerLength] = None,
111-
mode: Optional[Mode] = None,
112110
**kwargs,
113111
) -> LibraryAnswerResponse:
114112
url = f"{self._client.get_base_url()}/{self._module_name}"
@@ -117,8 +115,6 @@ def create(
117115
"path": path,
118116
"fieldIds": field_ids,
119117
"labels": labels,
120-
"answerLength": answer_length,
121-
"mode": mode,
122118
}
123119
raw_response = self._post(url=url, body=body)
124120
return LibraryAnswerResponse.from_dict(raw_response)

ai21/models/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from ai21.models.answer_length import AnswerLength
21
from ai21.models.chat_message import ChatMessage
32
from ai21.models.document_type import DocumentType
43
from ai21.models.embed_type import EmbedType
54
from ai21.models.improvement_type import ImprovementType
6-
from ai21.models.mode import Mode
75
from ai21.models.paraphrase_style_type import ParaphraseStyleType
86
from ai21.models.penalty import Penalty
97
from ai21.models.responses.answer_response import AnswerResponse
@@ -32,8 +30,6 @@
3230

3331

3432
__all__ = [
35-
"AnswerLength",
36-
"Mode",
3733
"ChatMessage",
3834
"RoleType",
3935
"Penalty",

ai21/models/answer_length.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

ai21/models/mode.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/integration_tests/clients/studio/test_answer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
from ai21 import AI21Client
3-
from ai21.models import AnswerLength, Mode
43

54
_CONTEXT = (
65
"Holland is a geographical region[2] and former province on the western coast of"
@@ -27,8 +26,6 @@ def test_answer(question: str, is_answer_in_context: bool, expected_answer_type:
2726
response = client.answer.create(
2827
context=_CONTEXT,
2928
question=question,
30-
answer_length=AnswerLength.LONG,
31-
mode=Mode.FLEXIBLE,
3229
)
3330

3431
assert response.answer_in_context == is_answer_in_context

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def get_studio_answer():
6060
{"context": _DUMMY_CONTEXT, "question": _DUMMY_QUESTION},
6161
"answer",
6262
{
63-
"answerLength": None,
6463
"context": _DUMMY_CONTEXT,
65-
"mode": None,
6664
"question": _DUMMY_QUESTION,
6765
},
6866
AnswerResponse(id="some-id", answer_in_context=True, answer="42"),

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def test__create__when_pass_kwargs__should_not_pass_to_request(self, mock_ai21_s
9696
method="POST",
9797
url=_BASE_URL + "/answer",
9898
params={
99-
"answerLength": None,
10099
"context": _DUMMY_CONTEXT,
101-
"mode": None,
102100
"question": _DUMMY_QUESTION,
103101
},
104102
files=None,

0 commit comments

Comments
 (0)