Skip to content

Commit 693af90

Browse files
authored
Merge pull request #231 from hand-e-fr/3.0.0_beta1
2 parents 3ed47e5 + 203997d commit 693af90

106 files changed

Lines changed: 4728 additions & 8372 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/quality_check.yml

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
python-version: "3.12"
4545

4646
- name: Install dependencies
47-
run: pip install .[dev,pydantic]
47+
run: pip install .[dev]
4848

4949
- name: Run autopep8
5050
run: python -m autopep8 --recursive --in-place src/OpenHosta
@@ -67,7 +67,7 @@ jobs:
6767
python-version: "3.12"
6868

6969
- name: Install dependencies
70-
run: pip install .[dev,pydantic]
70+
run: pip install .[dev]
7171

7272
- name: Run mypy
7373
run: python -m mypy src/OpenHosta
@@ -81,7 +81,7 @@ jobs:
8181
run: python -m bandit -c pyproject.toml -r src/OpenHosta -f txt
8282
continue-on-error: true
8383

84-
unit-tests:
84+
functionnal-tests:
8585
needs: setup
8686
runs-on: ubuntu-latest
8787
steps:
@@ -92,28 +92,18 @@ jobs:
9292

9393
- name: Install dependencies
9494
run: pip install .[tests]
95-
96-
- name: Run unit tests
97-
run: python -m pytest tests/unitTests -v --cov=OpenHosta.core
9895

99-
functional-tests:
100-
needs: setup
101-
runs-on: ubuntu-latest
102-
steps:
103-
- uses: actions/checkout@v4
104-
- uses: actions/setup-python@v5
105-
with:
106-
python-version: "3.12"
107-
108-
- name: Install dependencies
109-
run: pip install .[tests]
110-
- name: Run functional tests
96+
- name: create .env file
97+
run: |
98+
echo "OPENHOSTA_DEFAULT_MODEL_API_KEY=${{ secrets.OPENHOSTA_DEFAULT_MODEL_API_KEY }}" >> .env
99+
100+
- name: Run functionnal tests
111101
env:
112-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
113-
run: python -m pytest tests/functionnalTests -v --cov=OpenHosta
102+
OPENHOSTA_DEFAULT_MODEL_API_KEY: ${{ secrets.OPENHOSTA_DEFAULT_MODEL_API_KEY }}
103+
run: python -m pytest tests/functionnal -v --cov=OpenHosta
114104

115105
notify:
116-
needs: [code-quality, static-analysis, unit-tests, functional-tests]
106+
needs: [code-quality, static-analysis, functionnal-tests]
117107
runs-on: ubuntu-latest
118108
if: always()
119109
steps:

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ build/
1919
mypy/
2020
.mypy_cache/
2121
linter.py
22-
*pt.py
23-
tests/reports/*report.txt
22+
tests/reports/*report.txt
23+
tests/functionnalTests/.env
24+
**/.env

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ All significant changes to this project will be documented in this file.
2020

2121
- **Fixes**
2222
- #195 fix Bug with pydantic import
23-
- #199 improve pydantic return type support for List[BaseModel] and Dict[..., BaseModel]
23+
- #199 improve pydantic return type support for List[Model] and Dict[..., Model]
2424

2525
## **v2.1.5**
2626
- **Fixes**
@@ -42,7 +42,7 @@ All significant changes to this project will be documented in this file.
4242

4343
## **v2.1.3**
4444
- **Features**
45-
- Added `additionnal_headers` in `Model` to add specific values in the header of the request send to the API.
45+
- Added `additionnal_headers` in `OpenAICompatibleModel` to add specific values in the header of the request send to the API.
4646
- `ask` can now be used without specify the `user` parameter name.
4747

4848
- **Fixes**
@@ -57,7 +57,7 @@ All significant changes to this project will be documented in this file.
5757

5858
## **v2.1.2**
5959
- **Doc**
60-
- Fix the example for the custom Model class with a Llama Model
60+
- Fix the example for the custom OpenAICompatibleModel class with a Llama OpenAICompatibleModel
6161

6262
- **Fixes**
6363
- Remove the PIL dependency
@@ -67,7 +67,7 @@ All significant changes to this project will be documented in this file.
6767
- Changed examples syntax in the system prompt for better performances.
6868

6969
- **Doc**
70-
- Added an example for a custom Model class with an Llama model.
70+
- Added an example for a custom OpenAICompatibleModel class with an Llama model.
7171

7272
## **v2.0-beta2**
7373
- **Added**
@@ -131,7 +131,7 @@ All significant changes to this project will be documented in this file.
131131
## **v1.1.1** 10/07/24
132132

133133
- **Features**
134-
- Added `_last_request` attributs to the `Model` object
134+
- Added `_last_request` attributs to the `OpenAICompatibleModel` object
135135

136136
- **Optimization**
137137
- Reduce the `emulate`'s user prompt to only the function call string and move the rest in the system prompt.
@@ -179,7 +179,7 @@ All significant changes to this project will be documented in this file.
179179
- the `emulate` function is now decorator-resistant.
180180
- The function `config.set_default_model` works now w/ `config.set_default_apiKey`
181181
- `thought` function now accept multiple arguments
182-
- `suggest` and `analytics` call now th LLM with `Model` class (`ai_call`)
182+
- `suggest` and `analytics` call now th LLM with `OpenAICompatibleModel` class (`ai_call`)
183183
- `emulate` works now in a nested function.
184184
- Added Flask compatibility
185185

