Skip to content

Commit d6e4599

Browse files
committed
Update docs and refs
1 parent c4a0393 commit d6e4599

File tree

9 files changed

+163
-56
lines changed

9 files changed

+163
-56
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<div align="center" style="display: flex; align-items: center; justify-content: center;">
2-
<picture>
3-
<source srcset=".overrides/.icons/custom/ai_function_dark.png" media="(prefers-color-scheme: light)">
4-
<source srcset=".overrides/.icons/custom/ai_function_light.png" media="(prefers-color-scheme: dark)">
5-
<img src=".overrides/.icons/custom/ai_function_light.png" alt="AI functions">
6-
</picture>
2+
<picture>
3+
<source srcset="docs/assets/ai_function_light.png" media="(prefers-color-scheme: dark)">
4+
<img src="docs/assets/ai_function_dark.png" alt="Your Image" style="max-width: 100%;">
5+
</picture>
76
</div>
87

98
#

aifn/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .ai_function import build, AIFunction
1+
from .function import build, AIFunction
22

33
__all__ = ["build", "AIFunction"]
Lines changed: 89 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55
import warnings
66

77

8+
def build(task_description: str, is_async: bool = False, api_key: Optional[str] = None) -> "AIFunction":
9+
"""
10+
Build a specialized AI function for a given task.
11+
12+
Parameters
13+
----------
14+
task_description : str
15+
The description of the task for which the function is being built.
16+
17+
is_async : bool, optional
18+
Indicates whether the function should be asynchronous. Defaults to False.
19+
20+
api_key : str, optional
21+
The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - `WECO_API_KEY`.
22+
23+
Returns
24+
-------
25+
AIFunction
26+
A specialized AI function for the given task.
27+
28+
Examples
29+
--------
30+
>>> from aifn import build
31+
>>> country_to_capital = build("Given a country name, return its capital city as 'capital'.")
32+
>>> country_to_capital("India").output["capital"]
33+
'New Delhi'
34+
"""
35+
client = Client(api_key=api_key)
36+
fn_name, fn_version, fn_desc = client.build(task_description=task_description)
37+
return AIFunction(fn_name=fn_name, version=fn_version, fn_desc=fn_desc, is_async=is_async, api_key=api_key)
38+
39+
840
class AIFunction:
941
"""
1042
An AI powered function that can be called like any other function to perform a specific task.
@@ -83,6 +115,33 @@ def __call__(
83115
-------
84116
NamedTuple
85117
A NamedTuple containing the output and metadata of the response.
118+
119+
Examples
120+
--------
121+
122+
**Build and call a function**
123+
124+
>>> from aifn import build
125+
>>> country_to_capital = build("Given a country name, return its capital city as 'capital'.")
126+
>>> response = country_to_capital("France")
127+
>>> response.output["capital"]
128+
'Paris'
129+
130+
**Retrieve and call an existing function**
131+
132+
>>> from aifn import AIFunction
133+
>>> idea_evaluator = AIFunction("BusinessIdeaAnalyzer-XYZ123")
134+
>>> response = idea_evaluator("A platform to connect pet owners with pet sitters.")
135+
>>> response.output["score"]
136+
0.85
137+
138+
**Call an existing function with image inputs**
139+
140+
>>> from aifn import AIFunction
141+
>>> image_classifier = AIFunction("ImageClassifier-ABC123")
142+
>>> response = image_classifier(images_input=["https://example.com/cat.jpg"])
143+
>>> response.output["label"]
144+
'cat'
86145
"""
87146
return self._fn(
88147
fn_name=self.fn_name,
@@ -119,6 +178,16 @@ def batch(
119178
-------
120179
List[NamedTuple]
121180
A list of NamedTuples, each containing the output and metadata of the response.
181+
182+
Examples
183+
-------
184+
>>> from aifn import build
185+
>>> country_to_capital = build("Given a country name, return its capital city as 'capital'.")
186+
>>> batch_inputs = [{"text_input": "India"}, {"text_input": "USA"}, {"text_input": "UK"}]
187+
>>> responses = country_to_capital.batch(batch_inputs)
188+
>>> outputs = [response.output["capital"] for response in responses]
189+
>>> outputs
190+
['New Delhi', 'Washington, D.C.', 'London']
122191
"""
123192
return self._batch_fn(
124193
fn_name=self.fn_name,
@@ -179,12 +248,21 @@ async def async_wrapper(*args, **kwargs):
179248

180249
def make_sync(self) -> "AIFunction":
181250
"""
182-
Convert the AI function to synchronous mode.
251+
Convert an asynchronous AI function to a synchronous AI Function.
183252
184253
Returns
185254
-------
186255
AIFunction
187256
A new AIFunction instance in synchronous mode.
257+
258+
Examples
259+
-------
260+
>>> from aifn import build
261+
>>> country_to_capital = build("Given a country name, return its capital city as 'capital'.", is_async=True)
262+
>>> sync_country_to_capital = country_to_capital.make_sync()
263+
>>> response = sync_country_to_capital("USA")
264+
>>> response.output["capital"]
265+
'Washington, D.C.'
188266
"""
189267
if not self.is_async:
190268
warnings.warn(f"{self} is already a synchronous AI Function...Returning the same object.")
@@ -195,41 +273,25 @@ def make_sync(self) -> "AIFunction":
195273

196274
def make_async(self) -> "AIFunction":
197275
"""
198-
Convert the AI function to asynchronous mode.
276+
Convert a synchronous AI function to an asynchronous AI Function.
199277
200278
Returns
201279
-------
202280
AIFunction
203281
A new AIFunction instance in asynchronous mode.
282+
283+
Examples
284+
-------
285+
>>> from aifn import build
286+
>>> country_to_capital = build("Given a country name, return its capital city as 'capital'.", is_async=False)
287+
>>> async_country_to_capital = country_to_capital.make_async()
288+
>>> response = await async_country_to_capital("USA")
289+
>>> response.output["capital"]
290+
'Washington, D.C.'
204291
"""
205292
if self.is_async:
206293
warnings.warn(f"{self} is already an asynchronous AI Function...Returning the same object.")
207294
return self
208295
return AIFunction(
209296
fn_name=self.fn_name, version=self.version, fn_desc=self.fn_desc, is_async=True, api_key=self._client.api_key
210297
)
211-
212-
213-
def build(task_description: str, is_async: bool = False, api_key: Optional[str] = None) -> AIFunction:
214-
"""
215-
Build a specialized AI function for a given task.
216-
217-
Parameters
218-
----------
219-
task_description : str
220-
The description of the task for which the function is being built.
221-
222-
is_async : bool, optional
223-
Indicates whether the function should be asynchronous. Defaults to False.
224-
225-
api_key : str, optional
226-
The API key for the WecoAI service. If not provided, the API key must be set using the environment variable - `WECO_API_KEY`.
227-
228-
Returns
229-
-------
230-
AIFunction
231-
A specialized AI function for the given task.
232-
"""
233-
client = Client(api_key=api_key)
234-
fn_name, fn_version, fn_desc = client.build(task_description=task_description)
235-
return AIFunction(fn_name=fn_name, version=fn_version, fn_desc=fn_desc, is_async=is_async, api_key=api_key)

docs/api/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# API Reference Guide
1+
# API Reference
22

3-
:::aifn.ai_function
3+
:::aifn.function

docs/cookbook/cookbook.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
<div align="center" style="display: flex; align-items: center; justify-content: left;">
2-
<a href="https://git.io/typing-svg"><img src="https://readme-typing-svg.demolab.com?font=Georgia&size=32&duration=4000&pause=400&color=EE4C2C&vCenter=true&multiline=false&width=750&height=100&lines=AI+Function+Cookbook;" alt="Typing SVG" /></a>
3-
</div>
4-
51
## Getting Started
62

73
A client facing API for interacting with the [Weco AI](https://www.weco.ai/)'s AI function [platform](https://www.aifunction.com). It empowers you to go from zero to AI in just a few seconds!

docs/index.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<div align="center" style="display: flex; align-items: center; justify-content: center;">
2-
<picture>
3-
<source srcset="assets/ai_function_dark.png" media="(prefers-color-scheme: light)">
4-
<source srcset="assets/ai_function_dark.png" media="(prefers-color-scheme: dark)">
5-
<img src="assets/ai_function_light.png" alt="AI functions">
6-
</picture>
7-
</div>
1+
<figure markdown="span">
2+
![Image title](assets/ai_function_light.png#only-dark)
3+
![Image title](assets/ai_function_dark.png#only-light)
4+
</figure>
85

96
#
107

docs/stylesheets/extra.css

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Style links in the main content */
2+
main a {
3+
color: #FF5722 !important; /* Highlight links in orange */
4+
text-decoration: none; /* Remove underline */
5+
}
6+
7+
main a:hover, main a:focus {
8+
color: #E64A19 !important; /* Slightly darker orange on hover */
9+
text-decoration: none; /* Ensure no underline */
10+
}
11+
12+
/* Style links in the Table of Contents */
13+
nav[aria-label="Table of contents"] a {
14+
color: inherit !important; /* Keep default color initially */
15+
text-decoration: none;
16+
}
17+
18+
nav[aria-label="Table of contents"] a:hover, nav[aria-label="Table of contents"] a:focus {
19+
color: #FF5722 !important; /* Change text to orange on hover */
20+
text-decoration: none; /* Ensure no underline */
21+
}
22+
23+
/* Style links in the header navigation (e.g., About, Contributing) */
24+
header a, .md-header-nav a, .md-nav__item a {
25+
color: inherit !important; /* Keep default color initially */
26+
text-decoration: none;
27+
}
28+
29+
header a:hover, header a:focus, .md-header-nav a:hover, .md-header-nav a:focus, .md-nav__item a:hover, .md-nav__item a:focus {
30+
color: #FF5722 !important; /* Change text to orange on hover */
31+
text-decoration: none; /* Ensure no underline */
32+
}
33+
34+
/* Style links in the sidebar navigation */
35+
nav[aria-label="Navigation"] a {
36+
color: inherit !important; /* Keep default color initially */
37+
text-decoration: none;
38+
}
39+
40+
nav[aria-label="Navigation"] a:hover, nav[aria-label="Navigation"] a:focus {
41+
color: #FF5722 !important; /* Change text to orange on hover */
42+
text-decoration: none; /* Ensure no underline */
43+
}
44+
45+
/* Style links in the footer */
46+
footer a {
47+
color: inherit !important; /* Keep default color initially */
48+
text-decoration: none;
49+
}
50+
51+
footer a:hover, footer a:focus {
52+
color: #FF5722 !important; /* Change text to orange on hover */
53+
text-decoration: none; /* Ensure no underline */
54+
}

examples/cookbook.ipynb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
{
22
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"metadata": {},
6-
"source": [
7-
"<div align=\"center\" style=\"display: flex; align-items: center; justify-content: left;\">\n",
8-
" <a href=\"https://git.io/typing-svg\"><img src=\"https://readme-typing-svg.demolab.com?font=Georgia&size=32&duration=4000&pause=400&color=EE4C2C&vCenter=true&multiline=false&width=750&height=100&lines=AI+Function+Cookbook;\" alt=\"Typing SVG\" /></a>\n",
9-
"</div>"
10-
]
11-
},
123
{
134
"cell_type": "markdown",
145
"metadata": {},

mkdocs.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ plugins:
7979
show_signature_annotations: false
8080
show_source: false
8181
heading_level: 2
82+
show_symbol_type_toc: true
83+
members_order: source
84+
merge_init_into_class: true
8285

8386
# Customization
8487
extra:
@@ -94,10 +97,12 @@ extra:
9497

9598
extra_javascript:
9699
- javascripts/katex.js
100+
- javascripts/mathjax.js
97101
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js # (1)!
98102
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js
99103

100104
extra_css:
105+
- stylesheets/extra.css
101106
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
102107

103108
# Extensions
@@ -111,11 +116,14 @@ markdown_extensions:
111116
anchor_linenums: true
112117
line_spans: __span
113118
pygments_lang_class: true
119+
- attr_list
120+
- md_in_html
114121
- pymdownx.inlinehilite
115122
- pymdownx.superfences
116123
- pymdownx.snippets
124+
- pymdownx.blocks.caption
117125

118-
# Page treec
126+
# Page tree
119127
nav:
120128
- 'About': index.md
121129

0 commit comments

Comments
 (0)