gibson-cli 0.1.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 (112) hide show
  1. gibson_cli-0.1.0/.gitignore +9 -0
  2. gibson_cli-0.1.0/.pre-commit-config.yaml +21 -0
  3. gibson_cli-0.1.0/PKG-INFO +306 -0
  4. gibson_cli-0.1.0/README.md +293 -0
  5. gibson_cli-0.1.0/api/BaseApi.py +45 -0
  6. gibson_cli-0.1.0/api/Cli.py +248 -0
  7. gibson_cli-0.1.0/bin/gibson.py +16 -0
  8. gibson_cli-0.1.0/command/Api.py +31 -0
  9. gibson_cli-0.1.0/command/Base.py +28 -0
  10. gibson_cli-0.1.0/command/BaseCommand.py +26 -0
  11. gibson_cli-0.1.0/command/Build.py +69 -0
  12. gibson_cli-0.1.0/command/Code.py +198 -0
  13. gibson_cli-0.1.0/command/Conf.py +74 -0
  14. gibson_cli-0.1.0/command/Count.py +35 -0
  15. gibson_cli-0.1.0/command/Dev.py +121 -0
  16. gibson_cli-0.1.0/command/Forget.py +34 -0
  17. gibson_cli-0.1.0/command/Import.py +109 -0
  18. gibson_cli-0.1.0/command/List.py +61 -0
  19. gibson_cli-0.1.0/command/Merge.py +35 -0
  20. gibson_cli-0.1.0/command/Model.py +42 -0
  21. gibson_cli-0.1.0/command/Models.py +31 -0
  22. gibson_cli-0.1.0/command/Modify.py +43 -0
  23. gibson_cli-0.1.0/command/Module.py +42 -0
  24. gibson_cli-0.1.0/command/New.py +38 -0
  25. gibson_cli-0.1.0/command/OpenApi.py +141 -0
  26. gibson_cli-0.1.0/command/Question.py +105 -0
  27. gibson_cli-0.1.0/command/Remove.py +80 -0
  28. gibson_cli-0.1.0/command/Rename.py +71 -0
  29. gibson_cli-0.1.0/command/Rewrite.py +107 -0
  30. gibson_cli-0.1.0/command/Schema.py +42 -0
  31. gibson_cli-0.1.0/command/Schemas.py +31 -0
  32. gibson_cli-0.1.0/command/Show.py +37 -0
  33. gibson_cli-0.1.0/command/Test.py +42 -0
  34. gibson_cli-0.1.0/command/Tests.py +31 -0
  35. gibson_cli-0.1.0/command/Tree.py +92 -0
  36. gibson_cli-0.1.0/command/WarGames.py +35 -0
  37. gibson_cli-0.1.0/command/auth/Auth.py +25 -0
  38. gibson_cli-0.1.0/command/auth/Login.py +17 -0
  39. gibson_cli-0.1.0/command/auth/Logout.py +7 -0
  40. gibson_cli-0.1.0/command/tests/test_command_BaseCommand.py +10 -0
  41. gibson_cli-0.1.0/command/tests/test_command_Conf.py +19 -0
  42. gibson_cli-0.1.0/conf/Api.py +3 -0
  43. gibson_cli-0.1.0/conf/Code.py +9 -0
  44. gibson_cli-0.1.0/conf/Custom.py +4 -0
  45. gibson_cli-0.1.0/conf/Datastore.py +4 -0
  46. gibson_cli-0.1.0/conf/Dependencies.py +24 -0
  47. gibson_cli-0.1.0/conf/Dev.py +15 -0
  48. gibson_cli-0.1.0/conf/Frameworks.py +7 -0
  49. gibson_cli-0.1.0/conf/Modeler.py +3 -0
  50. gibson_cli-0.1.0/conf/Paths.py +10 -0
  51. gibson_cli-0.1.0/conf/Platform.py +16 -0
  52. gibson_cli-0.1.0/conf/Project.py +18 -0
  53. gibson_cli-0.1.0/conf/Version.py +2 -0
  54. gibson_cli-0.1.0/conf/dev/Api.py +5 -0
  55. gibson_cli-0.1.0/conf/dev/Base.py +3 -0
  56. gibson_cli-0.1.0/conf/dev/Model.py +3 -0
  57. gibson_cli-0.1.0/conf/dev/Schema.py +3 -0
  58. gibson_cli-0.1.0/conf/tests/test_conf_Dependencies.py +5 -0
  59. gibson_cli-0.1.0/conf/tests/test_conf_Platform.py +7 -0
  60. gibson_cli-0.1.0/core/CommandRouter.py +249 -0
  61. gibson_cli-0.1.0/core/Configuration.py +418 -0
  62. gibson_cli-0.1.0/core/Conversation.py +270 -0
  63. gibson_cli-0.1.0/core/Env.py +12 -0
  64. gibson_cli-0.1.0/core/Memory.py +148 -0
  65. gibson_cli-0.1.0/core/TimeKeeper.py +12 -0
  66. gibson_cli-0.1.0/core/utils.py +19 -0
  67. gibson_cli-0.1.0/data/default-ref-table.tmpl +4 -0
  68. gibson_cli-0.1.0/data/default-table.tmpl +6 -0
  69. gibson_cli-0.1.0/db/TableExceptions.py +6 -0
  70. gibson_cli-0.1.0/db/tests/test_db_TableExceptions.py +9 -0
  71. gibson_cli-0.1.0/dev/Dev.py +92 -0
  72. gibson_cli-0.1.0/display/Header.py +6 -0
  73. gibson_cli-0.1.0/display/WorkspaceFooter.py +10 -0
  74. gibson_cli-0.1.0/display/WorkspaceHeader.py +8 -0
  75. gibson_cli-0.1.0/display/tests/test_display_Header.py +9 -0
  76. gibson_cli-0.1.0/display/tests/test_display_WorkspaceFooter.py +9 -0
  77. gibson_cli-0.1.0/display/tests/test_display_WorkspaceHeader.py +8 -0
  78. gibson_cli-0.1.0/gibson_cli.egg-info/PKG-INFO +306 -0
  79. gibson_cli-0.1.0/gibson_cli.egg-info/SOURCES.txt +110 -0
  80. gibson_cli-0.1.0/gibson_cli.egg-info/dependency_links.txt +1 -0
  81. gibson_cli-0.1.0/gibson_cli.egg-info/entry_points.txt +2 -0
  82. gibson_cli-0.1.0/gibson_cli.egg-info/top_level.txt +14 -0
  83. gibson_cli-0.1.0/lang/Python.py +57 -0
  84. gibson_cli-0.1.0/lang/tests/test_lang_Python.py +70 -0
  85. gibson_cli-0.1.0/pyproject.toml +41 -0
  86. gibson_cli-0.1.0/requirements.txt +51 -0
  87. gibson_cli-0.1.0/services/auth/Server.py +75 -0
  88. gibson_cli-0.1.0/services/code/context/schema/DataDictionary.py +12 -0
  89. gibson_cli-0.1.0/services/code/context/schema/EntityKeys.py +49 -0
  90. gibson_cli-0.1.0/services/code/context/schema/Manager.py +28 -0
  91. gibson_cli-0.1.0/services/code/context/schema/tests/test_code_context_schema_DataDictionary.py +8 -0
  92. gibson_cli-0.1.0/services/code/context/schema/tests/test_code_context_schema_EntityKeys.py +52 -0
  93. gibson_cli-0.1.0/services/code/context/schema/tests/test_code_context_schema_Manager.py +34 -0
  94. gibson_cli-0.1.0/services/code/customization/Authenticator.py +51 -0
  95. gibson_cli-0.1.0/services/code/customization/BaseCustomization.py +12 -0
  96. gibson_cli-0.1.0/services/code/customization/CustomizationManager.py +20 -0
  97. gibson_cli-0.1.0/services/code/customization/tests/test_code_customization_Authenticator.py +53 -0
  98. gibson_cli-0.1.0/services/code/customization/tests/test_code_customization_BaseCustomization.py +14 -0
  99. gibson_cli-0.1.0/setup.cfg +4 -0
  100. gibson_cli-0.1.0/structure/Entity.py +115 -0
  101. gibson_cli-0.1.0/structure/constraints/ReferenceConstraint.py +36 -0
  102. gibson_cli-0.1.0/structure/keys/ForeignKey.py +41 -0
  103. gibson_cli-0.1.0/structure/keys/Index.py +64 -0
  104. gibson_cli-0.1.0/structure/keys/IndexAttribute.py +14 -0
  105. gibson_cli-0.1.0/structure/keys/tests/test_ForeignKey.py +80 -0
  106. gibson_cli-0.1.0/structure/keys/tests/test_Index.py +98 -0
  107. gibson_cli-0.1.0/structure/keys/tests/test_IndexAttribute.py +17 -0
  108. gibson_cli-0.1.0/structure/testing.py +194 -0
  109. gibson_cli-0.1.0/structure/tests/test_Entity.py +107 -0
  110. gibson_cli-0.1.0/tests/test_Env.py +14 -0
  111. gibson_cli-0.1.0/tests/test_Memory.py +89 -0
  112. gibson_cli-0.1.0/tests/test_utils.py +20 -0