README.md

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
11
# OpenHosta
2-
v2.2.2 - Open-Source Project
32

4-
<a href="https://colab.research.google.com/github/hand-e-fr/OpenHosta/blob/main/docs/openhosta_mistral_small.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> Basic Usage - local LLM (Mistral-Small-2501)</a>
5-
<br/>
6-
<a href="https://colab.research.google.com/github/hand-e-fr/OpenHosta/blob/main/docs/openhosta_phi4.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> Basic Usage - Synthetic Data - local LLM (phi-4)</a>
7-
<br/>
8-
<a href="https://colab.research.google.com/github/hand-e-fr/OpenHosta/blob/main/docs/openhosta_agent.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> Simple AI Agent with gpt-4o</a>
9-
<br/>Or have a look at [regression tests files](https://github.com/hand-e-fr/OpenHosta/tree/main/tests/non-regression) for multiples exemples.
3+
v3.0.0 - Integrates Inria Comments
104

11-
OpenHosta is a powerful Python tool designed to seamlessly integrate Large Language Models (LLMs) into 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.
5+
<br/>You can read the doc or directly have a look at [tests files](https://github.com/hand-e-fr/OpenHosta/tree/main/tests/) for multiples exemples.
126

13-
**- The future of development is human -**
7+
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.
8+
9+
OpenHosta can run fully offline with a local model, or use a remote model via API key.
1410

15-
Welcome to the OpenHosta documentation, a powerful tool that facilitates the integration LLM in the development environnement. OpenHosta is used to emulate functions using AI, while respecting Python's native paradygma and syntax.
11+
**- The future of development is human -**
1612

1713
For this project, we have adopted a [Code of Conduct](https://github.com/hand-e-fr/OpenHosta/blob/main/CODE_OF_CONDUCT.md) to ensure a respectful and inclusive environment for all contributors. Please take a moment to read it.
1814

15+
The simplest usage of OpenHosta is to allow semantic tests in your code, like this:
16+
17+
```python
18+
from OpenHosta import test
19+
20+
sentence = "You are an nice person."
21+
# You shall try with this too:
22+
# sentence = "You are a stupid #@!!~uk."
23+
24+
if test(f"this contains an insult: {sentence}"):
25+
print("The sentence is considered an insult.")
26+
else:
27+
print("The sentence is not considered an insult.")
28+
29+
# The sentence is not considered an insult.
30+
```
31+
32+
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).
33+
34+
```python
35+
from OpenHosta import emulate
36+
37+
from enum import Enum
38+
class DocumentType(Enum):
39+
OLD_BOOK = "old_book"
40+
ARTICLE = "article"
41+
REPORT = "report"
42+
THESIS = "thesis"
43+
44+
from PIL.Image import Image, open
45+
46+
def classify_document(page:Image)->DocumentType:
47+
"""
48+
This function classifies the document based on the content of the page givent in parameter.
49+
50+
Arguments:
51+
page: An image of the document page to classify.
52+
53+
Returns:
54+
DocumentType: The type of the document
55+
"""
56+
return emulate()
57+
58+
import requests
59+
url=r"https://www.inria.fr/sites/default/files/2024-01/A_outil_innovant_caracte%CC%81riser_plantes_1827x1026_bonnier-2.png"
60+
img = open(requests.get(url, stream=True).raw)
61+
62+
result = classify_document(img)
63+
64+
result
65+
# <DocumentType.OLD_BOOK: 'old_book'>
66+
```
67+
1968
## Table of Content
2069

2170
- [OpenHosta](#openhosta)
@@ -40,17 +89,31 @@ pip install OpenHosta
4089
or
4190

4291
```sh
43-
git clone https://github.com/hand-e-fr/OpenHosta.git
92+
pip install https://github.com/hand-e-fr/OpenHosta.git
4493
```
4594

46-
**See the full installation guide [here](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/installation.md)**
95+
or for a specific branch
96+
97+
```sh
98+
pip install "git+https://github.com/hand-e-fr/OpenHosta.git@unstable" # for the latest unstable version
99+
```
100+
101+
**See the full [installation guide](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/installation.md)**
47102

48103
## Example
49104

50-
```python
51-
from OpenHosta import emulate, config
105+
You shall set your API credentials either via environment variables or directly in your code.
106+
For now we assume that you have an OpenAI API key and that you have set it in .env like this:
107+
108+
```env
109+
OPENHOSTA_DEFAULT_MODEL_NAME="gpt-4.1"
110+
OPENHOSTA_DEFAULT_MODEL_API_KEY="put-your-api-key-here"
111+
```
52112

53-
config.set_default_apiKey("put-your-api-key-here")
113+
You can also use a local model using ollama. See [documentation](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/installation.md#local-models).
114+
115+
```python
116+
from OpenHosta import emulate
54117

55118
def translate(text:str, language:str)->str:
56119
"""
@@ -59,9 +122,12 @@ def translate(text:str, language:str)->str:
59122
return emulate()
60123

61124
result = translate("Hello World!", "French")
125+
62126
print(result)
127+
# Bonjour le monde !
63128
```
64-
You check OpenHosta's [documentation](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/doc.md) for more detailled informations or exemple
129+
130+
You check [OpenHosta's documentation](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/doc.md) for more detailled informations or exemple
65131

66132
## Further information
67133

0 commit comments

Comments
 (0)