s-kostyaev / ellama

Ellama is a tool for interacting with large language models from Emacs.
GNU General Public License v3.0
348 stars 25 forks source link

Feature request: Generic context elements #89

Closed r0man closed 3 months ago

r0man commented 3 months ago

Hi @s-kostyaev,

I have some knowledge bases at work and I would like to integrate them into Ellama. I have seen your elisa package and follow a similar approach. Instead of info nodes I'm adding documents that I got from an API. At the moment I use the 'buffer element type for this. Looking at the code in Ellama I was wondering if we could change the closed set of context elements to a more open set, which users could customize.

So, instead of having those pcase forms checking for the fixed set of 'file, 'buffer, etc, maybe we could use generic functions for it. Something along:

(cl-defun ellama-context-element-add (element)
  "Add the ELEMENT to the Ellama context.")

(cl-defun ellama-context-element-render (element format)
  "Render the context ELEMENT in the given FORMAT.")

(cl-defun ellama-context-element-content (element)
  "Return the content of the context ELEMENT.")

(cl-defstruct ellama-buffer-context-element
  "A context element baked by a buffer."
  buffer-name)

(cl-defstruct ellama-url-context-element
  "A context element baked by a buffer."
  url)

That way, users of Ellama could provide their own context elements and control how they are rendered, acted upon, etc.

Wdyt?

s-kostyaev commented 3 months ago

Hi @r0man,

LGTM. I would like to make Elisa extendable and useful in many cases, not just for elisp and Emacs. So this will help.

r0man commented 3 months ago

Hi @s-kostyaev ,

ok cool. I can take a look at this when I finished my paperwork.

r0man commented 3 months ago

This has been done in https://github.com/s-kostyaev/ellama/pull/94