weco 0.1.7__py3-none-any.whl → 0.1.8__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
@@ -153,24 +153,29 @@ class WecoAI:
153
153
  for _warning in response.get("warnings", []):
154
154
  warnings.warn(_warning)
155
155
 
156
- return {
156
+ returned_response = {
157
157
  "output": response["response"],
158
158
  "in_tokens": response["num_input_tokens"],
159
159
  "out_tokens": response["num_output_tokens"],
160
160
  "latency_ms": response["latency_ms"],
161
161
  }
162
+ if "reasoning_steps" in response:
163
+ returned_response["reasoning_steps"] = response["reasoning_steps"]
164
+ return returned_response
162
165
 
163
- def _build(self, task_description: str, multimodal: bool, is_async: bool) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
166
+ def _build(
167
+ self, task_description: str, multimodal: bool, is_async: bool
168
+ ) -> Union[Tuple[str, int, str], Coroutine[Any, Any, Tuple[str, int, str]]]:
164
169
  """Internal method to handle both synchronous and asynchronous build requests.
165
170
 
166
171
  Parameters
167
172
  ----------
168
173
  task_description : str
169
174
  A description of the task for which the function is being built.
170
-
175
+
171
176
  multimodal : bool
172
177
  Whether the function is multimodal or not.
173
-
178
+
174
179
  is_async : bool
175
180
  Whether to perform an asynchronous request.
176
181
 
@@ -212,7 +217,7 @@ class WecoAI:
212
217
  ----------
213
218
  task_description : str
214
219
  A description of the task for which the function is being built.
215
-
220
+
216
221
  multimodal : bool, optional
217
222
  Whether the function is multimodal or not (default is False).
218
223
 
@@ -230,7 +235,7 @@ class WecoAI:
230
235
  ----------
231
236
  task_description : str
232
237
  A description of the task for which the function is being built.
233
-
238
+
234
239
  multimodal : bool, optional
235
240
  Whether the function is multimodal or not (default is False).
236
241
 
@@ -385,7 +390,13 @@ class WecoAI:
385
390
  return image_info
386
391
 
387
392
  def _query(
388
- self, is_async: bool, fn_name: str, version_number: Optional[int], text_input: Optional[str], images_input: Optional[List[str]]
393
+ self,
394
+ is_async: bool,
395
+ fn_name: str,
396
+ version_number: Optional[int],
397
+ text_input: Optional[str],
398
+ images_input: Optional[List[str]],
399
+ return_reasoning: Optional[bool]
389
400
  ) -> Union[Dict[str, Any], Coroutine[Any, Any, Dict[str, Any]]]:
390
401
  """Internal method to handle both synchronous and asynchronous query requests.
391
402
 
@@ -401,6 +412,8 @@ class WecoAI:
401
412
  The text input to the function.
402
413
  images_input : List[str], optional
403
414
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
415
+ return_reasoning : bool, optional
416
+ Whether to return reasoning for the output.
404
417
 
405
418
  Returns
406
419
  -------
@@ -427,7 +440,7 @@ class WecoAI:
427
440
 
428
441
  # Make the request
429
442
  endpoint = "query"
430
- data = {"name": fn_name, "text": text_input, "images": image_urls, "version_number": version_number}
443
+ data = {"name": fn_name, "text": text_input, "images": image_urls, "version_number": version_number, "return_reasoning": return_reasoning}
431
444
  request = self._make_request(endpoint=endpoint, data=data, is_async=is_async)
432
445
 
433
446
  if is_async:
@@ -442,7 +455,12 @@ class WecoAI:
442
455
  return self._process_query_response(response=response)
443
456
 
444
457
  async def aquery(
445
- self, fn_name: str, version_number: Optional[int] = -1, text_input: Optional[str] = "", images_input: Optional[List[str]] = []
458
+ self,
459
+ fn_name: str,
460
+ version_number: Optional[int] = -1,
461
+ text_input: Optional[str] = "",
462
+ images_input: Optional[List[str]] = [],
463
+ return_reasoning: Optional[bool] = False
446
464
  ) -> Dict[str, Any]:
447
465
  """Asynchronously queries a function with the given function ID and input.
448
466
 
@@ -456,6 +474,8 @@ class WecoAI:
456
474
  The text input to the function.
457
475
  images_input : List[str], optional
458
476
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
477
+ return_reasoning : bool, optional
478
+ Whether to return reasoning for the output. Default is False.
459
479
 
460
480
  Returns
461
481
  -------
@@ -463,9 +483,18 @@ class WecoAI:
463
483
  A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
464
484
  and the latency in milliseconds.
465
485
  """
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]:
486
+ return await self._query(
487
+ fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, return_reasoning=return_reasoning, is_async=True
488
+ )
489
+
490
+ def query(
491
+ self,
492
+ fn_name: str,
493
+ version_number: Optional[int] = -1,
494
+ text_input: Optional[str] = "",
495
+ images_input: Optional[List[str]] = [],
496
+ return_reasoning: Optional[bool] = False
497
+ ) -> Dict[str, Any]:
469
498
  """Synchronously queries a function with the given function ID and input.
470
499
 
471
500
  Parameters
@@ -478,6 +507,8 @@ class WecoAI:
478
507
  The text input to the function.
479
508
  images_input : List[str], optional
480
509
  A list of image URLs or images encoded in base64 with their metadata to be sent as input to the function.
510
+ return_reasoning : bool, optional
511
+ Whether to return reasoning for the output. Default is False.
481
512
 
482
513
  Returns
483
514
  -------
@@ -485,23 +516,27 @@ class WecoAI:
485
516
  A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
486
517
  and the latency in milliseconds.
487
518
  """
