OpenHosta 2.2.2__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {openhosta-2.2.2/src/OpenHosta.egg-info → openhosta-3.0.0}/PKG-INFO +86 -27
  2. openhosta-3.0.0/README.md +166 -0
  3. {openhosta-2.2.2 → openhosta-3.0.0}/pyproject.toml +3 -14
  4. openhosta-3.0.0/src/OpenHosta/__init__.py +44 -0
  5. openhosta-3.0.0/src/OpenHosta/asynchrone/__init__.py +12 -0
  6. openhosta-3.0.0/src/OpenHosta/core/analizer.py +172 -0
  7. openhosta-3.0.0/src/OpenHosta/core/config.py +116 -0
  8. openhosta-3.0.0/src/OpenHosta/core/inspection.py +159 -0
  9. openhosta-3.0.0/src/OpenHosta/core/logger.py +24 -0
  10. openhosta-3.0.0/src/OpenHosta/core/meta_prompt.py +148 -0
  11. openhosta-3.0.0/src/OpenHosta/core/pydantic_proxy.py +74 -0
  12. openhosta-3.0.0/src/OpenHosta/core/type_converter.py +322 -0
  13. openhosta-3.0.0/src/OpenHosta/exec/ask.py +65 -0
  14. openhosta-3.0.0/src/OpenHosta/exec/closure.py +121 -0
  15. openhosta-3.0.0/src/OpenHosta/exec/emulate.py +78 -0
  16. openhosta-3.0.0/src/OpenHosta/models/OpenAICompatible.py +166 -0
  17. openhosta-3.0.0/src/OpenHosta/models/__init__.py +8 -0
  18. openhosta-3.0.0/src/OpenHosta/models/base_model.py +72 -0
  19. openhosta-3.0.0/src/OpenHosta/pipelines/__init__.py +6 -0
  20. openhosta-3.0.0/src/OpenHosta/pipelines/simple_pipeline.py +249 -0
  21. openhosta-3.0.0/src/OpenHosta/semantics/operators.py +7 -0
  22. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta/utils/errors.py +0 -12
  23. openhosta-3.0.0/src/OpenHosta/utils/import_handler.py +20 -0
  24. {openhosta-2.2.2 → openhosta-3.0.0/src/OpenHosta.egg-info}/PKG-INFO +86 -27
  25. openhosta-3.0.0/src/OpenHosta.egg-info/SOURCES.txt +31 -0
  26. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta.egg-info/requires.txt +1 -12
  27. openhosta-2.2.2/README.md +0 -100
  28. openhosta-2.2.2/src/OpenHosta/OpenHosta.py +0 -55
  29. openhosta-2.2.2/src/OpenHosta/__init__.py +0 -3
  30. openhosta-2.2.2/src/OpenHosta/asynchrone/__init__.py +0 -20
  31. openhosta-2.2.2/src/OpenHosta/core/analizer.py +0 -308
  32. openhosta-2.2.2/src/OpenHosta/core/config.py +0 -93
  33. openhosta-2.2.2/src/OpenHosta/core/hosta_inspector.py +0 -410
  34. openhosta-2.2.2/src/OpenHosta/core/logger.py +0 -176
  35. openhosta-2.2.2/src/OpenHosta/core/memory.py +0 -32
  36. openhosta-2.2.2/src/OpenHosta/core/pydantic_stub.py +0 -72
  37. openhosta-2.2.2/src/OpenHosta/core/type_converter.py +0 -108
  38. openhosta-2.2.2/src/OpenHosta/exec/ask.py +0 -59
  39. openhosta-2.2.2/src/OpenHosta/exec/emulate.py +0 -168
  40. openhosta-2.2.2/src/OpenHosta/exec/example.py +0 -52
  41. openhosta-2.2.2/src/OpenHosta/exec/generate_data.py +0 -75
  42. openhosta-2.2.2/src/OpenHosta/exec/predict/dataset/__init__.py +0 -0
  43. openhosta-2.2.2/src/OpenHosta/exec/predict/dataset/dataset.py +0 -568
  44. openhosta-2.2.2/src/OpenHosta/exec/predict/dataset/oracle.py +0 -224
  45. openhosta-2.2.2/src/OpenHosta/exec/predict/dataset/sample_type.py +0 -78
  46. openhosta-2.2.2/src/OpenHosta/exec/predict/encoder/__init__.py +0 -0
  47. openhosta-2.2.2/src/OpenHosta/exec/predict/encoder/base_encoder.py +0 -13
  48. openhosta-2.2.2/src/OpenHosta/exec/predict/encoder/simple_encoder.py +0 -164
  49. openhosta-2.2.2/src/OpenHosta/exec/predict/model/__init__.py +0 -9
  50. openhosta-2.2.2/src/OpenHosta/exec/predict/model/builtins/__init__.py +0 -0
  51. openhosta-2.2.2/src/OpenHosta/exec/predict/model/builtins/algo_architecture.py +0 -87
  52. openhosta-2.2.2/src/OpenHosta/exec/predict/model/builtins/classification.py +0 -154
  53. openhosta-2.2.2/src/OpenHosta/exec/predict/model/builtins/linear_regression.py +0 -155
  54. openhosta-2.2.2/src/OpenHosta/exec/predict/model/hosta_model.py +0 -38
  55. openhosta-2.2.2/src/OpenHosta/exec/predict/model/model_provider.py +0 -58
  56. openhosta-2.2.2/src/OpenHosta/exec/predict/model/neural_network.py +0 -185
  57. openhosta-2.2.2/src/OpenHosta/exec/predict/model/neural_network_types.py +0 -154
  58. openhosta-2.2.2/src/OpenHosta/exec/predict/predict.py +0 -312
  59. openhosta-2.2.2/src/OpenHosta/exec/predict/predict_config.py +0 -61
  60. openhosta-2.2.2/src/OpenHosta/exec/predict/predict_memory.py +0 -98
  61. openhosta-2.2.2/src/OpenHosta/exec/predict/stubs.py +0 -74
  62. openhosta-2.2.2/src/OpenHosta/exec/thinkof.py +0 -165
  63. openhosta-2.2.2/src/OpenHosta/exec/thought.py +0 -8
  64. openhosta-2.2.2/src/OpenHosta/exec/use.py +0 -34
  65. openhosta-2.2.2/src/OpenHosta/models/OpenAICompatible.py +0 -210
  66. openhosta-2.2.2/src/OpenHosta/utils/__init__.py +0 -0
  67. openhosta-2.2.2/src/OpenHosta/utils/hosta_type.py +0 -29
  68. openhosta-2.2.2/src/OpenHosta/utils/import_handler.py +0 -21
  69. openhosta-2.2.2/src/OpenHosta/utils/meta_prompt.py +0 -130
  70. openhosta-2.2.2/src/OpenHosta/utils/progress_bar.py +0 -22
  71. openhosta-2.2.2/src/OpenHosta/utils/torch_nn_utils.py +0 -273
  72. openhosta-2.2.2/src/OpenHosta.egg-info/SOURCES.txt +0 -56
  73. {openhosta-2.2.2 → openhosta-3.0.0}/LICENSE +0 -0
  74. {openhosta-2.2.2 → openhosta-3.0.0}/setup.cfg +0 -0
  75. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta/core/__init__.py +0 -0
  76. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta/exec/__init__.py +0 -0
  77. {openhosta-2.2.2/src/OpenHosta/exec/predict → openhosta-3.0.0/src/OpenHosta/utils}/__init__.py +0 -0
  78. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta.egg-info/dependency_links.txt +0 -0
  79. {openhosta-2.2.2 → openhosta-3.0.0}/src/OpenHosta.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: OpenHosta
