Skip to main content

A lightweight library integrating LLM natively into Python

Project description

OpenHosta

v3.0 - Integrates Inria Comments


You can read the doc or directly have a look at tests files for multiples exemples.

OpenHosta is a powerful Python extension designed to seamlessly integrate semantic capabilities seen in Large Language Models (LLMs) into tradictional development environments, enabling AI-powered function emulation that maintains native Python syntax and paradigms. Its strength lies in its simplicity and flexibility, allowing developers to easily create AI-enhanced applications while maintaining clean, Pythonic code structure.

OpenHosta can run fully offline with a local model, or use a remote model via API key.

- The future of development is human -

For this project, we have adopted a Code of Conduct to ensure a respectful and inclusive environment for all contributors. Please take a moment to read it.

The simplest usage of OpenHosta is to allow semantic tests in your code, like this:

from OpenHosta import test

sentence = "You are an nice person."
# You shall try with this too:
# sentence = "You are a stupid #@!!~uk."

if test(f"this contains an insult: {sentence}"):
    print("The sentence is considered an insult.")
else:
    print("The sentence is not considered an insult.")

# The sentence is not considered an insult.

But the most powerful feature of OpenHosta is the emulate function, which allows you to define a function with a docstring and let OpenHosta implement it for you using AI. The emulate function supports basic python types, dataclasses, pydantic, enums and Images. You can use all these types as input and output of the function (except for Images which can only be input).

from OpenHosta import emulate

from enum import Enum
class DocumentType(Enum):
    OLD_BOOK = "old_book"
    ARTICLE = "article"
    REPORT = "report"
    THESIS = "thesis"

from PIL.Image import Image, open

def classify_document(page:Image)->DocumentType:
    """
    This function classifies the document based on the content of the page givent in parameter.
    
    Arguments:
    page: An image of the document page to classify.

    Returns:
    DocumentType: The type of the document
    """
    return emulate()

import requests
url=r"https://www.inria.fr/sites/default/files/2024-01/A_outil_innovant_caracte%CC%81riser_plantes_1827x1026_bonnier-2.png"
img = open(requests.get(url, stream=True).raw)

result = classify_document(img)

result
# <DocumentType.OLD_BOOK: 'old_book'>

Table of Content


How to install OpenHosta ?

You can install OpenHosta either via pip or via GitHub.

We encourage you to use a virtual environment. You can create one with:

python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`

Then you can install OpenHosta with one of the following commands:

pip install OpenHosta

or

pip install "git+https://github.com/hand-e-fr/OpenHosta.git"

or for a specific branch

pip install "git+https://github.com/hand-e-fr/OpenHosta.git@unstable" # for the latest unstable version

See the full installation guide

Example

You shall set your API credentials either via environment variables or directly in your code. For now we assume that you have an OpenAI API key and that you have set it in .env like this:

# This is the content of your .env file to be placed in the root of your project
OPENHOSTA_DEFAULT_MODEL_NAME="gpt-4.1"
OPENHOSTA_DEFAULT_MODEL_API_KEY="put-your-api-key-here"

You can also use a local model using ollama. See documentation.

from OpenHosta import emulate

def translate(text:str, language:str)->str:
    """
    This function translates the text in the “text” parameter into the language specified in the “language” parameter.
    """
    return emulate()

result = translate("Hello World!", "French")

print(result)
# Bonjour le monde !

You check OpenHosta's documentation for more detailled informations or exemple

Further information

Contributing

We warmly welcome contributions from the community. Whether you are an experienced developer or a beginner, your contributions are welcome.

If you wish to contribute to this project, please refer to our Contribution Guide and our Code of Conduct.

Browse the existing issues to see if someone is already working on what you have in mind or to find contribution ideas.

License

This project is licensed under the MIT License. This means you are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, subject to the following conditions:

  • The text of the license below must be included in all copies or substantial portions of the software.

See the LICENSE file for more details.

Authors & Contact

For further questions or assistance, please refer to partner hand-e or contact us directly via github.

Authors:

  • Emmanuel Batt: Manager and Coordinator, Founder of Hand-e
  • William Jolivet: DevOps, SysAdmin
  • Léandre Ramos: IA developer
  • Merlin Devillard: UX designer, Product Owner

GitHub: https://github.com/hand-e-fr/OpenHosta


Thank you for your interest in our project and your potential contributions!

The OpenHosta Team

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

openhosta-3.0.3.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openhosta-3.0.3-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file openhosta-3.0.3.tar.gz.

File metadata

  • Download URL: openhosta-3.0.3.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for openhosta-3.0.3.tar.gz
Algorithm Hash digest
SHA256 0a48349e0bd24c30fad954eb01b12268b24bd927730e1e7dde94cfc866930a73
MD5 6808e5d1200daa54842d7e0891e25832
BLAKE2b-256 896cb20a2056edc03dbf04435443a904a792e38d5ccad5c39130d405be91f805

See more details on using hashes here.

File details

Details for the file openhosta-3.0.3-py3-none-any.whl.

File metadata

  • Download URL: openhosta-3.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for openhosta-3.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5cc19ead42bda3dd80123bdba626697688a496904fb164806126ea8a60da52fc
MD5 ef9e12571b3e97ca119e0a9d839fd132
BLAKE2b-256 fabd6eb863934cff0a57ae259ec75a191aabce68edd5e642a2cd296ef3985681

See more details on using hashes here.

Supported by

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