488
- return self._query(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, is_async=False)
519
+ return self._query(
520
+ fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, return_reasoning=return_reasoning, is_async=False
521
+ )
489
522
 
490
- def batch_query(self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1) -> List[Dict[str, Any]]:
523
+ def batch_query(
524
+ self, fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1, return_reasoning: Optional[bool] = False
525
+ ) -> List[Dict[str, Any]]:
491
526
  """Batch queries a function version with a list of inputs.
492
527
 
493
528
  Parameters
494
529
  ----------
495
530
  fn_name : str
496
531
  The name of the function or a list of function names to query.
497
-
498
532
  batch_inputs : List[Dict[str, Any]]
499
533
  A list of inputs for the functions to query. The input must be a dictionary containing the data to be processed. e.g.,
500
534
  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
535
  and for a combination of text and image inputs, the dictionary should be {"text_input": "input text", "images_input": ["url1", "url2", ...]}.
502
-
503
536
  version_number : int, optional
504
537
  The version number of the function to query. If not provided, the latest version will be used. Pass -1 to use the latest version.
538
+ return_reasoning : bool, optional
539
+ Whether to return reasoning for the output. Default is False.
505
540
 
506
541
  Returns
507
542
  -------
@@ -509,11 +544,11 @@ class WecoAI:
509
544
  A list of dictionaries, each containing the output of a function query,
510
545
  in the same order as the input queries.
511
546
  """
547
+
512
548
  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
- ))
549
+ tasks = list(
550
+ map(lambda fn_input: self.aquery(fn_name=fn_name, version_number=version_number, return_reasoning=return_reasoning, **fn_input), batch_inputs)
551
+ )
517
552
  return await asyncio.gather(*tasks)
518
553
 
519
554
  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,17 @@ 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(fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, return_reasoning=return_reasoning)
76
83
  return response
77
84
 
78
85
 
79
86
  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
87
+ fn_name: str,
88
+ version_number: Optional[int] = -1,
89
+ text_input: Optional[str] = "",
90
+ images_input: Optional[List[str]] = [],
91
+ return_reasoning: Optional[bool] = False,
92
+ api_key: Optional[str] = None,
81
93
  ) -> Dict[str, Any]:
82
94
  """Queries a function asynchronously with the given function ID and input.
83
95
 
@@ -91,6 +103,8 @@ async def aquery(
91
103
  The text input to the function.
92
104
  images_input : List[str], optional
93
105
  A list of image URLs to be used as input to the function.
106
+ return_reasoning : bool, optional
107
+ A flag to indicate if the reasoning should be returned. Default is False.
94
108
  api_key : str
95
109
  The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
96
110
 
@@ -101,12 +115,14 @@ async def aquery(
101
115
  and the latency in milliseconds.
102
116
  """
103
117
  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)
118
+ response = await client.aquery(
119
+ fn_name=fn_name, version_number=version_number, text_input=text_input, images_input=images_input, return_reasoning=return_reasoning
120
+ )
105
121
  return response
106
122
 
107
123
 
108
124
  def batch_query(
109
- fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1, api_key: Optional[str] = None
125
+ fn_name: str, batch_inputs: List[Dict[str, Any]], version_number: Optional[int] = -1, return_reasoning: Optional[bool] = False, api_key: Optional[str] = None
110
126
  ) -> List[Dict[str, Any]]:
111
127
  """Synchronously queries multiple functions using asynchronous calls internally.
112
128
 
@@ -119,15 +135,14 @@ def batch_query(
119
135
  The name of the function or a list of function names to query.
120
136
  Note that if a single function name is provided, it will be used for all queries.
121
137
  If a list of function names is provided, the length must match the number of queries.
122
-
123
138
  batch_inputs : List[str]
124
139
  A list of inputs for the functions to query. The input must be a dictionary containing the data to be processed. e.g.,
125
140
  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
141
  and for a combination of text and image inputs, the dictionary should be {"text_input": "input text", "images_input": ["url1", "url2", ...]}.
127
-
128
142
  version_number : int, optional
129
143
  The version number of the function to query. If not provided, the latest version is used. Default is -1 for the same behavior.
130
-
144
+ return_reasoning : bool, optional
145
+ A flag to indicate if the reasoning should be returned. Default is False.
131
146
  api_key : str, optional
132
147
  The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
133
148
 
@@ -138,5 +153,5 @@ def batch_query(
138
153
  in the same order as the input queries.
139
154
  """
140
155
  client = WecoAI(api_key=api_key)
141
- responses = client.batch_query(fn_name=fn_name, version_number=version_number, batch_inputs=batch_inputs)
156
+ responses = client.batch_query(fn_name=fn_name, version_number=version_number, batch_inputs=batch_inputs, return_reasoning=return_reasoning)
142
157
  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.8
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=l0H62JxDsfiF4vW2v5GEUhf6IEWX3m9_oFy7A-Wf_wI,22447
3
+ weco/constants.py,sha256=eoAq-9qN2aZrqyIWdrb3V1zomV5kp80PfxxoPoQNMNI,167
4
+ weco/functional.py,sha256=hFUFCWIlWDadaPAFpjl0cLF0ExysTYuld8Uwza_hyqM,6853
5
+ weco/utils.py,sha256=UUSw6ocqWdlSmIXVcH66DAL4NuLU2rFOyviD8aTWsv0,4371
6
+ weco-0.1.8.dist-info/LICENSE,sha256=NvpxfBuSajszAczWBGKxhHe4gsvil1H63zmu8xXZdL0,1064
7
+ weco-0.1.8.dist-info/METADATA,sha256=olHH_wAex7_djdDwleCGCoQnwXTAjTwOSLHo0SWG1JU,5716
8
+ weco-0.1.8.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
9
+ weco-0.1.8.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
10
+ weco-0.1.8.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