Skip to content

Commit

Permalink
Merge pull request #181 from haesleinhuepf/bugfix-reflection-versus-p…
Browse files Browse the repository at this point in the history
…rompt-writing

Bugfix reflection versus prompt writing, simplifyed calling the LLM from python
  • Loading branch information
haesleinhuepf authored Jul 22, 2024
2 parents 57ebb1a + 791b974 commit b2936ee
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 106 deletions.
287 changes: 185 additions & 102 deletions demo/writing_prompts.ipynb

Large diffs are not rendered by default.

Binary file modified docs/images/writing_prompts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/bia_bob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ._document import doc
from ._utilities import available_models
from ._notebook_generation import generate_notebook
from ._utilities import ask_llm

bob.initialize = init_assistant
bob.__version__ = __version__
Expand Down
4 changes: 4 additions & 0 deletions src/bia_bob/_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ def remove_outer_markdown_annotation(code):
def refine_code(code):
"""Uses reflection to figure out which variables are available and imports are missing.
The LLM is asked to refine the code accordingly."""
if "%bob" in code:
# task was to write a prompt
return code

reusable_variables_block = create_reusable_variables_block()
refined_code = ask_llm(f"""
Expand Down
8 changes: 4 additions & 4 deletions src/bia_bob/suggestions/_bia_bob.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def suggestions():
* by the end, show the result.
```
If you explicitly wish to do this with Python code, you can do it like this:
You can also submit a prompt without system prompts to the LLM and retrieve the response as string like this:
(Note that the image parameter is optional)
```python
from bia_bob import bob
code = bob("Do this, that and by the end, show the result.")
from bia_bob import ask_llm
code = ask_llm("Do this, that and by the end, show the result.", image=image)
exec(code)
```
"""

0 comments on commit b2936ee

Please sign in to comment.