weco 0.0.1__py3-none-any.whl → 0.1.1__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/__init__.py CHANGED
@@ -0,0 +1,8 @@
1
+ from .client import WecoAI
2
+ from .functional import build, query
3
+
4
+ __all__ = [
5
+ "WecoAI",
6
+ "build",
7
+ "query",
8
+ ]
weco/client.py ADDED
@@ -0,0 +1,121 @@
1
+ import os
2
+ from typing import Any, Dict
3
+
4
+ import requests
5
+
6
+
7
+ class WecoAI:
8
+ def __init__(self, api_key: str = None) -> None:
9
+ """Initializes the WecoAI client with the provided API key and base URL.
10
+
11
+ Parameters
12
+ ----------
13
+ api_key : str
14
+ The API key used for authentication. If not provided, the client will attempt to read it from the environment variable - WECO_API_KEY.
15
+ base_url : str
16
+ The base URL of the WecoAI API.
17
+
18
+ Raises
19
+ ------
20
+ ValueError
21
+ If the API key is not provided to the client, is not set as an environment variable or is not a string.
22
+ """
23
+ # Manage the API key
24
+ if api_key is None or not isinstance(api_key, str):
25
+ try:
26
+ api_key = os.environ["WECO_API_KEY"]
27
+ except KeyError:
28
+ raise ValueError(
29
+ "WECO_API_KEY must be passed to client or set as an environment variable"
30
+ )
31
+ self.api_key = api_key
32
+
33
+ # base URL
34
+ self.base_url = "https://function-builder.vercel.app"
35
+
36
+ def _headers(self) -> Dict[str, str]:
37
+ """Constructs the headers for the API requests.
38
+
39
+ Returns
40
+ -------
41
+ dict
42
+ A dictionary containing the headers.
43
+ """
44
+ return {
45
+ "Authorization": f"Bearer {self.api_key}",
46
+ "Content-Type": "application/json",
47
+ }
48
+
49
+ def _post(self, endpoint: str, data: Dict[str, Any]) -> Dict[str, Any]:
50
+ """Makes a POST request to the specified endpoint with the provided data.
51
+
52
+ Parameters
53
+ ----------
54
+ endpoint : str
55
+ The API endpoint to which the request will be made.
56
+ data : dict
57
+ The data to be sent in the request body.
58
+
59
+ Returns
60
+ -------
61
+ dict
62
+ The response from the server as a dictionary.
63
+
64
+ Raises
65
+ ------
66
+ requests.HTTPError
67
+ If the request fails.
68
+ """
69
+ url = f"{self.base_url}/{endpoint}"
70
+ response = requests.post(url, json=data, headers=self._headers())
71
+ response.raise_for_status()
72
+ return response.json()
73
+
74
+ def build(self, task_description: str) -> tuple[str, str]:
75
+ """Builds a specialized function given a task description.
76
+
77
+ Parameters
78
+ ----------
79
+ task_description : str
80
+ A description of the task for which the function is being built.
81
+
82
+ Returns
83
+ -------
84
+ tuple[str, str]
85
+ A tuple containing the name and description of the function.
86
+ """
87
+ endpoint = "build"
88
+ data = {"request": task_description}
89
+ response = self._post(endpoint, data)
90
+ return response["name"], response["description"]
91
+
92
+ def query(self, fn_name: str, fn_input: str) -> Dict[str, Any]:
93
+ """Queries a function with the given function ID and input.
94
+
95
+ Parameters
96
+ ----------
97
+ fn_name : str
98
+ The name of the function to query.
99
+ fn_input : str
100
+ The input to the function.
101
+
102
+ Returns
103
+ -------
104
+ dict
105
+ A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
106
+ and the latency in milliseconds.
107
+ """
108
+
109
+ endpoint = "query"
110
+ data = {
111
+ "name": fn_name,
112
+ "user_message": fn_input,
113
+ }
114
+ response = self._post(endpoint, data)
115
+ result = {
116
+ "output": response["response"],
117
+ "in_tokens": response["num_input_tokens"],
118
+ "out_tokens": response["num_output_tokens"],
119
+ "latency_ms": response["latency_ms"],
120
+ }
121
+ return result
weco/functional.py ADDED
@@ -0,0 +1,46 @@
1
+ from typing import Any, Dict, Optional
2
+
3
+ from .client import WecoAI
4
+
5
+
6
+ def build(task_description: str, api_key: str = None) -> tuple[str, str]:
7
+ """Builds a specialized function given a task description.
8
+
9
+ Parameters
10
+ ----------
11
+ task_description : str
12
+ A description of the task for which the function is being built.
13
+ api_key : str
14
+ The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
15
+
16
+ Returns
17
+ -------
18
+ tuple[str, str]
19
+ A tuple containing the name and description of the function.
20
+ """
21
+ client = WecoAI(api_key=api_key)
22
+ response = client.build(task_description=task_description)
23
+ return response
24
+
25
+
26
+ def query(fn_name: str, fn_input: str, api_key: Optional[str] = None) -> Dict[str, Any]:
27
+ """Queries a function with the given function ID and input.
28
+
29
+ Parameters
30
+ ----------
31
+ fn_name : str
32
+ The name of the function to query.
33
+ fn_input : str
34
+ The input to the function.
35
+ api_key : str
36
+ The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - WECO_API_KEY.
37
+
38
+ Returns
39
+ -------
40
+ dict
41
+ A dictionary containing the output of the function, the number of input tokens, the number of output tokens,
42
+ and the latency in milliseconds.
43
+ """
44
+ client = WecoAI(api_key=api_key)
45
+ response = client.query(fn_name=fn_name, fn_input=fn_input)
46
+ return response
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Weco AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.1
2
+ Name: weco
3
+ Version: 0.1.1
4
+ Summary: A client facing API for interacting with the WeCo AI function builder service.
5
+ Home-page: https://github.com/WecoAI/weco
6
+ Author: ['WeCo AI Team']
7
+ Author-email: dhruv@weco.ai
8
+ License: MIT
9
+ Keywords: artificial intelligence,machine learning,data science,function builder,LLM
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: requests
16
+
17
+ [![Typing SVG](https://readme-typing-svg.demolab.com?font=Georgia&size=32&duration=4000&pause=400&color=FD4578&vCenter=true&multiline=false&width=750&height=100&lines=WeCo:+Function+Builder+Client;)](https://git.io/typing-svg)
18
+
19
+ [![License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
20
+ ![Python](https://img.shields.io/badge/Python-3.10.14-blue)
21
+
22
+
23
+ # WeCo $f$(👷‍♂️)
24
+
25
+ A client facing API for interacting with the [WeCo AI](https://www.weco.ai/) function builder [service](https://weco-app.vercel.app/function)!
26
+
27
+
28
+ Use this API to build *complex* systems *fast*. We lower the barrier of entry to software engineer, data science and machine learning by providing an interface to prototype difficult solutions quickly in just a few lines of code.
29
+
30
+ ## Installation
31
+
32
+ Install the `weco` package simply by calling this in your terminal of choice:
33
+ ```bash
34
+ pip install weco
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - 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/).
40
+ - The **query** function allows you to test and use the newly created function in your own code.
41
+
42
+ We provide both services in two ways:
43
+ - `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. An example is shown [here](examples/example_client.py).
44
+ - `weco.query` and `weco.build` to be used when you only require sparse usage. An example is provided [here](examples/example_functional.py).
45
+
46
+ ## Usage
47
+
48
+ When using the WeCo API, you will need to set the API key:
49
+ You can find/setup your API key [here](https://weco-app.vercel.app/account) by navigating to the API key tab. Once you have your API key, you may pass it to the `weco` client using the `api_key` argument input or set it as an environment variable such as:
50
+ ```
51
+ export WECO_API_KEY=<YOUR_WECO_API_KEY>
52
+ ```
53
+
54
+ ## Example
55
+
56
+ We create a function on the [web console](https://weco-app.vercel.app/function) for the following task:
57
+ > "I want to evaluate the feasibility of a machine learning task. Give me a json object with three keys - 'feasibility', 'justification', and 'suggestions'."
58
+
59
+ Now, you're ready to query this function anywhere in your code!
60
+
61
+ ```python
62
+ from weco import query
63
+ response = query(
64
+ fn_name=fn_name,
65
+ fn_input="I want to train a model to predict house prices using the Boston Housing dataset hosted on Kaggle.",
66
+ )
67
+ ```
68
+
69
+ ## Enjoy $f$(👷‍♂️)!
@@ -0,0 +1,8 @@
1
+ weco/__init__.py,sha256=Xl80uFblDNbhIxL3_BQgYc_SninCeOeF0shnzPCrxrw,119
2
+ weco/client.py,sha256=YOUgWJwLKlp9GR2u40pmnjaBtmDjLtdP_pUuvDAMCJQ,3744
3
+ weco/functional.py,sha256=AnQ0PaZKr2K9a7wxXfVPJTTJLgrn1niZDQctdkj5vFA,1501
4
+ weco-0.1.1.dist-info/LICENSE,sha256=NvpxfBuSajszAczWBGKxhHe4gsvil1H63zmu8xXZdL0,1064
5
+ weco-0.1.1.dist-info/METADATA,sha256=ieRckEKjQ-shxHf5VPcNCHENd6CUpJz3i43-EeLSnMw,3214
6
+ weco-0.1.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ weco-0.1.1.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
8
+ weco-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: weco
3
- Version: 0.0.1
4
- Summary: Python package for using Weco's service
5
- Home-page: https://github.com/wecoai/weco-python
6
- Author: Yuxiang Wu
7
- Author-email: Yuxiang Wu <yuxiang@weco.ai>
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.8
12
- Description-Content-Type: text/markdown
13
-
14
- # Weco Package
15
-
16
- This is a Python package for using Weco AI service.
17
-
18
- ## Installation
19
-
20
- ```bash
21
- pip install wec o
22
-
@@ -1,5 +0,0 @@
1
- weco/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- weco-0.0.1.dist-info/METADATA,sha256=TQDFU0KqOJr1rmCdj_OFjoTpwaii38ELCZWQH1X5BPw,534
3
- weco-0.0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
4
- weco-0.0.1.dist-info/top_level.txt,sha256=F0N7v6e2zBSlsorFv-arAq2yDxQbzX3KVO8GxYhPUeE,5
5
- weco-0.0.1.dist-info/RECORD,,