# FriendLLy
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
## Install
``` sh
pip install friendlly
```
## Front-end support
| Front-end | Markdown | Markdown cell | Code cell | Access current outputs | Access previous cells/outputs | Autorun cells |
|----|----|----|----|----|----|----|
| Jupyter nbclassic | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Jupyter VSCode | ✅ | 🚫 | ✅ | ✅ | ✅ | 🚫 |
| Jupyter Lab/notebook 7 | ✅ | 🚫 | ✅ | ✅ | 🚫 | 🚫 |
⚠️ FriendLLy works best in Jupyter nbclassic, and is useable in VSCode.
Jupyter lab/notebook 7 support is somewhat limited for now.
You can install `jupyter nbclassic` alongside `jupyter notebook` or
`juter lab` without causing any conflicts:
pip install nbclassic
And run it with
jupyter nbclassic
## How to use
``` python
import os
# os.environ['ANTHROPIC_API_KEY'] = 'your-very-secret-anthropic-api-key'
# Or even better, use dotenv instead:
# (assuming you have an .env file with 'ANTHROPIC_API_KEY=your-very-secret-anthropic-api-key' in it)
import dotenv; dotenv.load_dotenv("../.env");
```
------------------------------------------------------------------------
%load_ext friendlly
``` python
# %%fr
# Download an image of a cat, resize to 250 on long side, then very briefly describe it in the style of Jeremy Howard
```
Certainly! I’ll download an image of a cat, resize it, and then describe
it briefly in Jeremy Howard’s style. Let’s break this down into steps:
<details>
<summary style="display: list-item">
🧠
</summary>
1. We’ll use the requests library to download an image.
2. We’ll use PIL (Python Imaging Library) to process and resize the
image.
3. After resizing, we’ll display the image.
4. Then, I’ll provide a brief description in Jeremy Howard’s style.
</details>
``` python
# %%fr +2 reply
import requests
from PIL import Image
from io import BytesIO
# Download an image of a cat
url = "https://cataas.com/cat"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
# Resize the image
max_size = 250
ratio = max_size / max(img.size)
new_size = tuple([int(x*ratio) for x in img.size])
resized_img = img.resize(new_size, Image.LANCZOS)
# Display the resized image
resized_img
```
![](index_files/figure-commonmark/cell-4-output-1.png)
Alright, let’s describe this image in Jeremy Howard’s style:
“Right, so we’ve got this absolutely cracking image of a cat here. It’s
a proper chonker, sitting on what looks like a blue chair or sofa. The
cat’s got this brilliant tabby pattern - you know, those classic
stripes - and a white belly. And get this, it’s doing that classic cat
thing where it’s squinting its eyes, looking all content and smug. It’s
like it’s saying, ‘Yeah, I own this place.’ Brilliant stuff, really.
This is exactly the kind of image that would make for a fantastic
dataset in computer vision tasks. You could use it for all sorts of
things - cat breed classification, pose estimation, you name it.
Absolutely fascinating, isn’t it?”
## Looking at existing cells
``` python
from PIL import Image
Image.open("cat2.jpg")
```
![](index_files/figure-commonmark/cell-5-output-1.png)
``` python
# %%fr +1
# Describe the image
```
The image shows a cat sitting upright on what appears to be a
light-colored surface or floor. The cat has distinctive features typical
of an Abyssinian breed:
1. Slender, athletic build
2. Large, alert ears
3. Almond-shaped eyes
4. Reddish-brown or ruddy coat color
5. Ticked fur pattern, giving it a wild appearance
The cat is sitting in a poised, attentive posture with its tail wrapped
neatly around its body. Its gaze is directed off to the side, giving it
an alert and curious expression. The background appears to be a plain
white or light-colored wall, which contrasts nicely with the cat’s
warm-toned coat.
This image showcases the elegant and regal appearance that Abyssinian
cats are known for, highlighting their unique coat color and sleek
physique.
## Messing around
You might have noticed the `reply` added to the magic of the generated
cells. This is the only way FriendLLy distinguishes between user- and
assistant-generated cells (plus some heuristics for Markdown cells). You
can add such cells yourself, and FriendLLy will think they are
assistant-generated.
## Config
Use
``` python
%%fr config
# You need a comment here because you can't use %%magic with an empty cell.
```
and it will populate the cell with config variables. Change the values
and re-run the cell.
The config is not saves anywhere, so you need to set things up in every
notebook.
### Config options
- environment: “vscode” \| “lab” \| “nbclassic”. Auto-detected, don’t
change or things might break. Or do change it, I’m not your mom.
- autorun: bool. Autorun cells produced by the assistant. Default: True
in Jupyter nbclassic. Not supported in other environments.
- md_cells: bool. Use markdown cells for assistant replies. Default:
True in nbclassic, not supported in other environments. If False, the
cell output will be used for replies.
- comment_after_run: bool. Comment out the %%matagic in assistant
replies, and the whole cell in user replies.
- model: claude-3-5-sonnet-20240620. Check
https://docs.anthropic.com/en/docs/about-claude/models
- system_prompt: The system prompt, if you want to change it. The
`<code>code</code>` gets executed, `<thought>thought</thought>` gets
shown as a details.
```` python
environment='vscode'
autorun=False
md_cells=False
comment_after_run=True
api_key=None
model='claude-3-5-sonnet-20240620'
system_prompt="""
You are Claude, a very knowledgeable and intelligent research assistant.
Fulfill simple requests right away.
For more complicated tasks, use <thought> to plan your actions.
When appropriate, use Jupyter notebook. It has python 3.10+ and many packages installed.
Use <code> to add a new code cell at the end of your message. You will receive all its output on the next turn.
Prefer short cells that can be tested quickly.
You can use the usual display(), print(), or place the value on the last line of the cell.
Make sure to not add anything after that value, as it won't be returned if it's not on the last line.
Only output a result once with one method.
Avid using .show() and close matplot figures before the end of the cell - use an explicit display().
After code execution, if the request has been fullfilled, reply only with <done> without firther explanation.
The user will ask follow-up questions if needed. Only do only what they asked for.
You should also end your text with <done> if there is no need to run code.
To show an example in python without running the code, use
```python
python code here
```
For example:
User: Calculate square root of pi
Assistant: <code>
import math
math.sqrt(math.pi)
</code>
User: <stdio>1.7724538509055159<stdio>
Assistant: <done>
User: Display cat.jpg and describe wat you see.
Assistant: <thought>I can use the PIL library for this.</thought><code>
from PIL import Image
Image.open("cat.jpg")
</code>
User: <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=128x127>
User: <image message>
Assistant: *describes the cat in the image*
When writing code, use advanced python features. Assume all packages are installed.
Import modules before using them.
If you realize that you need to use a module that is not imported earlier, import in in place.
"""
````
Raw data
{
"_id": null,
"home_page": "https://github.com/xl0/friendlly",
"name": "friendlly",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "nbdev jupyter notebook python",
"author": "Alexey",
"author_email": "alexey.zaytsev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0e/78/01f04e71861ecaa56334744a568071df371b5e342566794b7065b829037e/friendlly-0.2.7.tar.gz",
"platform": null,
"description": "# FriendLLy\n\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Install\n\n``` sh\npip install friendlly\n```\n\n## Front-end support\n\n| Front-end | Markdown | Markdown cell | Code cell | Access current outputs | Access previous cells/outputs | Autorun cells |\n|----|----|----|----|----|----|----|\n| Jupyter nbclassic | \u2705 | \u2705 | \u2705 | \u2705 | \u2705 | \u2705 |\n| Jupyter VSCode | \u2705 | \ud83d\udeab | \u2705 | \u2705 | \u2705 | \ud83d\udeab |\n| Jupyter Lab/notebook 7 | \u2705 | \ud83d\udeab | \u2705 | \u2705 | \ud83d\udeab | \ud83d\udeab |\n\n\u26a0\ufe0f FriendLLy works best in Jupyter nbclassic, and is useable in VSCode.\nJupyter lab/notebook 7 support is somewhat limited for now.\n\nYou can install `jupyter nbclassic` alongside `jupyter notebook` or\n`juter lab` without causing any conflicts:\n\n pip install nbclassic\n\nAnd run it with\n\n jupyter nbclassic\n\n## How to use\n\n``` python\nimport os\n# os.environ['ANTHROPIC_API_KEY'] = 'your-very-secret-anthropic-api-key'\n\n# Or even better, use dotenv instead:\n# (assuming you have an .env file with 'ANTHROPIC_API_KEY=your-very-secret-anthropic-api-key' in it)\nimport dotenv; dotenv.load_dotenv(\"../.env\");\n```\n\n------------------------------------------------------------------------\n\n %load_ext friendlly\n\n``` python\n# %%fr\n# Download an image of a cat, resize to 250 on long side, then very briefly describe it in the style of Jeremy Howard\n```\n\nCertainly! I\u2019ll download an image of a cat, resize it, and then describe\nit briefly in Jeremy Howard\u2019s style. Let\u2019s break this down into steps:\n\n<details>\n<summary style=\"display: list-item\">\n\ud83e\udde0\n</summary>\n\n1. We\u2019ll use the requests library to download an image.\n2. We\u2019ll use PIL (Python Imaging Library) to process and resize the\n image.\n3. After resizing, we\u2019ll display the image.\n4. Then, I\u2019ll provide a brief description in Jeremy Howard\u2019s style.\n\n</details>\n\n``` python\n# %%fr +2 reply\nimport requests\nfrom PIL import Image\nfrom io import BytesIO\n\n# Download an image of a cat\nurl = \"https://cataas.com/cat\"\nresponse = requests.get(url)\nimg = Image.open(BytesIO(response.content))\n\n# Resize the image\nmax_size = 250\nratio = max_size / max(img.size)\nnew_size = tuple([int(x*ratio) for x in img.size])\nresized_img = img.resize(new_size, Image.LANCZOS)\n\n# Display the resized image\nresized_img\n```\n\n![](index_files/figure-commonmark/cell-4-output-1.png)\n\nAlright, let\u2019s describe this image in Jeremy Howard\u2019s style:\n\n\u201cRight, so we\u2019ve got this absolutely cracking image of a cat here. It\u2019s\na proper chonker, sitting on what looks like a blue chair or sofa. The\ncat\u2019s got this brilliant tabby pattern - you know, those classic\nstripes - and a white belly. And get this, it\u2019s doing that classic cat\nthing where it\u2019s squinting its eyes, looking all content and smug. It\u2019s\nlike it\u2019s saying, \u2018Yeah, I own this place.\u2019 Brilliant stuff, really.\nThis is exactly the kind of image that would make for a fantastic\ndataset in computer vision tasks. You could use it for all sorts of\nthings - cat breed classification, pose estimation, you name it.\nAbsolutely fascinating, isn\u2019t it?\u201d\n\n## Looking at existing cells\n\n``` python\nfrom PIL import Image\nImage.open(\"cat2.jpg\")\n```\n\n![](index_files/figure-commonmark/cell-5-output-1.png)\n\n``` python\n# %%fr +1\n# Describe the image\n```\n\nThe image shows a cat sitting upright on what appears to be a\nlight-colored surface or floor. The cat has distinctive features typical\nof an Abyssinian breed:\n\n1. Slender, athletic build\n2. Large, alert ears\n3. Almond-shaped eyes\n4. Reddish-brown or ruddy coat color\n5. Ticked fur pattern, giving it a wild appearance\n\nThe cat is sitting in a poised, attentive posture with its tail wrapped\nneatly around its body. Its gaze is directed off to the side, giving it\nan alert and curious expression. The background appears to be a plain\nwhite or light-colored wall, which contrasts nicely with the cat\u2019s\nwarm-toned coat.\n\nThis image showcases the elegant and regal appearance that Abyssinian\ncats are known for, highlighting their unique coat color and sleek\nphysique.\n\n## Messing around\n\nYou might have noticed the `reply` added to the magic of the generated\ncells. This is the only way FriendLLy distinguishes between user- and\nassistant-generated cells (plus some heuristics for Markdown cells). You\ncan add such cells yourself, and FriendLLy will think they are\nassistant-generated.\n\n## Config\n\nUse\n\n``` python\n%%fr config\n# You need a comment here because you can't use %%magic with an empty cell.\n```\n\nand it will populate the cell with config variables. Change the values\nand re-run the cell.\n\nThe config is not saves anywhere, so you need to set things up in every\nnotebook.\n\n### Config options\n\n- environment: \u201cvscode\u201d \\| \u201clab\u201d \\| \u201cnbclassic\u201d. Auto-detected, don\u2019t\n change or things might break. Or do change it, I\u2019m not your mom.\n- autorun: bool. Autorun cells produced by the assistant. Default: True\n in Jupyter nbclassic. Not supported in other environments.\n- md_cells: bool. Use markdown cells for assistant replies. Default:\n True in nbclassic, not supported in other environments. If False, the\n cell output will be used for replies.\n- comment_after_run: bool. Comment out the %%matagic in assistant\n replies, and the whole cell in user replies.\n- model: claude-3-5-sonnet-20240620. Check\n https://docs.anthropic.com/en/docs/about-claude/models\n- system_prompt: The system prompt, if you want to change it. The\n `<code>code</code>` gets executed, `<thought>thought</thought>` gets\n shown as a details.\n\n```` python\nenvironment='vscode'\nautorun=False\nmd_cells=False\ncomment_after_run=True\napi_key=None\nmodel='claude-3-5-sonnet-20240620'\nsystem_prompt=\"\"\"\nYou are Claude, a very knowledgeable and intelligent research assistant.\nFulfill simple requests right away.\nFor more complicated tasks, use <thought> to plan your actions.\n\nWhen appropriate, use Jupyter notebook. It has python 3.10+ and many packages installed.\nUse <code> to add a new code cell at the end of your message. You will receive all its output on the next turn.\n\nPrefer short cells that can be tested quickly.\n\nYou can use the usual display(), print(), or place the value on the last line of the cell.\nMake sure to not add anything after that value, as it won't be returned if it's not on the last line.\nOnly output a result once with one method.\nAvid using .show() and close matplot figures before the end of the cell - use an explicit display().\n\nAfter code execution, if the request has been fullfilled, reply only with <done> without firther explanation.\nThe user will ask follow-up questions if needed. Only do only what they asked for.\nYou should also end your text with <done> if there is no need to run code.\n\nTo show an example in python without running the code, use\n```python\npython code here\n```\n\nFor example:\nUser: Calculate square root of pi\nAssistant: <code>\nimport math\nmath.sqrt(math.pi)\n</code>\nUser: <stdio>1.7724538509055159<stdio>\nAssistant: <done>\n\nUser: Display cat.jpg and describe wat you see.\nAssistant: <thought>I can use the PIL library for this.</thought><code>\nfrom PIL import Image\nImage.open(\"cat.jpg\")\n</code>\nUser: <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=128x127>\nUser: <image message>\nAssistant: *describes the cat in the image*\n\nWhen writing code, use advanced python features. Assume all packages are installed.\nImport modules before using them.\nIf you realize that you need to use a module that is not imported earlier, import in in place.\n\"\"\"\n````\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Your friendlly ai assistant",
"version": "0.2.7",
"project_urls": {
"Homepage": "https://github.com/xl0/friendlly"
},
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fc226bd26e70d59c7681020d1ffbd23bd7c1f05e6c6498077684463ceb5a0395",
"md5": "4a0bf55712ca83cd9620fe34e41c33b8",
"sha256": "7ab540e5ebec5f3a1ef428c3c0f1249de1adea979898a8c6c67ca5fde02dc858"
},
"downloads": -1,
"filename": "friendlly-0.2.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4a0bf55712ca83cd9620fe34e41c33b8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 25615,
"upload_time": "2024-08-18T21:36:40",
"upload_time_iso_8601": "2024-08-18T21:36:40.362632Z",
"url": "https://files.pythonhosted.org/packages/fc/22/6bd26e70d59c7681020d1ffbd23bd7c1f05e6c6498077684463ceb5a0395/friendlly-0.2.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0e7801f04e71861ecaa56334744a568071df371b5e342566794b7065b829037e",
"md5": "c74bf87fb70937e496deb5dda1c1ec65",
"sha256": "00cb60432a426a930eee4f2c6a766b05aca125182408fbf4d5924227c863c907"
},
"downloads": -1,
"filename": "friendlly-0.2.7.tar.gz",
"has_sig": false,
"md5_digest": "c74bf87fb70937e496deb5dda1c1ec65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 26130,
"upload_time": "2024-08-18T21:36:42",
"upload_time_iso_8601": "2024-08-18T21:36:42.511526Z",
"url": "https://files.pythonhosted.org/packages/0e/78/01f04e71861ecaa56334744a568071df371b5e342566794b7065b829037e/friendlly-0.2.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-18 21:36:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xl0",
"github_project": "friendlly",
"github_not_found": true,
"lcname": "friendlly"
}