weco 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
weco/client.py CHANGED
@@ -31,7 +31,7 @@ class WecoAI:
31
31
  ----------
32
32
  api_key : str
33
33
  The API key used for authentication.
34
-
34
+
35
35
  timeout : float
36
36
  The timeout for the HTTP requests in seconds. Default is 120.0.
37
37
 
@@ -39,7 +39,7 @@ class WecoAI:
39
39
  Whether to use HTTP/2 protocol for the HTTP requests. Default is True.
40
40
  """
41
41
 
42
- def __init__(self, api_key: str = None, timeout: float = 120.0, http2: bool = True) -> None:
42
+ def __init__(self, api_key: Union[str, None] = None, timeout: float = 120.0, http2: bool = True) -> None:
43
43
  """Initializes the WecoAI client with the provided API key and base URL.
44
44
 
45
45
  Parameters
@@ -68,6 +68,7 @@ class WecoAI:
68
68
  self.http2 = http2
69
69
  self.timeout = timeout
70
70
  self.base_url = "https://function.api.weco.ai"
71
+
71
72
  # Setup clients
72
73
  self.client = httpx.Client(http2=http2, timeout=timeout)
73
74
  self.async_client = httpx.AsyncClient(http2=http2, timeout=timeout)
@@ -153,24 +154,29 @@ class WecoAI:
153
154
  for _warning in response.get("warnings", []):
154
155
  warnings.warn(_warning)
155
156
 
156
- return {
157
+ returned_response = {
157
158
  "output": response["response"],
158
159
  "in_tokens": response["num_input_tokens"],
159
160
  "out_tokens": response["num_output_tokens"],
160
161
  "latency_ms": response["latency_ms"],
161
162
  }
163
+ if "reasoning_steps" in response:
164
+ returned_response["reasoning_steps"] = response["reasoning_steps"]
165
+ return returned_response
162
166
 
163
- def _build(self, task_description: str, multimodal: bool, is_async: bool) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
167
+ def _build(
168
+ self, task_description: str, multimodal: bool, is_async: bool
169
+ ) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
164
170
  """Internal method to handle both synchronous and asynchronous build requests.
165
171
 
166
172
  Parameters
167
173
  ----------
168
174
  task_description : str
169
175
  A description of the task for which the function is being built.
170
-
176
+
171
177
  multimodal : bool
172
178
  Whether the function is multimodal or not.
173
-
179
+
174
180
  is_async : bool
175
181
  Whether to perform an asynchronous request.
176
182
 
@@ -212,7 +218,7 @@ class WecoAI:
212
218
  ----------
213
219
  task_description : str
214
220
  A description of the task for which the function is being built.
215
-
221
+
216
222
  multimodal : bool, optional
217
223
  Whether the function is multimodal or not (default is False).
218
224
 
@@ -230,7 +236,7 @@ class WecoAI:
230
236
  ----------
231
237
  task_description : str
232
238
  A description of the task for which the function is being built.
233
-
239
+
234
240
  multimodal : bool, optional
235
241
  Whether the function is multimodal or not (default is False).
236
242
 
@@ -385,7 +391,13 @@ class WecoAI:
385
391
  return image_info
386
392
 
387
393
  def _query(
388
- self, is_async: bool, fn_name: str, version_number: Optional[int], text_input: Optional[str], images_input: Optional[List[str]]
394
+ self,
395
+ is_async: bool,
396
+ fn_name: str,
397
+ version_number: Optional[int],
398
+ text_input: Optional[str],
399
+ images_input: Optional[List[str]],
400
+ return_reasoning: Optional[bool],
389
401
  ) -> Union[Dict[str, Any], Coroutine[Any, Any, Dict[str, Any]]]:
390
402
  """Internal method to handle both synchronous and asynchronous query requests.
391
403
 
@@ -401,6 +413,8 @@ class WecoAI:
401
413
  The text input to the function.
402
414
  images_input : List[str], optional
403
415
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
416
+ return_reasoning : bool, optional
417
+ Whether to return reasoning for the output.
404
418
 
405
419
  Returns
406
420
  -------
@@ -427,7 +441,13 @@ class WecoAI:
427
441
 
428
442
  # Make the request
429
443
  endpoint = "query"
430
- data = {"name": fn_name, "text": text_input, "images": image_urls, "version_number": version_number}
444
+ data = {
445
+ "name": fn_name,
446
+ "text": text_input,
447
+ "images": image_urls,
448
+ "version_number": version_number,
449
+ "return_reasoning": return_reasoning,
450
+ }
431
451
  request = self._make_request(endpoint=endpoint, data=data, is_async=is_async)
432
452
 
433
453
  if is_async:
@@ -442,7 +462,12 @@ class WecoAI:
442
462
  return self._process_query_response(response=response)
443
463
 
444
464
  async def aquery(
445
- self, fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = []
465
+ self,
466
+ fn_name: str,
467
+ version_number: Optional[int] = -1,
468
+ text_input: Optional[str] = "",
469
+ images_input: Optional[List[str]] = [],
470
+ return_reasoning: Optional[bool] = False,
446
471
  ) -> Dict[str, Any]:
447
472
  """Asynchronously queries a function with the given function ID and input.
448
473
 
@@ -456,6 +481,8 @@ class WecoAI:
456
481
  The text input to the function.
457
482
  images_input : List[str], optional
458
483
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
484
+ return_reasoning : bool, optional
485
+ Whether to return reasoning for the output. Default is False.
459
486
 
460
487
  Returns
461
488
  -------
@@ -463,9 +490,23 @@ class WecoAI:
463
490
  A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
464
491
  and the latency in milliseconds.
465
492
  """
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]:
493
+ return await self._query(
494
+ fn_name=fn_name,
495
+ version_number=version_number,
496
+ text_input=text_input,
497
+ images_input=images_input,
498
+ return_reasoning=return_reasoning,
499
+ is_async=True,
500
+ )
501
+
502
+ def query(
503
+ self,
504
+ fn_name: str,
505
+ version_number: Optional[int] = -1,
506
+ text_input: Optional[str] = "",
507
+ images_input: Optional[List[str]] = [],
508
+ return_reasoning: Optional[bool] = False,
509
+ ) -> Dict[str, Any]:
469
510
  """Synchronously queries a function with the given function ID and input.
470
511
 
471
512
  Parameters
@@ -478,6 +519,8 @@ class WecoAI:
478
519
  The text input to the function.
479
520
  images_input : List[str], optional
480
521
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
522
+ return_reasoning : bool, optional
523
+ Whether to return reasoning for the output. Default is False.
481
524
 
482
525
  Returns
483
526
  -------
@@ -485,23 +528,36 @@ class WecoAI:
485
528
  A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
486
529
  and the latency in milliseconds.
487
530
  """