3
- Version: 2.2.2
3
+ Version: 3.0.0
4
4
  Summary: A lightweight library integrating LLM natively into Python
5
5
  Author: Léandre Ramos, Merlin Devillard, William Jolivet, Emmanuel Batt
6
6
  License: MIT License
@@ -56,12 +56,7 @@ License-File: LICENSE
56
56
  Requires-Dist: requests>=2.32.3
57
57
  Requires-Dist: typing_extensions>=4.12.2
58
58
  Requires-Dist: jinja2>=3.1.5
59
- Provides-Extra: all
60
- Requires-Dist: pydantic>=2.9.2; extra == "all"
61
- Requires-Dist: torch>=2.5.1; extra == "all"
62
- Requires-Dist: numpy>=2.1.3; extra == "all"
63
- Provides-Extra: pydantic
64
- Requires-Dist: pydantic>=2.8.2; extra == "pydantic"
59
+ Requires-Dist: python-dotenv>=1.1.1
65
60
  Provides-Extra: dev
66
61
  Requires-Dist: mypy>=1.13.0; extra == "dev"
67
62
  Requires-Dist: isort>=5.13.2; extra == "dev"
@@ -75,28 +70,75 @@ Requires-Dist: pytest-cov>=5.0.0; extra == "tests"
75
70
  Requires-Dist: pillow>=11.0.0; extra == "tests"
