Skip to main content

unsure

unsure is a library for creating operations on uncertain or ambiguous values, utilizing an inference endpoint to determine transformations and comparisons. It's meant to leverage ai while yielding predictable and invariant results.

Installation

To install the package, run:

pip install unsurepy

Configuration

All that needs to be configured is the inference endpoint.

Through API Key

It supports Groq apis and OpenAi apis for now, so a groqApiKey can be provided like this

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

and for openAi

from unsurepy import create_unsure

unsure = create_unsure(groq_ai_api_key='your key here')

Through and inference function

from unsurepy import create_unsure

def inference_endpoint(q: str) -> str:
    # any function that returns a string here, you can call OpenAI, Gemini, Claude, or your own model, just return a string
    pass

create_unsure(inference_endpoint=inference_endpoint)

Usage

Once it's configured you can start using the operators just like this

Is operator:

Checks equality. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Lion").is_("Mammal"))  # True

Pick operator:

Picks an information from a string. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Contact Number: +1-800-555-5555").pick("phone number"))  # "+1-800-555-5555"
print(unsure("Phone: +1-800-555-5555").pick("phone number"))  # "+1-800-555-5555"
print(unsure("Call us at +1-800-555-5555").pick("phone number"))  # "+1-800-555-5555"

Categorize operator:

Categorizes the string into the given categories. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Sky").categorize(["blue", "green"]))  # "blue"
print(unsure("Grass").categorize(["blue", "green"]))  # "green"

flatMapTo operator:

Transforms the string into what's demanded. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Response: {\"key\": \"should get this\"}").flat_map_to("key's value"))  # "should get this"
print(
    unsure("HTML Content: <html><body><div class=\"scrapable\">Target Content<div></body></html>")
    .flat_map_to("content of the div with the class scrapable")
)  # "target content"
print(unsure("Favorite Color: #FF5733").flat_map_to("color in hex"))  # "#ff5733"
print(unsure("Order Total: 12345 USD").flat_map_to("price"))  # "12345"

mapTo operator:

Transforms the string into what's demanded but returns an unsure, so it's chainable. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Amount: 200.23 $").map_to("number").map_to("integer").flat())  # "200"

flat operator:

Returns either the changed transformation's result or the initial value if no mapTo was used. Example:

from unsurepy import create_unsure

unsure = create_unsure(groq_api_key='your key here')

print(unsure("Amount: 200.23 $").map_to("number").map_to("integer").flat())  # "200"
print(unsure("Some value").flat())  # "Some value"

Options

inferenceEndpoint: The function that will be called in the operators. groqApiKey: The Api key that will be used to call groq APIs using llama3-70b-8192 model. openAiApiKey: The Api key that will be used to call Open Ai APIs using gpt-3.5-turbo. model: You can specify the model you want to use, for open source models llama3-70b-8192 works best which is the default. preventLowerCase: Prevents lowercasing the inference response.

Note: If both inferenceEndpoint and groqApiKey are provided inferenceEndpoint will be used.

License

This project is under the ISC license. Requests and contributions are most welcomed.

Metadata

Release files for unsurepy 1.0.2

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

Source distribution (sdist)

Source distribution for unsurepy 1.0.2
File Size Uploaded Provenance Actions
unsurepy-1.0.2.tar.gz 4.2 kB Without provenance Details for unsurepy-1.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 10.2 kB

Release files / unsurepy-1.0.2.tar.gz

Download URL unsurepy-1.0.2.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
db15fd07b87ef00038874fc502d8bef831b7aed3b51de59ec69bab5f79187874
BLAKE2b-256 checksum
How to use checksums
09686554b157215c7a3a8de6050585e09288b04f706d8f1862ba5ac91677e75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Release files / unsurepy-1.0.2-py3-none-any.whl

Download URL unsurepy-1.0.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
205c43238c4feaf0f005a5218ab1c34fa8265fcba7dcdd23378a4cfc16396f19
BLAKE2b-256 checksum
How to use checksums
ee32f4ce41f5e48b1f7a019e0f6927414b8daee84f838ac3352b9cb9aea86b08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.12.4

Security for unsurepy 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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