488
- return self._query(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=False)
489
-
490
- def batch_query(self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1) -> List[Dict[str, Any]]:
531
+ return self._query(
532
+ fn_name=fn_name,
533
+ version_number=version_number,
534
+ text_input=text_input,
535
+ images_input=images_input,
536
+ return_reasoning=return_reasoning,
537
+ is_async=False,
538
+ )
539
+
540
+ def batch_query(
541
+ self,
542
+ fn_name: str,
543
+ batch_inputs: List[Dict[str, Any]],
544
+ version_number: Optional[int] = -1,
545
+ return_reasoning: Optional[bool] = False,
546
+ ) -> List[Dict[str, Any]]:
491
547
  """Batch queries a function version with a list of inputs.
492
548
 
493
549
  Parameters
494
550
  ----------
495
551
  fn_name : str
496
552
  The name of the function or a list of function names to query.
497
-
498
553
  batch_inputs : List[Dict[str, Any]]
499
554
  A list of inputs for the functions to query. The input must be a dictionary containing the data to be processed. e.g.,
500
555
  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", ...]}
501
556
  and for a combination of text and image inputs, the dictionary should be {"text_input": "input text", "images_input": ["url1", "url2", ...]}.
502
-
503
557
  version_number : int, optional
504
558
  The version number of the function to query. If not provided, the latest version will be used. Pass -1 to use the latest version.
559
+ return_reasoning : bool, optional
560
+ Whether to return reasoning for the output. Default is False.
505
561
 
506
562
  Returns
507
563
  -------
@@ -509,11 +565,16 @@ class WecoAI:
509
565
  A list of dictionaries, each containing the output of a function query,
510
566
  in the same order as the input queries.
511
567
  """
568
+
512
569
  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
