Skip to content

Commit a944382

Browse files
Merge pull request #119 from hand-e-fr/dev
Dev
2 parents ef2ca0d + b241f96 commit a944382

9 files changed

Lines changed: 48 additions & 20 deletions

File tree

CHAGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ All significant changes to this project will be documented in this file.
44

55
---
66

7-
## **v1.1rc3**
7+
## **v1.1-rc4**
8+
9+
- **Feature**
10+
- Added `suggest` function. Works the same as the `__suggest__` attributs but in a function
11+
12+
- **Doc**
13+
- Many inconsistencies and errors corrected.
14+
15+
- **Internal**
16+
- Added Github workflows for linting, formating and testing when pushing to dev and main
17+
18+
- **Fixes**
19+
- `suggest` attribute `diagramm` is now `diagram`
20+
21+
## **v1.1-rc3**
822

923
- **Fixes**
1024
- `emulate` now works when emulated function is called inside another one

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ git clone git@github.com:hand-e-fr/OpenHosta.git
8181
2. Navigate to the **directory** of the cloned project:
8282

8383
```bash
84-
cd OpenHosta-dev
84+
cd OpenHosta
8585
```
8686

8787
3. Ensure you have installed the necessary **dependencies** before starting.
@@ -90,9 +90,11 @@ cd OpenHosta-dev
9090
pip install .
9191
```
9292

93-
4. Check that you have the correct version.
93+
4. Check that you have the correct version from Python.
9494

9595
```python
96+
import OpenHosta
97+
9698
OpenHosta.__version__
9799
```
98100

doc/Docs.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Let's **get started**! First here's the **table of contents** to help you naviga
7676
- ["emulate" Function](#emulate-function)
7777
- [Supported types \& Pydantic](#supported-types--pydantic)
7878
- [Integration Details](#integration-details)
79-
- ["suggest" Attributs](#suggest-attributs)
79+
- ["suggest" Function](#suggest-function)
8080
- [Usage](#usage)
8181
- [Output Examples](#output-examples)
8282
- ["thought" Function](#thought-function)
@@ -186,7 +186,7 @@ my_model = config.Model(
186186

187187
def find_name_age(sentence:str, id:dict)->dict:
188188
"""
189-
This function find in a text the name and the age of a personn.
189+
This function find in a text the name and the age of a person.
190190
191191
Args:
192192
sentence: The text in which to search for information
@@ -249,15 +249,15 @@ Let's take the same example, but using this feature:
249249
from pydantic import BaseModel
250250
from OpenHosta import emulate, config
251251

252-
class Personn(BaseModel):
252+
class Person(BaseModel):
253253
name: str
254254
age: int
255255

256256
config.set_default_api_key("put-your-api-key-here")
257257

258-
def find_first_name(sentence:str)->Personn:
258+
def find_first_name(sentence:str)->Person:
259259
"""
260-
This function find in a text the name and the age of a personn.
260+
This function find in a text the name and the age of a person.
261261
262262
Args:
263263
sentence: The text in which to search for information
@@ -271,7 +271,7 @@ def find_first_name(sentence:str)->Personn:
271271

272272
Note that the Pydantic model cannot be defined inside a function, as this will produce an error.
273273

274-
### "suggest" Attributs
274+
### "suggest" Function
275275

276276
When you use the emulate function, an attribute is automatically attached. This attribute is a function giving you hints on how to improve your prompt, and a diagram visualization tool. This tool uses the default model to operate.
277277

@@ -289,15 +289,18 @@ def find_occurence_of_a_word(word :str, text: str) -> int:
289289

290290
find_occurence_of_a_word("Hello", "Hello World Hello!")
291291

292-
find_occurence_of_a_word.__suggest__(find_occurence_of_a_word)
292+
print(suggest(multpily)) # to have the raw message
293+
print(multiply.diagram) # to have just the diagram
294+
295+
find_occurence_of_a_word.__suggest__(find_occurence_of_a_word) # same
293296
print(find_occurence_of_a_word.advanced)
294297
```
295298

296299
In this example, you can see that after calling the emulated function, we can call `suggest`, which takes as arguments the function object to which it is hooked. After that, we have four new attributes at our disposal:
297300
- `enhanced prompt`: It's a proposal to improve the function's prompt.
298301
- `review`: This is the analysis provided by the AI for its prompt improvement. Can be useful to understand its reasoning.
299302
- `advanced`: Similar to `enhanced prompt` but adds an iteration. The AI will then try to solve advanced problems according to context or other factors. Especially useful in the most complex cases.
300-
- `diagramm`: Gives a Mermaid diagram showing the stages of AI thinking. Useful if you want to try coding the function yourself.
303+
- `diagram`: Gives a Mermaid diagram showing the stages of AI thinking. Useful if you want to try coding the function yourself.
301304

302305
You can also retrieve the entire LLM response by storing the output of the `suggest` function.
303306

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "OpenHosta"
7-
version = "1.1.0-rc3"
7+
version = "1.1.0-rc4"
88
description = "Open-Source programming project IA integretion in developement environnement"
99
keywords = ["AI", "GPT", "Natural language", "Autommatic", "Easy"]
1010
authors = [

src/OpenHosta/OpenHosta.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
Model(model="gpt-4o", base_url="https://api.openai.com/v1/chat/completions")
55
)
66

7-
87
from .emulate import _exec_emulate
98
from . import config
109
from .thought import thought
1110
from .exec import HostaInjector
1211
from .example import example, load_examples, save_examples
12+
from .enhancer import suggest
1313

1414
emulate = HostaInjector(_exec_emulate)
1515

@@ -21,6 +21,7 @@
2121
"save_examples",
2222
"config",
2323
"Model",
24-
"DefaultManager"
24+
"DefaultManager",
25+
"suggest"
2526
)
2627

src/OpenHosta/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .OpenHosta import *
22

3-
__version__ = "1.1.0"
3+
__version__ = "1.1.0rc4"

src/OpenHosta/emulate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ def _exec_emulate(
8484
creativity=l_creativity,
8585
diversity=l_diversity,
8686
)
87-
87+
8888
if _obj is not None and inspect.isfunction(_obj):
8989
setattr(_obj, "_last_response", response.json())
9090

91-
9291
if response.status_code == 200:
9392
l_ret = model.request_handler(
9493
response, _function_return, _function_return_caller

src/OpenHosta/enhancer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import sys
3+
from typing import Callable
34

45
from .prompt import PromptMananger
56
from .config import DefaultManager
@@ -66,7 +67,7 @@ def _build_attributes(func: object, last_enh) -> int:
6667
func.enhanced_prompt = last_enh["enhanced"]
6768
func.review = last_enh["review"]
6869
func.advanced = last_enh["advanced"]
69-
func.diagramm = last_enh["mermaid"]
70+
func.diagram = last_enh["mermaid"]
7071
return 0
7172

7273

@@ -88,3 +89,12 @@ def enhance(func):
8889

8990
_build_attributes(func, last_enh)
9091
return last_enh
92+
93+
def suggest(func:Callable):
94+
if not callable(func):
95+
raise ValueError("Suggest arguments must be a callable.")
96+
try:
97+
full = func.__suggest__(func)
98+
except AttributeError:
99+
raise AttributeError(f"The “__suggest__” attribute is not defined. The function {func.__name__} might not have been called.")
100+
return full

src/OpenHosta/errors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ class ApiKeyError(RequestError):
2626
""" Raised when API key is missing or incorrect """
2727

2828
class FrameError(OhErrorMixin):
29-
""" Raised when the frame inspection fail """
30-
29+
""" Raised when the frame inspection fail """

0 commit comments

Comments
 (0)