ad4m icon indicating copy to clipboard operation
ad4m copied to clipboard

Local AI model inference

Open lucksus opened this issue 5 months ago • 0 comments

This adds AI model inference to ADAM, including downloading and managing of models from Huggingface, registering tasks and prompting models - based on Kalosm.

As a first step, this PR only focusses on managing and making available a couple of hard-coded models, but introducing an new section "AI" to the Ad4mClient. Other, future PRs will add the ability to have the user select and manage the exact models (https://github.com/coasys/ad4m/pull/504), as well as registering external modals via API, and UI in the ADAM Launcher for all of this.

New AI interface functions in Ad4mClient

This introduced 3 different kinds of model interactions that ADAM provides to apps via it's interface

Language processing with LLMs via tasks

const task = await ad4mClient.ai.addTask(
  //Model name, currently irrelevant with hard-coded model,
  "Llama", 
  //System prompt
  "You analyse incoming text for topics and respond with a JSON array including the topic names", 
  // Examples
  [
    {
      input: "Hey guys, how is it going?",
      output: '["greeting"]'
    },
    {
      input: "I really want to try the new Synergy plugin in Flux",
      output: '["testing", "Synergy", "Flux"]'
    },
  ]
);

This spawns a session of the given model and configures it with the prompt and the examples, so that subsequently it can be run with:

const answer = await ad4mClient.ai.prompt(task.taskId, "Hello there, yeah I also would like to test that plugin!")

Emedding of text

const vector = await ad4mClient.ai.embed("Bert", "This is a test string");

Transcription of audio

const streamId = await ad4mClient.ai.openTranscriptionStream("Whisper", (text) => {
  console.log(text);
  });
  
// Feed raw sample data (float 32)
await ad4mClient.ai.feedTranscriptionStream(streamId, [0, 10, 20, 30]);

Progress

  • [x] ADAM interface/client definitions
  • [x] Task CRUD
  • [x] Task execution
  • [x] Embedding vectors
  • [ ] Audio transcription

lucksus avatar Sep 05 '24 10:09 lucksus