Skip to content

Commit

Permalink
Merge pull request #164 from NimbleBoxAI/yash/multiapi-bugfix
Browse files Browse the repository at this point in the history
[chore] automate generation of components list
  • Loading branch information
yashbonde authored Oct 16, 2023
2 parents c070050 + 18431fa commit c181b3b
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
python -m pip install sphinx-rtd-theme==1.2.2
cd server
python3 -m pip install .
cd ..
python3 scripts/list_builtins.py ./api_docs/templates/components-list.rst ./api_docs/examples/components-list.rst
- name: Build docs
run: |
Expand Down
7 changes: 0 additions & 7 deletions api_docs/cf_server/chainfury_server.api.fury.rst

This file was deleted.

1 change: 0 additions & 1 deletion api_docs/cf_server/chainfury_server.api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ Submodules
:maxdepth: 4

chainfury_server.api.chains
chainfury_server.api.fury
chainfury_server.api.prompts
chainfury_server.api.user
75 changes: 75 additions & 0 deletions api_docs/examples/components-list.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Components List
===============

.. this is a jinja template document, run scripts/list_builtins.py to generate components-list.rst
There are several components that are shipped with the ``chainfury``. You can find how to access the underlying function
via the `components page`_.

.. code-block::python
# load the registries you can do these imports
from chainfury import programatic_actions_registry, ai_actions_registry
Programatic Actions
-------------------

Programatic means that these are generally not an LLM call rather something more standard like calling an API,
transforming the data, etc.


* `serper-api` - Search the web with Serper. Copy: ``programatic_actions_registry.get("serper-api")``

* `call_api_requests` - Call an API using the requests library. Copy: ``programatic_actions_registry.get("call_api_requests")``

* `regex_search` - Perform a regex search on the text and get items in an array. Copy: ``programatic_actions_registry.get("regex_search")``

* `regex_substitute` - Perform a regex substitution on the text and get the result. Copy: ``programatic_actions_registry.get("regex_substitute")``

* `json_translator` - Extract a value from a JSON object using a list of keys. Copy: ``programatic_actions_registry.get("json_translator")``


AI Action Components
--------------------

These actions generally take the input, create a custom prompt, call the Model and respond back with the result.


* `hello-world` - Python function loaded from a file used as an AI action. Copy: ``ai_actions_registry.get("hello-world")``

* `deep-rap-quote` - J-type action will write a deep poem in the style of a character. Copy: ``ai_actions_registry.get("deep-rap-quote")``


Memory Components
-----------------

Memory components are used to store data, which can be a Vector DB or Redis, etc.


* `qdrant-write` - Write to the Qdrant DB using the Qdrant client. Copy: ``memory_registry.get_write("qdrant-write")``

* `qdrant-read` - Function to read from the Qdrant DB using the Qdrant client. Copy: ``memory_registry.get_read("qdrant-read")``


Model Components
----------------

Model are the different GenAI models that can be used from the ``chainfury``.


* `stability-text-to-image` - Generate a new image from a text prompt. Copy: ``model_registry.get("stability-text-to-image")``

* `chatnbx` - Chat with the ChatNBX API with OpenAI compatability, see more at https://chat.nbox.ai/. Copy: ``model_registry.get("chatnbx")``

* `nbx-deploy` - Call NimbleBox LLMOps deploy API. Copy: ``model_registry.get("nbx-deploy")``

* `openai-completion` - Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position. Copy: ``model_registry.get("openai-completion")``

* `openai-chat` - Given a list of messages describing a conversation, the model will return a response. Copy: ``model_registry.get("openai-chat")``

* `openai-embedding` - Given a list of messages create embeddings for each message. Copy: ``model_registry.get("openai-embedding")``


.. all the links are here
.. _components page: https://qdrant.tech/documentation/tutorials/bulk-upload/#upload-directly-to-disk
2 changes: 1 addition & 1 deletion api_docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Read the latest blog posts:

examples/install
examples/storing-private-data
examples/use-chainfury-privately

.. toctree::
:maxdepth: 2
Expand All @@ -65,6 +64,7 @@ Read the latest blog posts:
:caption: Integrations

