Skip to content

Commit df54ea1

Browse files
committed
[PROJ] Format code with Black
1 parent c16c56d commit df54ea1

File tree

5 files changed

+71
-32
lines changed

5 files changed

+71
-32
lines changed

tests/test_asynchronous.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def assert_query_response(query_response):
2626
async def text_evaluator():
2727
fn_name, version_number, fn_desc = await abuild(
2828
task_description="Evaluate the sentiment of the given text. Provide a json object with 'sentiment' and 'explanation' keys.",
29-
multimodal=False
29+
multimodal=False,
3030
)
3131
return fn_name, version_number, fn_desc
3232

@@ -44,7 +44,7 @@ async def test_text_aquery(text_evaluator):
4444
async def image_evaluator():
4545
fn_name, version_number, fn_desc = await abuild(
4646
task_description="Describe the contents of the given images. Provide a json object with 'description' and 'objects' keys.",
47-
multimodal=True
47+
multimodal=True,
4848
)
4949
return fn_name, version_number, fn_desc
5050

@@ -69,7 +69,7 @@ async def test_image_aquery(image_evaluator):
6969
async def text_and_image_evaluator():
7070
fn_name, version_number, fn_desc = await abuild(
7171
task_description="Evaluate, solve and arrive at a numerical answer for the image provided. Provide a json object with 'answer' and 'explanation' keys.",
72-
multimodal=True
72+
multimodal=True,
7373
)
7474
return fn_name, version_number, fn_desc
7575

tests/test_batching.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def ml_task_evaluator():
1010
fn_name, version_number, _ = build(
1111
task_description="I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'.",
12-
multimodal=False
12+
multimodal=False,
1313
)
1414
return fn_name, version_number
1515

@@ -18,23 +18,29 @@ def ml_task_evaluator():
1818
def ml_task_inputs():
1919
return [
2020
{"text_input": "I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle."},
21-
{"text_input": "I want to train a model to classify digits using the MNIST dataset hosted on Kaggle using a Google Colab notebook."},
21+
{
22+
"text_input": "I want to train a model to classify digits using the MNIST dataset hosted on Kaggle using a Google Colab notebook."
23+
},
2224
]
2325

2426

2527
@pytest.fixture
2628
def image_evaluator():
2729
fn_name, version_number, _ = build(
2830
task_description="Describe the contents of the given images. Provide a json object with 'description' and 'objects' keys.",
29-
multimodal=True
31+
multimodal=True,
3032
)
3133
return fn_name, version_number
3234

3335

3436
@pytest.fixture
3537
def image_inputs():
3638
return [
37-
{"images_input": ["https://www.integratedtreatmentservices.co.uk/wp-content/uploads/2013/12/Objects-of-Reference.jpg"]},
39+
{
40+
"images_input": [
41+
"https://www.integratedtreatmentservices.co.uk/wp-content/uploads/2013/12/Objects-of-Reference.jpg"
42+
]
43+
},
3844
{"images_input": ["https://t4.ftcdn.net/jpg/05/70/90/23/360_F_570902339_kNj1reH40GFXakTy98EmfiZHci2xvUCS.jpg"]},
3945
]
4046

@@ -72,4 +78,4 @@ def test_batch_query_image(image_evaluator, image_inputs):
7278
assert isinstance(query_response["latency_ms"], float)
7379

7480
output = query_response["output"]
75-
assert set(output.keys()) == {"description", "objects"}
81+
assert set(output.keys()) == {"description", "objects"}

tests/test_synchronous.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def assert_query_response(query_response):
2525
def text_evaluator():
2626
fn_name, version_number, fn_desc = build(
2727
task_description="Evaluate the sentiment of the given text. Provide a json object with 'sentiment' and 'explanation' keys.",
28-
multimodal=False
28+
multimodal=False,
2929
)
3030
return fn_name, version_number, fn_desc
3131

@@ -42,7 +42,7 @@ def test_text_query(text_evaluator):
4242
def image_evaluator():
4343
fn_name, version_number, fn_desc = build(
4444
task_description="Describe the contents of the given images. Provide a json object with 'description' and 'objects' keys.",
45-
multimodal=True
45+
multimodal=True,
4646
)
4747
return fn_name, version_number, fn_desc
4848

@@ -66,7 +66,7 @@ def test_image_query(image_evaluator):
6666
def text_and_image_evaluator():
6767
fn_name, version_number, fn_desc = build(
6868
task_description="Evaluate, solve and arrive at a numerical answer for the image provided. Perform any additional things if instructed. Provide a json object with 'answer' and 'explanation' keys.",
69-
multimodal=True
69+
multimodal=True,
7070
)
7171
return fn_name, version_number, fn_desc
7272

weco/client.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class WecoAI:
3131
----------
3232
api_key : str
3333
The API key used for authentication.
34-
34+
3535
timeout : float
3636
The timeout for the HTTP requests in seconds. Default is 120.0.
3737
@@ -160,17 +160,19 @@ def _process_query_response(self, response: Dict[str, Any]) -> Dict[str, Any]:
160160
"latency_ms": response["latency_ms"],
161161
}
162162