76
71
  Requires-Dist: pydantic>=2.8.2; extra == "tests"
77
72
  Requires-Dist: Flask>=3.0.3; extra == "tests"
78
- Provides-Extra: predict
79
- Requires-Dist: torch>=2.5.1; extra == "predict"
80
- Requires-Dist: numpy>=2.1.3; extra == "predict"
73
+ Dynamic: license-file
81
74
 
82
75
  # OpenHosta
83
- v2.2.2 - Open-Source Project
84
76
 
85
- <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>
86
- <br/>
87
- <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>
88
- <br/>
89
- <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>
90
- <br/>Or have a look at [regression tests files](https://github.com/hand-e-fr/OpenHosta/tree/main/tests/non-regression) for multiples exemples.
77
+ v3.0.0 - Integrates Inria Comments
91
78
 
92
- 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.
79
+ <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.
93
80
 
94
- **- The future of development is human -**
81
+ 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.
82
+
83
+ OpenHosta can run fully offline with a local model, or use a remote model via API key.
95
84
 
96
- 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.
85
+ **- The future of development is human -**
97
86
 
98
87
  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.
99
88
 
89
+ The simplest usage of OpenHosta is to allow semantic tests in your code, like this:
90
+
91
+ ```python
92
+ from OpenHosta import test
93
+
94
+ sentence = "You are an nice person."
95
+ # You shall try with this too:
96
+ # sentence = "You are a stupid #@!!~uk."
97
+
98
+ if test(f"this contains an insult: {sentence}"):
99
+ print("The sentence is considered an insult.")
100
+ else:
101
+ print("The sentence is not considered an insult.")
102
+
103
+ # The sentence is not considered an insult.
104
+ ```
105
+
106
+ 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).
107
+
108
+ ```python
109
+ from OpenHosta import emulate
110
+
111
+ from enum import Enum
112
+ class DocumentType(Enum):
113
+ OLD_BOOK = "old_book"
114
+ ARTICLE = "article"
115
+ REPORT = "report"
116
+ THESIS = "thesis"
117
+
118
+ from PIL.Image import Image, open
119
+
120
+ def classify_document(page:Image)->DocumentType:
121
+ """
122
+ This function classifies the document based on the content of the page givent in parameter.
123
+
124
+ Arguments:
125
+ page: An image of the document page to classify.
126
+
127
+ Returns:
128
+ DocumentType: The type of the document
129
+ """
130
+ return emulate()
131
+
132
+ import requests
133
+ url=r"https://www.inria.fr/sites/default/files/2024-01/A_outil_innovant_caracte%CC%81riser_plantes_1827x1026_bonnier-2.png"
134
+ img = open(requests.get(url, stream=True).raw)
135
+
136
+ result = classify_document(img)
137
+
138
+ result
139
+ # <DocumentType.OLD_BOOK: 'old_book'>
140
+ ```
141
+
100
142
  ## Table of Content