source/chainfury.components
examples/components-list

.. toctree::
:maxdepth: 2
Expand Down
54 changes: 54 additions & 0 deletions api_docs/templates/components-list.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Components List
===============

.. this is a jinja template document, run scripts/list_builtins.py to generate components-list.rst
There are several components that are shipped with the ``chainfury``. You can find how to access the underlying function
via the `components page`_.

.. code-block::python
# load the registries you can do these imports
from chainfury import programatic_actions_registry, ai_actions_registry
Programatic Actions
-------------------

Programatic means that these are generally not an LLM call rather something more standard like calling an API,
transforming the data, etc.

{% for component in pc %}
* `{{ component.id }}` - {{ component.description }}
{% endfor %}

AI Action Components
--------------------

These actions generally take the input, create a custom prompt, call the Model and respond back with the result.

{% for component in ac %}
* `{{ component.id }}` - {{ component.description }}
{% endfor %}

Memory Components
-----------------

Memory components are used to store data, which can be a Vector DB or Redis, etc.

{% for component in mc %}
* `{{ component.id }}` - {{ component.description }}
{% endfor %}

Model Components
----------------

Model are the different GenAI models that can be used from the ``chainfury``.

{% for component in moc %}
* `{{ component.id }}` - {{ component.description }}
{% endfor %}

.. all the links are here
.. _components page: https://qdrant.tech/documentation/tutorials/bulk-upload/#upload-directly-to-disk

2 changes: 1 addition & 1 deletion cf_internal
2 changes: 1 addition & 1 deletion chainfury/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ def __call__(self, **data: Dict[str, Any]) -> Any:

class MemoryRegistry:
def __init__(self) -> None:
self._memories = {}
self._memories: Dict[str, Node] = {}

def register_write(
self,
Expand Down
2 changes: 1 addition & 1 deletion chainfury/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def __init__(
collection_name: str,
id: str,
fn: object,
description,
description: str = "",
usage: List[Union[str, int]] = [],
tags=[],
):
Expand Down
2 changes: 2 additions & 0 deletions chainfury/components/qdrant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _insert():
fn=qdrant_write,
outputs={"status": 0},
vector_key="embeddings",
description="Write to the Qdrant DB using the Qdrant client",
)


Expand Down Expand Up @@ -251,6 +252,7 @@ def qdrant_read(
fn=qdrant_read,
outputs={"items": 0},
vector_key="embeddings",
description="Function to read from the Qdrant DB using the Qdrant client",
)


Expand Down
58 changes: 58 additions & 0 deletions scripts/list_builtins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from fire import Fire
import jinja2 as j2
from chainfury import programatic_actions_registry, ai_actions_registry, memory_registry, model_registry


def main(src_file: str, trg_file: str, v: bool = False):
with open(src_file, "r") as f:
temp = j2.Template(f.read())

# create the components list
pc = []
for node_id, node in programatic_actions_registry.nodes.items():
pc.append(
{
"id": node.id,
"description": node.description.rstrip(".") + f'. Copy: ``programatic_actions_registry.get("{node.id}")``',
}
)

ac = []
for node_id, node in ai_actions_registry.nodes.items():
ac.append(
{
"id": node.id,
"description": node.description.rstrip(".") + f'. Copy: ``ai_actions_registry.get("{node.id}")``',
}
)

mc = []
for node_id, node in memory_registry._memories.items():
fn = "get_read" if node.id.endswith("-read") else "get_write"
mc.append(
{
"id": node.id,
"description": node.description.rstrip(".") + f'. Copy: ``memory_registry.{fn}("{node.id}")``',
}
)

moc = []
for model_id, model in model_registry.models.items():
moc.append(
{
"id": model_id,
"description": model.description.rstrip(".") + f'. Copy: ``model_registry.get("{model_id}")``',
}
)

op = temp.render(pc=pc, ac=ac, mc=mc, moc=moc)
if v:
print(op)
print("Writing to", trg_file)

with open(trg_file, "w") as f:
f.write(op)


if __name__ == "__main__":
Fire(main)

0 comments on commit c181b3b

Please sign in to comment.