Skip to content

Commit

Permalink
Restructure the JS reference
Browse files Browse the repository at this point in the history
  • Loading branch information
deepbuzin committed Feb 20, 2025
1 parent 352680b commit 8762bc2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/ai/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gel AI
reference_extai
reference_http
reference_python
javascript
reference_javascript
guide_edgeql
guide_python
fastapi_gelai_searchbot
Expand Down
109 changes: 42 additions & 67 deletions docs/ai/javascript.rst → docs/ai/reference_javascript.rst
Original file line number Diff line number Diff line change
@@ -1,94 +1,67 @@
.. _ref_ai_javascript:
.. _ref_ai_javascript_reference:

==========
JavaScript
==========
=================
AI JavaScript API
=================

:edb-alt-title: Gel AI's JavaScript package
:edb-alt-title: AI Extension JavaScript API

``@gel/ai`` offers a convenient wrapper around ``ext::ai``. Install it with
npm or via your package manager of choice:
``@gel/ai`` is a wrapper around the :ref:`AI extension
<ref_ai_extai_reference>` in |Gel|.

.. code-block:: bash
.. code-tabs::

$ npm install @gel/ai # or
$ yarn add @gel/ai # or
$ pnpm add @gel/ai # or
$ bun add @gel/ai
.. code-tab:: bash
:caption: npm

$ npm install @gel/ai

Usage
=====
.. code-tab:: bash
:caption: yarn

Start by importing ``createClient`` from ``gel`` and ``createAI`` from
``@gel/ai``:
$ yarn add @gel/ai

.. code-tab:: bash
:caption: pnpm

$ pnpm add @gel/ai

.. code-tab:: bash
:caption: bun

$ bun add @gel/ai


Overview
========

The AI package is built on top of the regular |Gel| client objects.

**Example**:

.. code-block:: typescript
import { createClient } from "gel";
import { createAI } from "@gel/ai";
Create a |Gel| client. Create an instance of the AI client by passing in the
Gel client and any options for the AI provider (like the text generation
model):

.. code-block:: typescript
const client = createClient();
const gpt4Ai = createAI(client, {
model: "gpt-4-turbo-preview",
});
You may use any of the supported :ref:`text generation models
<ref_ai_extai_reference_text_generation_models>`. Add your query as context:

.. code-block:: typescript
const astronomyAi = gpt4Ai.withContext({
query: "Astronomy"
});
This "query" property doesn't have to be a proper query at all. It can be any
expression that produces a set of objects, like ``Astronomy`` in the example
above which will return all objects of that type. On the other hand, if you
want to narrow the field more, you can give it a query like ``select Astronomy
filter .topic = "Mars"``.

The default text generation prompt will ask your selected provider to limit
answer to information provided in the context and will pass the queried
objects' AI index as context along with that prompt.

Call your AI client's ``queryRag`` method, passing in a text query.

.. code-block:: typescript
console.log(
await astronomyAi.queryRag("What color is the sky on Mars?")
);
You can chain additional calls of ``withContext`` or ``withConfig`` to create
additional AI clients, identical except for the newly specified values.

.. code-block:: typescript
const fastAstronomyAi = astronomyAi.withConfig({
model: "gpt-3.5-turbo",
});
console.log(
await fastAstronomyAi.queryRag("What color is the sky on Mars?")
);
const fastChemistryAi = fastAstronomyAi.withContext({
query: "Chemistry"
});
console.log(
await fastChemistryAi.queryRag("What is the atomic number of gold?")
);
API Reference
=============
Factory functions
=================

.. js:function:: createAI( \
client: Client, \
Expand All @@ -111,14 +84,16 @@ API Reference
interactions. The default is the built-in system prompt.


GelAI
-----
Core classes
============


.. js:class:: GelAI

Instances of ``GelAI`` offer methods for client configuration and utilizing
RAG.
Instances of ``GelAI`` offer methods for client configuration and utilizing RAG.

Public methods
^^^^^^^^^^^^^^
:ivar client:
An instance of |Gel| client.

.. js:method:: withConfig(options: Partial<AIOptions>): GelAI

Expand Down
3 changes: 2 additions & 1 deletion docs/ai/reference_python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ AI Python API

:edb-alt-title: AI Extension Python API

The ``gel.ai`` package is an optional binding of the AI extension in |Gel|.
The ``gel.ai`` package is an optional binding of the :ref:`AI extension
<ref_ai_extai_reference>` in |Gel|.

.. code-block:: bash
Expand Down

0 comments on commit 8762bc2

Please sign in to comment.