Skip to content

Commit

Permalink
claudette
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Apr 30, 2024
1 parent 657b4ff commit e1669d4
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 104 deletions.
4 changes: 2 additions & 2 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"id": "3d773712-12fe-440e-891f-36f59666dfde",
"metadata": {},
"source": [
"# Claudio's source"
"# Claudette's source"
]
},
{
"cell_type": "markdown",
"id": "c47b5d38",
"metadata": {},
"source": [
"This is the 'literate' source code for Claudio. You can view the fully rendered version of the notebook [here](https://answerdotai.github.io/claudio/core.html), or you can clone the git repo and run the [interactive notebook](https://github.com/AnswerDotAI/claudio/blob/main/00_core.ipynb) in Jupyter. The notebook is converted the [Python module claudio/core.py](https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py) using [nbdev](https://nbdev.fast.ai/). The goal of this source code is to both create the Python module, and also to teach the reader *how* it is created, without assuming much existing knowledge about Claude's API.\n",
"This is the 'literate' source code for Claudette. You can view the fully rendered version of the notebook [here](https://answerdotai.github.io/claudette/core.html), or you can clone the git repo and run the [interactive notebook](https://github.com/AnswerDotAI/claudette/blob/main/00_core.ipynb) in Jupyter. The notebook is converted the [Python module claudette/core.py](https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py) using [nbdev](https://nbdev.fast.ai/). The goal of this source code is to both create the Python module, and also to teach the reader *how* it is created, without assuming much existing knowledge about Claude's API.\n",
"\n",
"Most of the time you'll see that we write some source code *first*, and then a description or discussion of it *afterwards*."
]
Expand Down
84 changes: 42 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# claudio
# claudette


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

*Claudio* is a wrapper for Anthropic’s [Python
*Claudette* is a wrapper for Anthropic’s [Python
SDK](https://github.com/anthropics/anthropic-sdk-python).

TODO: This README is incomplete.

## Install

``` sh
pip install claudio
pip install claudette
```

## Getting started

Anthropic’s Python SDK will automatically be installed with Claudio, if
you don’t already have it.
Anthropic’s Python SDK will automatically be installed with Claudette,
if you don’t already have it.

You’ll need to set the `ANTHROPIC_API_KEY` environment variable to the
key provided by Anthropic.
Expand All @@ -31,17 +31,17 @@ To print every HTTP request and response in full, uncomment the above
line.

``` python
from claudio import *
from claudette import *
```

Claudio only exports the symbols that are needed to use the library, so
you can use `import *` to import them. Alternatively, just use:
Claudette only exports the symbols that are needed to use the library,
so you can use `import *` to import them. Alternatively, just use:

``` python
import claudio
import claudette
```

…and then add the prefix `claudio.` to any usages of the module.
…and then add the prefix `claudette.` to any usages of the module.

``` python
models
Expand All @@ -65,12 +65,12 @@ surprisingly good!)
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Chat

> Chat (model:Optional[str]=None, cli:Optional[claudio.core.Client]=None,
> Chat (model:Optional[str]=None, cli:Optional[claudette.core.Client]=None,
> sp='', tools:Optional[list]=None)
*Anthropic chat client.*
Expand All @@ -89,7 +89,7 @@ chat = Chat(model, sp="You are a helpful assistant.")
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Chat.\_\_call\_\_
Expand Down Expand Up @@ -152,7 +152,7 @@ life, the universe, and everything is 42.”
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Chat.stream
Expand Down Expand Up @@ -265,7 +265,7 @@ img = fn.read_bytes()
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### img_msg
Expand All @@ -280,7 +280,7 @@ image data to be in, so we have a little function to create that for us.
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### text_msg
Expand Down Expand Up @@ -352,7 +352,7 @@ be daisies or a similar type of flower.

Claude also supports uploading an image without any text, in which case
it’ll make a general comment about what it sees. You can then use
[`Chat`](https://AnswerDotAI.github.io/claudio/core.html#chat) to ask
[`Chat`](https://AnswerDotAI.github.io/claudette/core.html#chat) to ask
questions:

``` python
Expand Down Expand Up @@ -433,7 +433,7 @@ while the body is mostly white with some tan/brown patches.
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### mk_msg
Expand All @@ -452,7 +452,7 @@ added as key/value pairs to the message*
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### mk_msgs
Expand All @@ -464,7 +464,7 @@ target="_blank" style="float:right; font-size:smaller">source</a>
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client
Expand All @@ -476,7 +476,7 @@ target="_blank" style="float:right; font-size:smaller">source</a>
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client.\_\_call\_\_
Expand Down Expand Up @@ -527,7 +527,7 @@ c.use
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### Client.stream
Expand Down Expand Up @@ -581,7 +581,7 @@ def sums(
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### get_schema
Expand Down Expand Up @@ -641,7 +641,7 @@ dictionary of allowable function names to call.
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### call_func
Expand Down Expand Up @@ -669,7 +669,7 @@ res
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### mk_toolres
Expand All @@ -679,15 +679,15 @@ target="_blank" style="float:right; font-size:smaller">source</a>
*Create a `tool_result` message from response `r`.*

| | **Type** | **Default** | **Details** |
|-----|----------|-------------|--------------------------------------------------------------------------------------------------------------------------------------|
| r | Mapping | | Tool use request response from Claude |
| res | NoneType | None | The result of calling the tool (calculated with [`call_func`](https://AnswerDotAI.github.io/claudio/core.html#call_func) by default) |
| ns | Optional | None | Namespace to search for tools |
| | **Type** | **Default** | **Details** |
|-----|----------|-------------|----------------------------------------------------------------------------------------------------------------------------------------|
| r | Mapping | | Tool use request response from Claude |
| res | NoneType | None | The result of calling the tool (calculated with [`call_func`](https://AnswerDotAI.github.io/claudette/core.html#call_func) by default) |
| ns | Optional | None | Namespace to search for tools |

In order to tell Claude the result of the tool call, we pass back a
`tool_result` message, created by calling
[`call_func`](https://AnswerDotAI.github.io/claudio/core.html#call_func).
[`call_func`](https://AnswerDotAI.github.io/claudette/core.html#call_func).

``` python
tr = mk_toolres(r, res=res, ns=ns)
Expand Down Expand Up @@ -720,15 +720,15 @@ directly.
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### xt

> xt (tag:str, c:Optional[list]=None, **kw)
*Helper to create appropriate data structure for
[`to_xml`](https://AnswerDotAI.github.io/claudio/core.html#to_xml).*
[`to_xml`](https://AnswerDotAI.github.io/claudette/core.html#to_xml).*

| | **Type** | **Default** | **Details** |
|-----|----------|-------------|--------------|
Expand All @@ -737,7 +737,7 @@ target="_blank" style="float:right; font-size:smaller">source</a>
| kw | | | |

An XML node contains a tag, optional children, and optional attributes.
[`xt`](https://AnswerDotAI.github.io/claudio/core.html#xt) creates a
[`xt`](https://AnswerDotAI.github.io/claudette/core.html#xt) creates a
tuple of these three things, which we will use to general XML shortly.
Attributes are passed as kwargs; since these might conflict with
reserved words in Python, you can optionally add a `_` prefix and it’ll
Expand All @@ -750,7 +750,7 @@ xt('x-custom', ['hi'], _class='bar')
('x-custom', ['hi'], {'class': 'bar'})

``` python
from claudio.core import div,img,h1,h2,p,hr,html
from claudette.core import div,img,h1,h2,p,hr,html
```

If you have to use a lot of tags of the same type, it’s convenient to
Expand Down Expand Up @@ -784,7 +784,7 @@ a
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### hl_md
Expand All @@ -807,7 +807,7 @@ hl_md('<test><xml foo="bar">a child</xml></test>')
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### to_xml
Expand All @@ -816,10 +816,10 @@ target="_blank" style="float:right; font-size:smaller">source</a>
*Convert `node` to an XML string.*

| | **Type** | **Default** | **Details** |
|------|----------|-------------|------------------------------------------------------------------------------------|
| node | tuple | | XML structure in [`xt`](https://AnswerDotAI.github.io/claudio/core.html#xt) format |
| hl | bool | False | Syntax highlight response? |
| | **Type** | **Default** | **Details** |
|------|----------|-------------|--------------------------------------------------------------------------------------|
| node | tuple | | XML structure in [`xt`](https://AnswerDotAI.github.io/claudette/core.html#xt) format |
| hl | bool | False | Syntax highlight response? |

Now we can convert that HTML data structure we created into XML:

Expand All @@ -842,7 +842,7 @@ to_xml(a, hl=True)
------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/claudio/blob/main/claudio/core.py#LNone"
href="https://github.com/AnswerDotAI/claudette/blob/main/claudette/core.py#LNone"
target="_blank" style="float:right; font-size:smaller">source</a>

### json_to_xml
Expand Down
1 change: 1 addition & 0 deletions claudio/__init__.py → claudette/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__version__ = "0.0.1"
from .core import *

41 changes: 41 additions & 0 deletions claudette/_modidx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Autogenerated by nbdev

d = { 'settings': { 'branch': 'main',
'doc_baseurl': '/claudette',
'doc_host': 'https://AnswerDotAI.github.io',
'git_url': 'https://github.com/AnswerDotAI/claudette',
'lib_path': 'claudette'},
'syms': { 'claudette.core': { 'claudette.core.(ToolsBetaMessage, Message)._repr_markdown_': ( 'core.html#(toolsbetamessage, '
'message)._repr_markdown_',
'claudette/core.py'),
'claudette.core.Chat': ('core.html#chat', 'claudette/core.py'),
'claudette.core.Chat.__call__': ('core.html#chat.__call__', 'claudette/core.py'),
'claudette.core.Chat.__init__': ('core.html#chat.__init__', 'claudette/core.py'),
'claudette.core.Chat.stream': ('core.html#chat.stream', 'claudette/core.py'),
'claudette.core.Client': ('core.html#client', 'claudette/core.py'),
'claudette.core.Client.__call__': ('core.html#client.__call__', 'claudette/core.py'),
'claudette.core.Client.__init__': ('core.html#client.__init__', 'claudette/core.py'),
'claudette.core.Client._r': ('core.html#client._r', 'claudette/core.py'),
'claudette.core.Client.stream': ('core.html#client.stream', 'claudette/core.py'),
'claudette.core.Usage.__add__': ('core.html#usage.__add__', 'claudette/core.py'),
'claudette.core.Usage.__repr__': ('core.html#usage.__repr__', 'claudette/core.py'),
'claudette.core.Usage.total': ('core.html#usage.total', 'claudette/core.py'),
'claudette.core._add_prefill': ('core.html#_add_prefill', 'claudette/core.py'),
'claudette.core._mk_content': ('core.html#_mk_content', 'claudette/core.py'),
'claudette.core._mk_ns': ('core.html#_mk_ns', 'claudette/core.py'),
'claudette.core._param': ('core.html#_param', 'claudette/core.py'),
'claudette.core._types': ('core.html#_types', 'claudette/core.py'),
'claudette.core.call_func': ('core.html#call_func', 'claudette/core.py'),
'claudette.core.contents': ('core.html#contents', 'claudette/core.py'),
'claudette.core.find_block': ('core.html#find_block', 'claudette/core.py'),
'claudette.core.get_schema': ('core.html#get_schema', 'claudette/core.py'),
'claudette.core.hl_md': ('core.html#hl_md', 'claudette/core.py'),
'claudette.core.img_msg': ('core.html#img_msg', 'claudette/core.py'),
'claudette.core.json_to_xml': ('core.html#json_to_xml', 'claudette/core.py'),
'claudette.core.mk_msg': ('core.html#mk_msg', 'claudette/core.py'),
'claudette.core.mk_msgs': ('core.html#mk_msgs', 'claudette/core.py'),
'claudette.core.mk_toolres': ('core.html#mk_toolres', 'claudette/core.py'),
'claudette.core.text_msg': ('core.html#text_msg', 'claudette/core.py'),
'claudette.core.to_xml': ('core.html#to_xml', 'claudette/core.py'),
'claudette.core.usage': ('core.html#usage', 'claudette/core.py'),
'claudette.core.xt': ('core.html#xt', 'claudette/core.py')}}}
File renamed without changes.
Loading

0 comments on commit e1669d4

Please sign in to comment.