- ))
570
+ tasks = list(
571
+ map(
572
+ lambda fn_input: self.aquery(
573
+ fn_name=fn_name, version_number=version_number, return_reasoning=return_reasoning, **fn_input
574
+ ),
575
+ batch_inputs,
576
+ )
577
+ )
517
578
  return await asyncio.gather(*tasks)
518
579
 
519
580
  return asyncio.run(run_queries())
weco/functional.py CHANGED
@@ -48,7 +48,12 @@ async def abuild(task_description: str, multimodal: bool = False, api_key: str =
48
48
 
49
49
 
50
50
  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
+ return_reasoning: Optional[bool] = False,
56
+ api_key: Optional[str] = None,
52
57
  ) -> Dict[str, Any]:
53
58
  """Queries a function synchronously with the given function ID and input.
54
59
 
@@ -62,6 +67,8 @@ def query(
62
67
  The text input to the function.
63
68
  images_input : List[str], optional
64
69
  A list of image URLs or base64 encoded images to be used as input to the function.
70
+ return_reasoning : bool, optional
71
+ A flag to indicate if the reasoning should be returned. Default is False.
65
72
  api_key : str
66
73
  The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
67
74
 
@@ -72,12 +79,23 @@ def query(
72
79
  and the latency in milliseconds.
73
80
  """
74
81
  client = WecoAI(api_key=api_key)
75
- response = client.query(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input)
82
+ response = client.query(
83
+ fn_name=fn_name,
84
+ version_number=version_number,
85
+ text_input=text_input,
86
+ images_input=images_input,
87
+ return_reasoning=return_reasoning,
88
+ )
76
89
  return response
77
90
 
78
91
 
79
92
  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
93
+ fn_name: str,
94
+ version_number: Optional[int] = -1,
95
+ text_input: Optional[str] = "",
96
+ images_input: Optional[List[str]] = [],
97
+ return_reasoning: Optional[bool] = False,
98
+ api_key: Optional[str] = None,
81
99
  ) -> Dict[str, Any]:
82
100
  """Queries a function asynchronously with the given function ID and input.
83
101
 
@@ -91,6 +109,8 @@ async def aquery(
91
109
  The text input to the function.
92
110
  images_input : List[str], optional
93
111
  A list of image URLs to be used as input to the function.
112
+ return_reasoning : bool, optional
113
+ A flag to indicate if the reasoning should be returned. Default is False.
94
114
  api_key : str
95
115
  The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
96
116
 
@@ -101,12 +121,22 @@ async def aquery(
101
121
  and the latency in milliseconds.
102
122
  """
103
123
  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)
124
+ response = await client.aquery(
125
+ fn_name=fn_name,
126
+ version_number=version_number,
127
+ text_input=text_input,
128
+ images_input=images_input,
129
+ return_reasoning=return_reasoning,
130
+ )
105
131
  return response
106
132
 
107
133
 
108
134
  def batch_query(
109
- fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1, api_key: Optional[str] = None
135
+ fn_name: str,
136
+ batch_inputs: List[Dict[str, Any]],
137
+ version_number: Optional[int] = -1,
138
+ return_reasoning: Optional[bool] = False,
139
+ api_key: Optional[str] = None,
110
140
  ) -> List[Dict[str, Any]]:
111
141
  """Synchronously queries multiple functions using asynchronous calls internally.
112
142
 
@@ -119,15 +149,14 @@ def batch_query(
119
149
  The name of the function or a list of function names to query.
120
150
  Note that if a single function name is provided, it will be used for all queries.
121
151
  If a list of function names is provided, the length must match the number of queries.
122
-
123
152
  batch_inputs : List[str]
124
153
  A list of inputs for the functions to query. The input must be a dictionary containing the data to be processed. e.g.,
125
154
  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", ...]}
126
155
  and for a combination of text and image inputs, the dictionary should be {"text_input": "input text", "images_input": ["url1", "url2", ...]}.
127
-
128
156
  version_number : int, optional
129
157
  The version number of the function to query. If not provided, the latest version is used. Default is -1 for the same behavior.
130
-
158
+ return_reasoning : bool, optional
159
+ A flag to indicate if the reasoning should be returned. Default is False.
131
160
  api_key : str, optional
132
161
  The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
133
162
 
@@ -138,5 +167,7 @@ def batch_query(
138
167
  in the same order as the input queries.
139
168
  """
140
169
  client = WecoAI(api_key=api_key)
