weco 0.1.0__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 +8 -0
- weco/client.py +121 -0
- weco/functional.py +46 -0
- {weco-0.1.0.dist-info → weco-0.1.1.dist-info}/METADATA +1 -1
- weco-0.1.1.dist-info/RECORD +8 -0
- weco-0.1.1.dist-info/top_level.txt +1 -0
- weco-0.1.0.dist-info/RECORD +0 -5
- weco-0.1.0.dist-info/top_level.txt +0 -1
- {weco-0.1.0.dist-info → weco-0.1.1.dist-info}/LICENSE +0 -0
- {weco-0.1.0.dist-info → weco-0.1.1.dist-info}/WHEEL +0 -0
weco/__init__.py
ADDED
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,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,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
weco
|
weco-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
weco-0.1.0.dist-info/LICENSE,sha256=NvpxfBuSajszAczWBGKxhHe4gsvil1H63zmu8xXZdL0,1064
|
|
2
|
-
weco-0.1.0.dist-info/METADATA,sha256=ea8ara4e-SA2DxtiUbnxZqSN9yR1iFFiDwxF671veiQ,3214
|
|
3
|
-
weco-0.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
4
|
-
weco-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
-
weco-0.1.0.dist-info/RECORD,,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
File without changes
|
|
File without changes
|