163-
def _build(self, task_description: str, multimodal: bool, is_async: bool) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
163+
def _build(
164+
self, task_description: str, multimodal: bool, is_async: bool
165+
) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
164166
"""Internal method to handle both synchronous and asynchronous build requests.
165167
166168
Parameters
167169
----------
168170
task_description : str
169171
A description of the task for which the function is being built.
170-
172+
171173
multimodal : bool
172174
Whether the function is multimodal or not.
173-
175+
174176
is_async : bool
175177
Whether to perform an asynchronous request.
176178
@@ -212,7 +214,7 @@ async def abuild(self, task_description: str, multimodal: bool = False) -> Tuple
212214
----------
213215
task_description : str
214216
A description of the task for which the function is being built.
215-
217+
216218
multimodal : bool, optional
217219
Whether the function is multimodal or not (default is False).
218220
@@ -230,7 +232,7 @@ def build(self, task_description: str, multimodal: bool = False) -> Tuple[str, i
230232
----------
231233
task_description : str
232234
A description of the task for which the function is being built.
233-
235+
234236
multimodal : bool, optional
235237
Whether the function is multimodal or not (default is False).
236238
@@ -385,7 +387,12 @@ def _validate_query(self, text_input: str, images_input: List[str]) -> List[Dict
385387
return image_info
386388

387389
def _query(
388-
self, is_async: bool, fn_name: str, version_number: Optional[int], text_input: Optional[str], images_input: Optional[List[str]]
390+
self,
391+
is_async: bool,
392+
fn_name: str,
393+
version_number: Optional[int],
394+
text_input: Optional[str],
395+
images_input: Optional[List[str]],
389396
) -> Union[Dict[str, Any], Coroutine[Any, Any, Dict[str, Any]]]:
390397
"""Internal method to handle both synchronous and asynchronous query requests.
391398
@@ -442,7 +449,11 @@ async def _async_query():
442449
return self._process_query_response(response=response)
443450

444451
async def aquery(
445-
self, fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = []
452+
self,
453+
fn_name: str,
454+
version_number: Optional[int] = -1,
455+
text_input: Optional[str] = "",
456+
images_input: Optional[List[str]] = [],
446457
) -> Dict[str, Any]:
447458
"""Asynchronously queries a function with the given function ID and input.
448459
@@ -463,9 +474,17 @@ async def aquery(
463474
A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
464475
and the latency in milliseconds.
465476
"""
466-
return await self._query(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=True)
467-
468-
def query(self, fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = []) -> Dict[str, Any]:
477+
return await self._query(
478+
fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=True
479+
)
480+
481+
def query(
482+
self,
483+
fn_name: str,
484+
version_number: Optional[int] = -1,
485+
text_input: Optional[str] = "",
486+
images_input: Optional[List[str]] = [],
487+
) -> Dict[str, Any]:
469488
"""Synchronously queries a function with the given function ID and input.
470489
471490
Parameters
@@ -485,9 +504,13 @@ def query(self, fn_name: str, version_number: Optional[int] = -1, text_input: Op
485504
A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
486505
and the latency in milliseconds.
487506
"""
488-
return self._query(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=False)
507+
return self._query(
508+
fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=False
509+
)
489510

490-
def batch_query(self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1) -> List[Dict[str, Any]]:
511+
def batch_query(
512+
self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1
513+
) -> List[Dict[str, Any]]:
491514
"""Batch queries a function version with a list of inputs.
492515
493516
Parameters
@@ -499,7 +522,7 @@ def batch_query(self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_
499522
A list of inputs for the functions to query. The input must be a dictionary containing the data to be processed. e.g.,
500523
when providing for a text input, the dictionary should be {"text_input": "input text"}, for an image input, the dictionary should be {"images_input": ["url1", "url2", ...]}
501524
and for a combination of text and image inputs, the dictionary should be {"text_input": "input text", "images_input": ["url1", "url2", ...]}.
502-
525+
503526
version_number : int, optional
504527
The version number of the function to query. If not provided, the latest version will be used. Pass -1 to use the latest version.
505528
@@ -509,11 +532,11 @@ def batch_query(self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_
509532
A list of dictionaries, each containing the output of a function query,
510533
in the same order as the input queries.
511534
"""
535+
512536
async def run_queries():
513-
tasks = list(map(
514-
lambda fn_input: self.aquery(fn_name=fn_name, version_number=version_number, **fn_input),
515-
batch_inputs
516-
))
537+
tasks = list(
538+
map(lambda fn_input: self.aquery(fn_name=fn_name, version_number=version_number, **fn_input), batch_inputs)
539+
)
517540
return await asyncio.gather(*tasks)
518541

519542
return asyncio.run(run_queries())

weco/functional.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ async def abuild(task_description: str, multimodal: bool = False, api_key: str =
4848

4949

5050
def query(
51-
fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = [], api_key: Optional[str] = None
51+
fn_name: str,
52+
version_number: Optional[int] = -1,
53+
text_input: Optional[str] = "",
54+
images_input: Optional[List[str]] = [],
55+
api_key: Optional[str] = None,
5256
) -> Dict[str, Any]:
5357
"""Queries a function synchronously with the given function ID and input.
5458
@@ -77,7 +81,11 @@ def query(
7781

7882

7983
async def aquery(
80-
fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = [], api_key: Optional[str] = None
84+
fn_name: str,
85+
version_number: Optional[int] = -1,
86+
text_input: Optional[str] = "",
87+
images_input: Optional[List[str]] = [],
88+
api_key: Optional[str] = None,
8189
) -> Dict[str, Any]:
8290
"""Queries a function asynchronously with the given function ID and input.
8391
@@ -101,7 +109,9 @@ async def aquery(
101109
and the latency in milliseconds.
102110
"""
103111
client = WecoAI(api_key=api_key)
104-
response = await client.aquery(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input)
112+
response = await client.aquery(
113+
fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input
114+
)
105115
return response
106116

107117

0 commit comments

Comments
 (0)