141
- responses = client.batch_query(fn_name=fn_name, version_number=version_number, batch_inputs=batch_inputs)
170
+ responses = client.batch_query(
171
+ fn_name=fn_name, version_number=version_number, batch_inputs=batch_inputs, return_reasoning=return_reasoning
172
+ )
142
173
  return responses
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: weco
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: A client facing API for interacting with the WeCo AI function builder service.
5
5
  Author-email: WeCo AI Team <dhruv@weco.ai>
6
6
  License: MIT
@@ -52,12 +52,16 @@ pip install weco
52
52
  ```
53
53
 
54
54
  ## Features
55
+ - Synchronous & Asynchronous client.
56
+ - Batch API
57
+ - Multimodality (Language & Vision)
58
+ - Interpretability (view the reasoning behind outputs)
59
+
60
+
61
+ ## What We Offer
55
62
 
56
63
  - The **build** function enables quick and easy prototyping of new functions via LLMs through just natural language. We encourage users to do this through our [web console](https://weco-app.vercel.app/function) for maximum control and ease of use, however, you can also do this through our API as shown in [here](examples/cookbook.ipynb).
57
64
  - The **query** function allows you to test and use the newly created function in your own code.
58
- - We offer asynchronous versions of the above clients.
59
- - We provide a **batch_query** functions that allows users to batch functions for various inputs as well as multiple inputs for the same function in a query. This is helpful to make a large number of queries more efficiently.
60
- - We also offer multimodality capabilities. You can now query our client with both **language** AND **vision** inputs!
61
65
 
62
66
  We provide both services in two ways:
63
67
  - `weco.WecoAI` client to be used when you want to maintain the same client service across a portion of code. This is better for dense service usage.
@@ -0,0 +1,10 @@
1
+ weco/__init__.py,sha256=qiKpnrm6t0n0bpAtXEKJO1Yz2xYXnJJRZBWt-cH7DdU,168
2
+ weco/client.py,sha256=mW0FRv6_ZEl1h12HfQ9Gfag84Nlzs6RFrXRNcW5vMBo,22782
3
+ weco/constants.py,sha256=eoAq-9qN2aZrqyIWdrb3V1zomV5kp80PfxxoPoQNMNI,167
4
+ weco/functional.py,sha256=v_YsR2jomckwDKRt-ZZtqC8-JmHJZ12tB6fJyCa6sYk,6964
5
+ weco/utils.py,sha256=UUSw6ocqWdlSmIXVcH66DAL4NuLU2rFOyviD8aTWsv0,4371
6
+ weco-0.1.9.dist-info/LICENSE,sha256=NvpxfBuSajszAczWBGKxhHe4gsvil1H63zmu8xXZdL0,1064
7
+ weco-0.1.9.dist-info/METADATA,sha256=70IQjezjRB-dTf3jg0Owr892snZOHL_RY0rpwpXcvxo,5716
8
+ weco-0.1.9.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
9
+ weco-0.1.9.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
10
+ weco-0.1.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (72.2.0)
2
+ Generator: setuptools (73.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,10 +0,0 @@
1
- weco/__init__.py,sha256=qiKpnrm6t0n0bpAtXEKJO1Yz2xYXnJJRZBWt-cH7DdU,168
2
- weco/client.py,sha256=RCKuLVsR_o4G1TOhB-btIENCllN3h3d6baKoxVxue2s,21365
3
- weco/constants.py,sha256=eoAq-9qN2aZrqyIWdrb3V1zomV5kp80PfxxoPoQNMNI,167
4
- weco/functional.py,sha256=gckeXFVouy4wLHj0uLwxQkRNUj0urldk1f5ZDZk4yhY,6209
5
- weco/utils.py,sha256=UUSw6ocqWdlSmIXVcH66DAL4NuLU2rFOyviD8aTWsv0,4371
6
- weco-0.1.7.dist-info/LICENSE,sha256=NvpxfBuSajszAczWBGKxhHe4gsvil1H63zmu8xXZdL0,1064
7
- weco-0.1.7.dist-info/METADATA,sha256=iPmC7l1aokdeYTACgT0Za8u07dyNxY8L1IJQMkqn7QE,5957
8
- weco-0.1.7.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
9
- weco-0.1.7.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
10
- weco-0.1.7.dist-info/RECORD,,
File without changes