101
143
 
102
144
  - [OpenHosta](#openhosta)
@@ -121,17 +163,31 @@ pip install OpenHosta
121
163
  or
122
164
 
123
165
  ```sh
124
- git clone https://github.com/hand-e-fr/OpenHosta.git
166
+ pip install https://github.com/hand-e-fr/OpenHosta.git
125
167
  ```
126
168
 
127
- **See the full installation guide [here](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/installation.md)**
169
+ or for a specific branch
170
+
171
+ ```sh
172
+ pip install "git+https://github.com/hand-e-fr/OpenHosta.git@unstable" # for the latest unstable version
173
+ ```
174
+
175
+ **See the full [installation guide](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/installation.md)**
128
176
 
129
177
  ## Example
130
178
 
131
- ```python
132
- from OpenHosta import emulate, config
179
+ You shall set your API credentials either via environment variables or directly in your code.
180
+ For now we assume that you have an OpenAI API key and that you have set it in .env like this:
181
+
182
+ ```env
183
+ OPENHOSTA_DEFAULT_MODEL_NAME="gpt-4.1"
184
+ OPENHOSTA_DEFAULT_MODEL_API_KEY="put-your-api-key-here"
185
+ ```
133
186
 
134
- config.set_default_apiKey("put-your-api-key-here")
187
+ 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).
188
+
189
+ ```python
190
+ from OpenHosta import emulate
135
191
 
136
192
  def translate(text:str, language:str)->str:
137
193
  """
@@ -140,9 +196,12 @@ def translate(text:str, language:str)->str:
140
196
  return emulate()
141
197
 
142
198
  result = translate("Hello World!", "French")
199
+
143
200
  print(result)
201
+ # Bonjour le monde !
144
202
  ```
145
- You check OpenHosta's [documentation](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/doc.md) for more detailled informations or exemple
203
+
204
+ You check [OpenHosta's documentation](https://github.com/hand-e-fr/OpenHosta/blob/main/docs/doc.md) for more detailled informations or exemple
146
205
 
147
206
  ## Further information
148
207
 
@@ -0,0 +1,166 @@
1
+ # OpenHosta
2
+
3
+ v3.0.0 - Integrates Inria Comments
4
+
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.
6
+
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.
10
+
11
+ **- The future of development is human -**
12
+
13
+ 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.
14
+
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
+
68
+ ## Table of Content
69
+
70
+ - [OpenHosta](#openhosta)
71
+ - [Table of Content](#table-of-content)
72
+ - [How to install OpenHosta ?](#how-to-install-openhosta-)
73
+ - [Example](#example)
74
+ - [Further information](#further-information)
75
+ - [Contributing](#contributing)
76
+ - [License](#license)
77
+ - [Authors \& Contact](#authors--contact)
78
+
79
+ ---
80
+
81
+ ## How to install OpenHosta ?
82
+
83
+ You can install OpenHosta either via pip or via GitHub.
84
+
85
+ ```sh
86
+ pip install OpenHosta
87
+ ```
88
+
89
+ or
90
+
91
+ ```sh
92
+ pip install https://github.com/hand-e-fr/OpenHosta.git
93
+ ```
94
+
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)**
102
+
103
+ ## Example
104
+
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
+ ```
112
+
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
117
+
118
+ def translate(text:str, language:str)->str:
119
+ """
120
+ This function translates the text in the “text” parameter into the language specified in the “language” parameter.
121
+ """
122
+ return emulate()
123
+
124
+ result = translate("Hello World!", "French")
125
+
126
+ print(result)
127
+ # Bonjour le monde !
128
+ ```
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
131
+
132
+ ## Further information
133
+
134
+ ### Contributing
135
+
136
+ We warmly welcome contributions from the community. Whether you are an experienced developer or a beginner, your contributions are welcome.
137
+
138
+ If you wish to contribute to this project, please refer to our [Contribution Guide](https://github.com/hand-e-fr/OpenHosta/blob/main/CONTRIBUTING.md) and our [Code of Conduct](https://github.com/hand-e-fr/OpenHosta/blob/main/CODE_OF_CONDUCT.md).
139
+
140
+ Browse the existing [issues](https://github.com/hand-e-fr/OpenHosta/issues) to see if someone is already working on what you have in mind or to find contribution ideas.
141
+
142
+ ### License
143
+
144
+ 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:
145
+
146
+ - The text of the license below must be included in all copies or substantial portions of the software.
147
+
148
+ See the [LICENSE](https://github.com/hand-e-fr/OpenHosta/blob/main/LICENSE) file for more details.
149
+
150
+ ### Authors & Contact
151
+
152
+ For further questions or assistance, please refer to partner hand-e or contact us directly via github.
153
+
154
+ **Authors**:
155
+ - Emmanuel Batt: Manager and Coordinator, Founder of Hand-e
156
+ - William Jolivet: DevOps, SysAdmin
157
+ - Léandre Ramos: IA developer
158
+ - Merlin Devillard: UX designer, Product Owner
159
+
160
+ GitHub: https://github.com/hand-e-fr/OpenHosta
161
+
162
+ ---
163
+
164
+ Thank you for your interest in our project and your potential contributions!
165
+
166
+ **The OpenHosta Team**
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "OpenHosta"
7
- version = "2.2.2"
7
+ version = "3.0.0"
8
8
  description = "A lightweight library integrating LLM natively into Python"
9
9
  keywords = ["AI", "GPT", "Natural language", "Autommatic", "Easy"]
10
10
  authors = [
@@ -43,18 +43,11 @@ classifiers = [
43
43
  dependencies = [
44
44
  "requests>=2.32.3",
45
45
  "typing_extensions>=4.12.2",
46
- "jinja2>=3.1.5"
46
+ "jinja2>=3.1.5",
47
+ "python-dotenv>=1.1.1"
47
48
  ]
48
49
 
49
50
  [project.optional-dependencies]
50
- all = [
51
- "pydantic>=2.9.2",
52
- "torch>=2.5.1",
53
- "numpy>=2.1.3"
54
- ]
55
- pydantic = [
56
- "pydantic>=2.8.2"
57
- ]
58
51
  dev = [
59
52
  "mypy>=1.13.0",
60
53
  "isort>=5.13.2",
@@ -70,10 +63,6 @@ tests = [
70
63
  "pydantic>=2.8.2",
71
64
  "Flask>=3.0.3"
72
65
  ]
73
- predict = [
74
- "torch>=2.5.1",
75
- "numpy>=2.1.3"
76
- ]
77
66
 
78
67
  [project.urls]
79
68
  Homepage = "https://github.com/hand-e-fr/OpenHosta"
@@ -0,0 +1,44 @@
1
+ __version__ = "3.0.0"
2
+
3
+ from .core.config import config
4
+ from .core.logger import print_last_prompt, print_last_decoding
5
+ from .core.meta_prompt import MetaPrompt
6
+
7
+ from .exec.ask import ask, ask_async
8
+ from .exec.emulate import emulate, emulate_async
9
+ from .exec.closure import closure, closure_async
10
+ from .semantics.operators import test, test_async
11
+
12
+ from .models import OpenAICompatibleModel as Model
13
+ from .models import OpenAICompatibleModel
14
+
15
+ from .core.config import reload_dotenv
16
+
17
+ from .pipelines import Pipeline, OneTurnConversationPipeline
18
+
19
+ import os
20
+
21
+ DefaultModel = config.DefaultModel
22
+ DefaultPipeline = config.DefaultPipeline
23
+
24
+ all = (
25
+ "ask",
26
+ "ask_async",
27
+ "emulate",
28
+ "emulate_async",
29
+ "closure",
30
+ "closure_async",
31
+ "test",
32
+ "test_async",
33
+ "config",
34
+ "reload_dotenv",
35
+ "Model",
36
+ "DefaultModel",
37
+ "DefaultPipeline",
38
+ "OpenAICompatibleModel",
39
+ "MetaPrompt",
40
+ "print_last_prompt",
41
+ "print_last_decoding",
42
+ "Pipeline",
43
+ "OneTurnConversationPipeline"
44
+ )
@@ -0,0 +1,12 @@
1
+ from ..exec.ask import ask_async as ask
2
+ from ..exec.emulate import emulate_async as emulate
3
+ from ..exec.closure import closure_async as closure
4
+ from ..semantics.operators import test_async as test
5
+
6
+
7
+ all = (
8
+ "ask",
9
+ "emulate",
10
+ "closure",
11
+ "test",
12
+ )
@@ -0,0 +1,172 @@
1
+
2
+ import inspect
3
+ from ..models import ModelCapabilities
4
+ from ..core.type_converter import nice_type_name, describe_type_as_python, describe_type_as_schema, BASIC_TYPES
5
+
6
+ def hosta_analyze_update(frame, inspection):
7
+ analyse = inspection["analyse"]
8
+ new_analyse = {
9
+ "name": analyse["name"],
10
+ "args": [],
11
+ "type": analyse["type"],
12
+ "doc": analyse["doc"]
13
+ }
14
+ args_info = inspect.getargvalues(frame)
15
+ new_analyse["args"] = [{"name":a["name"], "value":args_info.locals[a["name"]], "type":a["type"]} for a in analyse["args"]]
16
+ return new_analyse
17
+
18
+ def hosta_analyze(frame=None, function_pointer=None):
19
+ sig = inspect.signature(function_pointer)
20
+
21
+ if frame is None:
22
+ result_args_value_table = []
23
+ else:
24
+ args_info = inspect.getargvalues(frame)
25
+
26
+ result_args_value_table = [{
27
+ "name":arg,
28
+ "value": args_info.locals[arg],
29
+ "type":sig.parameters[arg].annotation} for arg in args_info.args]
30
+
31
+ result_function_name = function_pointer.__name__
32
+ result_return_type = sig.return_annotation
33
+ result_docstring = function_pointer.__doc__
34
+
35
+ return {
36
+ "name": result_function_name,
37
+ "args": result_args_value_table,
38
+ "type": result_return_type,
39
+ "doc": result_docstring
40
+ }
41
+
42
+
43
+ def encode_function(analyse, model_capability=set([ModelCapabilities.TEXT2TEXT])):
44
+ """
45
+ Encode the function signature and docstring into a format suitable for the model.
46
+ """
47
+ snippets = {}
48
+ snippets |= encode_function_documentation(analyse)
49
+ snippets |= encode_function_parameter_types(analyse)
50
+ snippets |= encode_function_parameter_values(analyse)
51
+ snippets |= encode_function_parameter_names(analyse)
52
+ snippets |= encode_function_return_type(analyse)
53
+ snippets |= encode_function_return_type_definition(analyse)
54
+
55
+ return snippets
56
+
57
+ def encode_function_documentation(analyse):
58
+ return {
59
+ "function_name" : analyse["name"],
60
+ "function_doc" : analyse["doc"],
61
+ }
62
+
63
+ def encode_function_parameter_types(analyse):
64
+
65
+ # Types of the arguments when type definition is too long
66
+ # to be included inline in the function call
67
+ json_schema_types_definition_list = {}
68
+
69
+ # Types of the arguments when type definition is too long
70
+ # to be included inline in the function call
71
+ python_types_definition_list = {}
72
+
73
+ for a in analyse["args"]:
74
+ arg_type = a["type"]
75
+ if arg_type is inspect._empty or arg_type in BASIC_TYPES:
76
+ # Basic types are assumed to be known by the model
77
+ # and are not included in the prompt
78
+ pass
79
+ else:
80
+ specifig_type_doc = describe_type_as_python(arg_type)
81
+ if not specifig_type_doc is None:
82
+ python_types_definition_list[nice_type_name(arg_type)] = specifig_type_doc
83
+
84
+ specifig_type_json = describe_type_as_schema(arg_type)
85
+ if not specifig_type_json is None:
86
+ json_schema_types_definition_list[nice_type_name(arg_type)] = specifig_type_json
87
+
88
+ return {
89
+ "python_type_definition_dict": "\n".join([f"```python\n# definition of type {k}:\n{v}\n```" for k,v in python_types_definition_list.items()]),
90
+ "json_schema_type_definition_dict": "\n\n".join([f"# JSON Schema of type {k}:\n```json\n{v}\n```" for k,v in json_schema_types_definition_list.items()]),
91
+ }
92
+
93
+ def encode_function_parameter_values(analyse):
94
+
95
+ args = analyse["args"]
96
+
97
+ # Vaiable value definition when content is too long
98
+ # to be included inline in the function call
99
+ variable_definition_list = []
100
+
101
+ # Call arguments for inline function call
102
+ call_string_list = []
103
+
104
+ for a in args:
105
+ call_arg, value, arg_type = a["name"], a["value"], a["type"]
106
+
107
+ # Place long variables outside function definition.
108
+ # math.pi is 17 char, I decide to cut at 20
109
+ str_value = repr(value)
110
+ if len(str_value) > 20:
111
+ try:
112
+ import PIL
113
+ if isinstance(value, PIL.Image.Image):
114
+ # Add a comment to explain that the image content is in the message
115
+ str_value += f" # the real content of `{call_arg}` image is provided as an image in the message"
116
+ except:
117
+ # PIL is not available. It cannot be an image
118
+ pass
119
+ variable_definition_list += [call_arg+"="+str_value+"\n"]
120
+ else:
121
+ # We do not show default values as this could contradict values from call
122
+ # call_arg += " = "+str_value
123
+ call_arg += " = "+str_value
124
+
125
+ call_string_list += [call_arg]
126
+
127
+ return {
128
+ "variables_initialization":"\n\n".join(variable_definition_list),
129
+ "function_call_arguments":", ".join(call_string_list),
130
+ }
131
+
132
+ def encode_function_parameter_names(analyse):
133
+
134
+ args = analyse["args"]
135
+
136
+ # Inline argument names and typing if short enough
137
+ inline_string_list = []
138
+
139
+ # Vaiable value definition when content is too long
140
+ # to be included inline in the function call
141
+ variable_definition_list = []
142
+
143
+ for a in args:
144
+ str_arg, arg_type = a["name"], a["type"]
145
+ if arg_type is inspect._empty:
146
+ pass
147
+ else:
148
+ str_arg += ": "+nice_type_name(arg_type)
149
+
150
+ inline_string_list += [str_arg]
151
+
152
+
153
+ return {
154
+ "function_return_type": " -> " + nice_type_name(analyse["type"]) if analyse["type"] else "",
155
+ "function_args":", ".join(inline_string_list),
156
+ "function_inline_variable_declaration":"\n".join(variable_definition_list),
157
+ }
158
+
159
+
160
+ def encode_function_return_type(analyse):
161
+ return {
162
+ "function_return_type": analyse["type"],
163
+ "function_return_type_name": nice_type_name(analyse["type"]),
164
+ }
165
+
166
+ def encode_function_return_type_definition(analyse):
167
+
168
+ return {
169
+ "function_return_as_python_type" : describe_type_as_python(analyse["type"]),
170
+ "function_return_as_json_schema" : describe_type_as_schema(analyse["type"]),
171
+ }
172
+