@@ -0,0 +1,9 @@
1
+ *.swp
2
+ __pycache__
3
+ .pytest_cache
4
+ .DS_Store
5
+ .idea
6
+ .tox
7
+ *.egg-info
8
+ venv
9
+ dist
@@ -0,0 +1,21 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v2.3.0
4
+ hooks:
5
+ - id: check-yaml
6
+ - id: end-of-file-fixer
7
+ - id: trailing-whitespace
8
+ - repo: https://github.com/psf/black
9
+ rev: 22.3.0
10
+ hooks:
11
+ - id: black
12
+ args:
13
+ - --config=project/pyproject.toml
14
+ - repo: https://github.com/pycqa/isort
15
+ rev: 5.12.0
16
+ hooks:
17
+ - id: isort
18
+ args:
19
+ - --profile
20
+ - black
21
+ - --filter-files
@@ -0,0 +1,306 @@
1
+ Metadata-Version: 2.1
2
+ Name: gibson-cli
3
+ Version: 0.1.0
4
+ Summary: Gibson Command Line Interface
5
+ Author-email: GibsonAI <noc@gibsonai.com>
6
+ Project-URL: Homepage, https://gibsonai.com/
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+
14
+ # Gibson CLI
15
+
16
+ v.0.1.0
17
+
18
+ ## Prerequisites
19
+
20
+ Gibson currently works on projects that use Python 3.9 or greater, MySQL, SQLAlchemy, Pydantic, Alembic, FastAPI and pytest. It is capable of building a complete application, from database to API end points, using these frameworks. Future enhancements of Gibson will include support for more languages and frameworks.
21
+
22
+ Portions of the Gibson backend code are written by Gibson. So far, versus a human developer, it has coded 66% of the software and did so in seconds. To get started, read the instructions here.
23
+
24
+ ## Installation
25
+
26
+ - Clone this repository somewhere in your environment
27
+ - Modify your `PYTHONPATH` to include a reference to the top level directory here
28
+ - `pip3 install -r requirements.txt`
29
+ - Add the `bin/` directory to your `PATH`
30
+
31
+ ## Key Terms
32
+
33
+ - Dev Mode
34
+ - Turn dev mode on to have Gibson write code for you as you execute commands.
35
+
36
+ - Entity | Entities
37
+ - Synonymous with a table name or data structure.
38
+
39
+ - Memory
40
+ - There are two types of memory: stored (long term) and last (the last action taken).
41
+
42
+ - Merge
43
+ - Merge the entities in the last memory into the stored memory.
44
+
45
+ ## Memory Concepts
46
+
47
+ There are two types of memory maintained by the Gibson CLI:
48
+
49
+ - `stored` (long term)
50
+ - `last` (short term)
51
+
52
+ When you import a datastore or API project into Gibson it stores the schema and all of its entities in stored memory. Stored memory is long term. It contains a copy of your database schema and represents the currently stable version of it.
53
+
54
+ Each time you ask Gibson to do something that results in a new or modified entity it will store it in last memory. Any time you ask the CLI to perform a coding task it will prefer last memory first, then stored memory.
55
+
56
+ Let's consider a more concrete example. You imported your datastore into the CLI and one of the tables is called "user". You execute:
57
+
58
+ `gibson modify user I want to add nickname`
59
+
60
+ So Gibson creates a new version of the user table containing a nickname column. This new table is stored in last memory. If you execute:
61
+
62
+ `gibson models`
63
+
64
+ The CLI will write the code for what is sitting in last memory.
65
+
66
+ This means you can make changes, try things out and decide if you want to make the changes permanent before merging the changes from last to stored. You can easily forget the last changes you made by executing:
67
+
68
+ `gibson forget last`
69
+
70
+ When you're ready to commit, just execute:
71
+
72
+ `gibson merge`
73
+
74
+ Everything in last will be moved to stored and last will be forgotten. Finally, if you want Gibson to recreate your database schema with all the recent changes, just execute:
75
+
76
+ `gibson build datastore`
77
+
78
+ Just note, build will first drop all of the tables in the datastore then recreate the database from scratch.
79
+
80
+ ## Logging in
81
+
82
+ Run `gibson auth login` to login to Gibson with your Google account.
83
+
84
+ ## Acquiring an API Key
85
+
86
+ While in beta, you have to acquire an API manually:
87
+
88
+ - Go to <https://staging.gibsonai.com/>.
89
+ - Chat with Gibson and create a new project.
90
+ - When your project is complete Gibson will email you the API key.
91
+ - gibson conf api::key [API key]
92
+
93
+ ## Usage
94
+
95
+ The main command is located in `bin/gibson`. Executing this command with no parameters will provide a help style menu to guide you.
96
+
97
+ ## Configuration
98
+
99
+ All of Gibson's configuration files and caches are stored in `$HOME/.gibson`. Use `gibson conf` for updating the configuration and `gibson forget` for clearing caches.
100
+
101
+ ### For Windows Users
102
+
103
+ - Make sure that you have an environment variable called HOME set. Gibson will store its configuration files and caches in this directory. We recommend you keep this directory outside of any repository to which you might be committing.
104
+ - To execute the `gibson` command, follow these instructions:
105
+ - Assuming the gibson executable is in `c:\Users\\[me]\projects\gibson\bin`
106
+ - Run `python c:\Users\\[me]\projects\gibson\bin\gibson`
107
+
108
+ ## Editor Integration
109
+
110
+ ### vim
111
+
112
+ - Make sure the `gibson` command is in your path by editing the `PATH` environment variable
113
+ - Edit `~/.vimrc`
114
+ - Add the following:
115
+ - `:command! -nargs=* Gibson r ! gibson <args>`
116
+ - Open a file and execute commands:
117
+ - `:Gibson module abc`
118
+ - `:Gibson models`
119
+ - `:Gibson schemas`
120
+
121
+ ## Currently Supported Software
122
+
123
+ - Python 3.9 or greater
124
+ - MySQL
125
+ - SQLAlchemy
126
+ - Pydantic
127
+ - Alembic
128
+ - FastAPI
129
+ - pytest
130
+
131
+ More languages and frameworks are in active development. If you do not see a version that you need let us know and we will get on it.
132
+
133
+ ## Coming Very Soon
134
+
135
+ - pytest based unit tests for all of the code Gibson writes.
136
+ - We know this is critical for Gibson to prove that its code is production-grade and bug free. As a development team, we need this too. It is coming in short order.
137
+ - Enhanced AI commands at your finger tips with code output and scratch storage.
138
+ - [DONE] See "Asking Gibson Questions With Context"
139
+ - Context aware coding from your Github repository.
140
+ - gibson scan
141
+ - AI based feedback directly to Gibson's creator:
142
+ - `gibson tell mike [hopefully nice things]`
143
+ - e.g. `gibson tell mike we need support for postgres`
144
+ - or, `gibson tell mike to hire me, I want to work on gibson`
145
+ - Significant data modeling improvements.
146
+ - The ability to integrate and download Function code using `gibson`.
147
+ - Along with a number of new Functions.
148
+ - Full FastAPI coding including module and entity specific dispatchers.
149
+
150
+ ## Detailed How-To
151
+
152
+ ### First Step
153
+
154
+ - Just run `gibson`. He will say hello and walk you through set up.
155
+
156
+ ### Configuring Your API Key
157
+
158
+ `gibson conf api::key [API key]`
159
+
160
+ ### Configuring Your Datastore
161
+
162
+ `gibson conf datastore::uri mysql+pymysql://[user]:[password]@[host]/[database name]`
163
+
164
+ Note: Gibson currently only supports MySQL. Let us know if you need something else.
165
+
166
+ ### Turning On Dev Mode
167
+
168
+ `gibson dev on`
169
+
170
+ - We suggest you turn dev mode on and leave it on. With it enabled, Gibson will act like your coworker and write code as you execute commands.
171
+
172
+ - You will need to provide 3 paths: `base` (where you want project base code to go), `model` (where you want SQLAlchemy models to go) and `schema` (where you want Pydantic schemas to go).
173
+
174
+ ### Importing Your Datastore
175
+
176
+ `gibson import datastore`
177
+
178
+ - This will make Gibson's stored memory aware of all of your datastore objects.
179
+ - `gibson import datastore .. dev`
180
+ - In addition to making Gibson aware, this will write all of the base, model and schema code for you.
181
+
182
+ ### Configuring a Custom BaseModel
183
+
184
+ You may be using a custom SQLAlchemy BaseModel and you do not want Gibson to use the one it has written.
185
+
186
+ ```sh
187
+ gibson conf code::custom::model::class [class name]
188
+ gibson conf code::custom::path [import path]
189
+ ```
190
+
191
+ For example, you might provide class name = `MyBaseModel` and import path = `project.model.MyBaseModel`
192
+
193
+ ### Writing the Base Code
194
+
195
+ `gibson base`
196
+
197
+ ### Writing the Code for a Single Model
198
+
199
+ `gibson model [table name]`
200
+
201
+ ### Writing the Code for a Single Schema
202
+
203
+ `gibson schema [table name]`
204
+
205
+ ### Writing the Code for All Models
206
+
207
+ `gibson models`
208
+
209
+ ### Writing the Code for All Schemas
210
+
211
+ `gibson schemas`
212
+
213
+ ### Adding a New Module to the Software Using AI
214
+
215
+ - gibson module [module name]
216
+ - e.g. gibson module user
217
+ - Gibson will display the SQL tables it has generated as a result of your request. It will store these entities in its last memory.
218
+ - gibson models
219
+ - This will write the code for the entities it just created.
220
+ - gibson merge
221
+ - This will merge the new entities into your project.
222
+ - Note, at the moment Gibson does not build the tables into your datastore.
223
+
224
+ ### Making Changes to the Software Using AI
225
+
226
+ - `gibson modify [table name] [natural language request]`
227
+ - e.g. `gibson modify my_table I want to add a new column called name and remove all of the columns related to email`
228
+ - Gibson will display the modified SQL table and store it in its last memory.
229
+ - `gibson models`
230
+ - This will write the code for the modified entity.
231
+ - `gibson merge`
232
+ - This will merge the modified entity into your project.
233
+ - Note, at the moment Gibson does not build the modified table into your datastore.
234
+
235
+ ### Forgetting Things Stored in Memory
236
+
237
+ - `gibson forget stored`
238
+ - `gibson forget last`
239
+ - `gibson forget all`
240
+
241
+ ### Building All of the Entities in Stored Memory into the Datastore
242
+
243
+ `gibson build`
244
+
245
+ ### Showing an Entity that is Stored in Memory
246
+
247
+ `gibson show [entity name]`
248
+
249
+ ### Building a Project End-to-End Using AI
250
+
251
+ - Go to <https://staging.gibsonai.com/>.
252
+ - Chat with Gibson and create a new project.
253
+ - When your project is complete Gibson will email you the API key.
254
+ - `gibson conf api::key [API key]`
255
+ - `gibson import api .. dev`
256
+ - Magic, no?
257
+
258
+ ### Integrating a Model into Your Code
259
+
260
+ Gibson creates base-level SQLAlchemy models. To integrate them just do this:
261
+
262
+ ```py
263
+ from my_project.gibsonai.model.Module import ModuleBase
264
+
265
+ class MyModule(ModuleBase):
266
+ pass
267
+ ```
268
+
269
+ - When you need to add custom business logic to the model, just modify your version of the model:
270
+
271
+ ```py
272
+ from my_project.gibsonai.model.Module import ModuleBase
273
+
274
+ class MyModule(ModuleBase):
275
+ def my_custom_business_logic(self):
276
+ return 1 + 1
277
+ ```
278
+
279
+ We strongly suggest you do not reference the base-level SQLAlchemy models directly. By sub-classing you won't have to refactor your code if you decide to add custom code.
280
+
281
+ ### Integrating a Schema into Your Code
282
+
283
+ At the moment, just refer to the base-level schema directly.
284
+
285
+ ### Migrating Your Software from PHP to Python
286
+
287
+ - Configure your datastore.
288
+ - Turn on Dev Mode.
289
+ - `gibson import datastore .. dev`
290
+ - 70% of your code is written, customize the remaining.
291
+
292
+ ### Asking Gibson Questions With Context
293
+
294
+ - `gibson ? [natural language request]`
295
+ - Your natural language request can include:
296
+ - `file://[full path]` to import a file from the filesystem
297
+ - `py://[import]` to import a file from `PYTHONPATH`
298
+ - `sql://[entity name]` to import the SQL
299
+ - For example:
300
+ - `gibson ? format file:///Users/me/file.py for PEP8`
301
+ - `gibson ? code review py://user.modules.User`
302
+ - `gibson ? add nickname to sql://user`
303
+ - When using `sql://`, any entities that are created as part of Gibson's response will be transferred into Gibson's last memory allowing you to execute a question, create a new entity and have Gibson immediately create a model or schema from it.
304
+ - e.g. `gibson ? add nickname to sql://user`
305
+ - `gibson model`
306
+ - Important note, `gibson ?` may cause your shell to incorrectly interpret the question mark. If it does, you can use `gibson q` instead (just replace the question mark with the letter `q`).
@@ -0,0 +1,293 @@
1
+ # Gibson CLI
2
+
3
+ v.0.1.0
4
+
5
+ ## Prerequisites
6
+
7
+ Gibson currently works on projects that use Python 3.9 or greater, MySQL, SQLAlchemy, Pydantic, Alembic, FastAPI and pytest. It is capable of building a complete application, from database to API end points, using these frameworks. Future enhancements of Gibson will include support for more languages and frameworks.
8
+
9
+ Portions of the Gibson backend code are written by Gibson. So far, versus a human developer, it has coded 66% of the software and did so in seconds. To get started, read the instructions here.
10
+
11
+ ## Installation
12
+
13
+ - Clone this repository somewhere in your environment
14
+ - Modify your `PYTHONPATH` to include a reference to the top level directory here
15
+ - `pip3 install -r requirements.txt`
16
+ - Add the `bin/` directory to your `PATH`
17
+
18
+ ## Key Terms
19
+
20
+ - Dev Mode
21
+ - Turn dev mode on to have Gibson write code for you as you execute commands.
22
+
23
+ - Entity | Entities
24
+ - Synonymous with a table name or data structure.
25
+
26
+ - Memory
27
+ - There are two types of memory: stored (long term) and last (the last action taken).
28
+
29
+ - Merge
30
+ - Merge the entities in the last memory into the stored memory.
31
+
32
+ ## Memory Concepts
33
+
34
+ There are two types of memory maintained by the Gibson CLI:
35
+
36
+ - `stored` (long term)
37
+ - `last` (short term)
38
+
39
+ When you import a datastore or API project into Gibson it stores the schema and all of its entities in stored memory. Stored memory is long term. It contains a copy of your database schema and represents the currently stable version of it.
40
+
41
+ Each time you ask Gibson to do something that results in a new or modified entity it will store it in last memory. Any time you ask the CLI to perform a coding task it will prefer last memory first, then stored memory.
42
+
43
+ Let's consider a more concrete example. You imported your datastore into the CLI and one of the tables is called "user". You execute:
44
+
45
+ `gibson modify user I want to add nickname`
46
+
47
+ So Gibson creates a new version of the user table containing a nickname column. This new table is stored in last memory. If you execute:
48
+
49
+ `gibson models`
50
+
51
+ The CLI will write the code for what is sitting in last memory.
52
+
53
+ This means you can make changes, try things out and decide if you want to make the changes permanent before merging the changes from last to stored. You can easily forget the last changes you made by executing:
54
+
55
+ `gibson forget last`
56
+
57
+ When you're ready to commit, just execute:
58
+
59
+ `gibson merge`
60
+
61
+ Everything in last will be moved to stored and last will be forgotten. Finally, if you want Gibson to recreate your database schema with all the recent changes, just execute:
62
+
63
+ `gibson build datastore`
64
+
65
+ Just note, build will first drop all of the tables in the datastore then recreate the database from scratch.
66
+
67
+ ## Logging in
68
+
69
+ Run `gibson auth login` to login to Gibson with your Google account.
70
+
71
+ ## Acquiring an API Key
72
+
73
+ While in beta, you have to acquire an API manually:
74
+
75
+ - Go to <https://staging.gibsonai.com/>.
76
+ - Chat with Gibson and create a new project.
77
+ - When your project is complete Gibson will email you the API key.
78
+ - gibson conf api::key [API key]
79
+
80
+ ## Usage
81
+
82
+ The main command is located in `bin/gibson`. Executing this command with no parameters will provide a help style menu to guide you.
83
+
84
+ ## Configuration
85
+
86
+ All of Gibson's configuration files and caches are stored in `$HOME/.gibson`. Use `gibson conf` for updating the configuration and `gibson forget` for clearing caches.
87
+
88
+ ### For Windows Users
89
+
90
+ - Make sure that you have an environment variable called HOME set. Gibson will store its configuration files and caches in this directory. We recommend you keep this directory outside of any repository to which you might be committing.
91
+ - To execute the `gibson` command, follow these instructions:
92
+ - Assuming the gibson executable is in `c:\Users\\[me]\projects\gibson\bin`
93
+ - Run `python c:\Users\\[me]\projects\gibson\bin\gibson`
94
+
95
+ ## Editor Integration
96
+
97
+ ### vim
98
+
99
+ - Make sure the `gibson` command is in your path by editing the `PATH` environment variable
100
+ - Edit `~/.vimrc`
101
+ - Add the following:
102
+ - `:command! -nargs=* Gibson r ! gibson <args>`
103
+ - Open a file and execute commands:
104
+ - `:Gibson module abc`
105
+ - `:Gibson models`
106
+ - `:Gibson schemas`
107
+
108
+ ## Currently Supported Software
109
+
110
+ - Python 3.9 or greater
111
+ - MySQL
112
+ - SQLAlchemy
113
+ - Pydantic
114
+ - Alembic
115
+ - FastAPI
116
+ - pytest
117
+
118
+ More languages and frameworks are in active development. If you do not see a version that you need let us know and we will get on it.
119
+
120
+ ## Coming Very Soon
121
+
122
+ - pytest based unit tests for all of the code Gibson writes.
123
+ - We know this is critical for Gibson to prove that its code is production-grade and bug free. As a development team, we need this too. It is coming in short order.
124
+ - Enhanced AI commands at your finger tips with code output and scratch storage.
125
+ - [DONE] See "Asking Gibson Questions With Context"
126
+ - Context aware coding from your Github repository.
127
+ - gibson scan
128
+ - AI based feedback directly to Gibson's creator:
129
+ - `gibson tell mike [hopefully nice things]`
130
+ - e.g. `gibson tell mike we need support for postgres`
131
+ - or, `gibson tell mike to hire me, I want to work on gibson`
132
+ - Significant data modeling improvements.
133
+ - The ability to integrate and download Function code using `gibson`.
134
+ - Along with a number of new Functions.
135
+ - Full FastAPI coding including module and entity specific dispatchers.
136
+
137
+ ## Detailed How-To
138
+
139
+ ### First Step
140
+
141
+ - Just run `gibson`. He will say hello and walk you through set up.
142
+
143
+ ### Configuring Your API Key
144
+
145
+ `gibson conf api::key [API key]`
146
+
147
+ ### Configuring Your Datastore
148
+
149
+ `gibson conf datastore::uri mysql+pymysql://[user]:[password]@[host]/[database name]`
150
+
151
+ Note: Gibson currently only supports MySQL. Let us know if you need something else.
152
+
153
+ ### Turning On Dev Mode
154
+
155
+ `gibson dev on`
156
+
157
+ - We suggest you turn dev mode on and leave it on. With it enabled, Gibson will act like your coworker and write code as you execute commands.
158
+
159
+ - You will need to provide 3 paths: `base` (where you want project base code to go), `model` (where you want SQLAlchemy models to go) and `schema` (where you want Pydantic schemas to go).
160
+
161
+ ### Importing Your Datastore
162
+
163
+ `gibson import datastore`
164
+
165
+ - This will make Gibson's stored memory aware of all of your datastore objects.
166
+ - `gibson import datastore .. dev`
167
+ - In addition to making Gibson aware, this will write all of the base, model and schema code for you.
168
+
169
+ ### Configuring a Custom BaseModel
170
+
171
+ You may be using a custom SQLAlchemy BaseModel and you do not want Gibson to use the one it has written.
172
+
173
+ ```sh
174
+ gibson conf code::custom::model::class [class name]
175
+ gibson conf code::custom::path [import path]
176
+ ```
177
+
178
+ For example, you might provide class name = `MyBaseModel` and import path = `project.model.MyBaseModel`
179
+
180
+ ### Writing the Base Code
181
+
182
+ `gibson base`
183
+
184
+ ### Writing the Code for a Single Model
185
+
186
+ `gibson model [table name]`
187
+
188
+ ### Writing the Code for a Single Schema
189
+
190
+ `gibson schema [table name]`
191
+
192
+ ### Writing the Code for All Models
193
+
194
+ `gibson models`
195
+
196
+ ### Writing the Code for All Schemas
197
+
198
+ `gibson schemas`
199
+
200
+ ### Adding a New Module to the Software Using AI
201
+
202
+ - gibson module [module name]
203
+ - e.g. gibson module user
204
+ - Gibson will display the SQL tables it has generated as a result of your request. It will store these entities in its last memory.
205
+ - gibson models
206
+ - This will write the code for the entities it just created.
207
+ - gibson merge
208
+ - This will merge the new entities into your project.
209
+ - Note, at the moment Gibson does not build the tables into your datastore.
210
+
211
+ ### Making Changes to the Software Using AI
212
+
213
+ - `gibson modify [table name] [natural language request]`
214
+ - e.g. `gibson modify my_table I want to add a new column called name and remove all of the columns related to email`
215
+ - Gibson will display the modified SQL table and store it in its last memory.
216
+ - `gibson models`
217
+ - This will write the code for the modified entity.
218
+ - `gibson merge`
219
+ - This will merge the modified entity into your project.
220
+ - Note, at the moment Gibson does not build the modified table into your datastore.
221
+
222
+ ### Forgetting Things Stored in Memory
223
+
224
+ - `gibson forget stored`
225
+ - `gibson forget last`
226
+ - `gibson forget all`
227
+
228
+ ### Building All of the Entities in Stored Memory into the Datastore
229
+
230
+ `gibson build`
231
+
232
+ ### Showing an Entity that is Stored in Memory
233
+
234
+ `gibson show [entity name]`
235
+
236
+ ### Building a Project End-to-End Using AI
237
+
238
+ - Go to <https://staging.gibsonai.com/>.
239
+ - Chat with Gibson and create a new project.
240
+ - When your project is complete Gibson will email you the API key.
241
+ - `gibson conf api::key [API key]`
242
+ - `gibson import api .. dev`
243
+ - Magic, no?
244
+
245
+ ### Integrating a Model into Your Code
246
+
247
+ Gibson creates base-level SQLAlchemy models. To integrate them just do this:
248
+
249
+ ```py
250
+ from my_project.gibsonai.model.Module import ModuleBase
251
+
252
+ class MyModule(ModuleBase):
253
+ pass
254
+ ```
255
+
256
+ - When you need to add custom business logic to the model, just modify your version of the model:
257
+
258
+ ```py
259
+ from my_project.gibsonai.model.Module import ModuleBase
260
+
261
+ class MyModule(ModuleBase):
262
+ def my_custom_business_logic(self):
263
+ return 1 + 1
264
+ ```
265
+
266
+ We strongly suggest you do not reference the base-level SQLAlchemy models directly. By sub-classing you won't have to refactor your code if you decide to add custom code.
267
+
268
+ ### Integrating a Schema into Your Code
269
+
270
+ At the moment, just refer to the base-level schema directly.
271
+
272
+ ### Migrating Your Software from PHP to Python
273
+
274
+ - Configure your datastore.
275
+ - Turn on Dev Mode.
276
+ - `gibson import datastore .. dev`
277
+ - 70% of your code is written, customize the remaining.
278
+
279
+ ### Asking Gibson Questions With Context
280
+
281
+ - `gibson ? [natural language request]`
282
+ - Your natural language request can include:
283
+ - `file://[full path]` to import a file from the filesystem
284
+ - `py://[import]` to import a file from `PYTHONPATH`
285
+ - `sql://[entity name]` to import the SQL
286
+ - For example:
287
+ - `gibson ? format file:///Users/me/file.py for PEP8`
288
+ - `gibson ? code review py://user.modules.User`
289
+ - `gibson ? add nickname to sql://user`
290
+ - When using `sql://`, any entities that are created as part of Gibson's response will be transferred into Gibson's last memory allowing you to execute a question, create a new entity and have Gibson immediately create a model or schema from it.
291
+ - e.g. `gibson ? add nickname to sql://user`
292
+ - `gibson model`
293
+ - Important note, `gibson ?` may cause your shell to incorrectly interpret the question mark. If it does, you can use `gibson q` instead (just replace the question mark with the letter `q`).
@@ -0,0 +1,45 @@
1
+ import requests
2
+
3
+
4
+ class BaseApi:
5
+ def get_headers(self):
6
+ raise NotImplementedError
7
+
8
+ def _get(self, end_point):
9
+ r = requests.get(self.get_url(end_point), headers=self.get_headers())
10
+
11
+ self.__raise_for_status(r)
12
+
13
+ return r.json()
14
+
15
+ def _post(self, end_point, json: dict):
16
+ r = requests.post(
17
+ self.get_url(end_point), headers=self.get_headers(), json=json
18
+ )
19
+
20
+ self.__raise_for_status(r)
21
+
22
+ return r
23
+
24
+ def _put(self, end_point, json: dict):
25
+ r = requests.put(self.get_url(end_point), headers=self.get_headers(), json=json)
26
+
27
+ self.__raise_for_status(r)
28
+
29
+ return r
30
+
31
+ def __raise_for_status(self, r):
32
+ try:
33
+ r.raise_for_status()
34
+ except:
35
+ try:
36
+ message = r.json()
37
+
38
+ print("=" * 78)
39
+ print("Raw Response:\n")
40
+ print(message)
41
+ print("\n" + "=" * 78)
42
+ except requests.exceptions.JSONDecodeError:
43
+ pass
44
+
45
+ raise