Skip to main content

com2fun - Transform document into function.

This liabrary leverages OpenAI API to predict the output of a function based on its documentation.

Install

pip install --upgrade com2fun

Usage

Basic usage:

import com2fun

@com2fun.com2fun
def top(category: str, n) -> list[str]:
    """top n items"""

In  [1]: top("fish", 5)
Out [1]: ['salmon', 'tuna', 'cod', 'mackerel', 'halibut']
In  [2]: type(top("fish", 5))
Out [2]: list
In  [3]: top("Pen Brand", 3)
Out [3]: ['Pilot', 'Uni-ball', 'Zebra']

Specifiy output format by document:

@com2fun.com2fun
def SWOT(action: str) -> dict:
    """
    SWOT analysis is a powerful tool used to assess an organization’s strengths, 
    weaknesses, opportunities, and threats. It helps organizations focus their 
    resources and actions on areas where they have the most potential for success 
    and makes strategic decisions more transparent.
    
    Generate a SWOT analysis to assist business owners, managers, and individuals 
    in making tough decisions.
    
    Return a dictionary like 
    {
        "strengths": [ (summary, explanation), ...],
        "weaknesses": [...],
        "oppotunities": [...],
        "threats": [...],
    }
    """

In  [4]: print(SWOT("provide additional training for customer service staff"))
Out [4]:
{'strengths': [('Increased customer satisfaction',
   'Providing additional training for customer service staff will help them better understand customer needs and provide better service, leading to increased customer satisfaction.')],
 'weaknesses': [('Cost of training',
   'Providing additional training for customer service staff will require additional resources, such as time and money, which can be a significant cost to the organization.')],
 'opportunities': [('Improved customer service',
   'Providing additional training for customer service staff will help them better understand customer needs and provide better service, leading to improved customer service.')],
 'threats': [('Lack of resources',
   'Providing additional training for customer service staff may require additional resources, such as time and money, which may not be available to the organization.')]}

Chain of thought:

@com2fun.com2fun
def solve_elementary_math(question: str) -> dict:
    """
    {"debug": {"step by step explanation": list[str]},
     "return": float}
    """
In  [5]: solve_elementary_math("Maurita and Felice each take 4 tests. Here are the results of Maurita’s 4 tests: 4, 4, 4, 4. Here are the results for 3 of Felice’s 4 tests: 3, 3, 3. If Maurita’s mean for the 4 tests is 1 point higher than Felice’s, what’s the score of Felice’s 4th test?")
Out [5]:
{'debug': {'step by step explanation': ['Maurita and Felice each took 4 tests.',
   'Maurita got 4, 4, 4, 4 on her tests.',
   'Felice got 3, 3, 3 on 3 of her tests.',
   'Maurita’s mean for the 4 tests is 1 point higher than Felice’s.',
   'We need to find the score of Felice’s 4th test.',
   'Maurita’s mean is 4, so Felice’s mean must be 3.',
   'The sum of Felice’s 4 tests must be 3 + 3 + 3 + x = 12.',
   'Therefore, x = 12 - 9 = 3.',
   'The score of Felice’s 4th test is 3.']},
 'return': 3.0}

Add Example

In  [1]: top.add_example('continents', 3)(['Asia', 'Africa', 'North America'])

Set Client

By default, com2fun uses the OpenAI library openai globally. You can set the client for com2fun by

@com2fun.com2fun(client=openai.OpenAI(api_key="your_api_key"))

Anthropic is also supported:

@com2fun.com2fun(
    SF=com2fun.SF.anthropic.AnthropicChatSF, client=anthropic.Anthropic()
)

Release files for com2fun 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for com2fun 0.1.10
File Size Uploaded
com2fun-0.1.10.tar.gz 9.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for com2fun 0.1.10
File Interpreter ABI Platform
com2fun-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / com2fun-0.1.10.tar.gz

Download URL com2fun-0.1.10.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1d5af4edf009b752ab53c2791db85e32958944148bd0c58fed6c91a940e5ad68
BLAKE2b-256 checksum
How to use checksums
4c405dd39e546cb3354e2bdf54f9a1523ff9d04306cc808a98ddecb12a71a7dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.3 Linux/5.10.192-1-MANJARO

Release files / com2fun-0.1.10-py3-none-any.whl

Download URL com2fun-0.1.10-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c7b51a9c752416d570fefd7550c760fd586d03fedf3510d134e6c4672ff059c
BLAKE2b-256 checksum
How to use checksums
60df2a9f939d840f2735395b60dcc3d06a5526e077512ae720405b76d524f3c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.3 Linux/5.10.192-1-MANJARO

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page