Skip to main content

A python library for extracting organized data out of chaos using large-language-models (LLMs) like ChatGPT.

Project description

From Chaos

A python library for extracting organized data out of chaos using large-language-models (LLMs) like ChatGPT and Gemini-Pro.

Installation

To install, use the following command:

pip install fromchaos

In order to use FromChaos, you must have the following environment variable set in the environment where your script is running:

OPENAI_API_KEY="<<your-openai-api-key-here>>"

Using FromChaos

FromChaos uses ChatGPT as its primary LLM (though others could be incorporated if desired). It accepts at its most basic level a question (about the data you want to get back), and the context (where to extract the value from).

Depending on your use-case, there are different classes of FromChaos to use. The following are code examples.


FromChaosList - Parsing Data To A List

With a block of text, using FromChaosList you can extract values as a python list.

from fromchaos import FromChaosList

context = """
This is a long string of data, it could be anything you like, plain text,
html, markdown, or something else like JSON.
"""

question = "Identify all data types that are mentioned"

try:
    chaos = FromChaosList(question, context, model='gpt-4')
    print(chaos.response)
except Exception:
    print('An error occured')

The response is a python list object, or an exception is thrown.

[
    "plain text",
    "html",
    "markdown",
    "json"
]

FromChaosShortString - Short Strings

For a quick summary of something, use the FromChaosShortString class.

from fromchaos import FromChaosShortString

context = """
Some very large text that talks about a variety of different things. Canada is a really big country. Australia is also big, but there are spiders. Italy has very good food. There's really good beef noodle soup in Taiwan.
"""

question = "Summarize what is talked about in these paragraphs."

try:
    chaos = FromChaosShortString(question, context, model='gpt-4')
    print(chaos.response)
except Exception:
    print('An error occured')

The response is a short python string.

The text talks about various characteristics of Canada, Australia, Italy, and Taiwan.

FromChaosBoolOrNone - True/False, or None values

For classifying something as either True, False, or None, use the FromChaosBoolOrNone class.

from fromchaos import FromChaosBoolOrNone

context = """
Some very large text that talks about a variety of different things. Canada is a really big country. Australia is also big, but there are spiders. Italy has very good food. There's really good beef noodle soup in Taiwan.
"""

question = "Is the united states mentioned in this paragraph?."

try:
    chaos = FromChaosBoolOrNone(question, context, model='gpt-4')
    print(chaos.response)
except Exception:
    print('An error occured')

The response is a boolean object, or Nonetype.

False

FromChaosParagraph - Get a paragraph of text

FromChaosParagraph works similar to FromChaosShortString, except instead of a succinct response, it allows the model to elaborate for a little bit for a longer response.

from fromchaos import FromChaosParagraph

context = """
The working holiday visa is valid for 12 months and it cannot be renewed. Applicants must show proof of funds. To apply, visit the consolate and pay the application fee of $65 CAD, then wait 3 weeks.
"""

question = "Summarize this visa."

try:
    chaos = FromChaosParagraph(question, context, model='gpt-4', max_chars=2000)
    print(chaos.response)
except Exception:
    print('An error occured')

The response is returned as a long string of text, or an exception is thrown

This visa is a working-holiday visa, with a validity of 12 months. This visa is non-renewable. For those interested in applying, proof of sufficient funds must be shown, and the consulate must be visited. An application fee of $65 CAD will apply, and a 3-week waiting period will be required.

FromChaosDict - Getting a dictionary

FromChaosDict allows you to pass in a dictionary of your choosing as a sample object, and get the response in the same format.

from fromchaos import FromChaosDict

context = """
The working holiday visa is valid for 12 months and it cannot be renewed. Applicants must show proof of funds. To apply, visit the consolate and pay the application fee of $65 CAD, then wait 3 weeks.
"""

question = "What is the fee, if any, for applying to this visa?."

sample_obj = {
    'amount': 400,
    'currency': 'USD'
}

try:
    chaos = FromChaosDict(question, context, sample_obj=sample_obj, model='gpt-4')
    print(chaos.response)
except Exception:
    print('An error occured')

The response is returned as a python dictionary, or an exception is thrown

{
    "amount": 65,
    "currency": "CAD"
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fromchaos-0.0.10.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

fromchaos-0.0.10-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fromchaos-0.0.10.tar.gz.

File metadata

  • Download URL: fromchaos-0.0.10.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for fromchaos-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b900273ac291542db7baecd069d70665a72a625feb3d225b97932ce094267049
MD5 de5514bcbb76d13a04254d63352d035e
BLAKE2b-256 859538eaf3ea573105c307ef412bd2dc4367e24ee24a670c19684f25e543caa0

See more details on using hashes here.

File details

Details for the file fromchaos-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: fromchaos-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for fromchaos-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 bbff02cd606d7383b5d27be293c7d14299cfe6e5f45df385d5cd41a6d7288d7c
MD5 98ec9a28d00a1c469570e8d79ad8ce62
BLAKE2b-256 e2fae4ce1d797c50e695a39ec87306e4d0f1ca158bed43ff281b1dd2b8a5ae85

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page