nomic-ai / gpt4all

GPT4All: Run Local LLMs on Any Device. Open-source and available for commercial use.
https://nomic.ai/gpt4all
MIT License
69.65k stars 7.62k forks source link

DOC: NodeJS Example Using API Embedding #1851

Closed zwilch closed 6 months ago

zwilch commented 8 months ago

Issue with current documentation:

I can not find a working nodejs API example for using Embedding. I have figured out, I should use "all-MiniLM-L6-v2-f16.gguf"

I stuck with that:

import { OpenAI } from 'openai';
const API_BASE   ="http://localhost:4891/v1"

export const run = async () => {
const openai = new OpenAI({
  apiKey: "not needed for a local LLM",
  baseURL:API_BASE+'/v1'
});

const embedding = await openai.embeddings.create({
model: "all-MiniLM-L6-v2-f16.gguf",
input: "The quick brown fox jumped over the lazy dog"
//encoding_format: “float”,
});

console.log(embedding);
}//end run();

run();//start

Idea or request for content:

Make a working example code for nodejs to use embedding API.

jacoobes commented 8 months ago

https://github.com/nomic-ai/gpt4all/blob/main/gpt4all-bindings/typescript/spec/embed.mjs

jacoobes commented 8 months ago

youll have to change the .bin ending to .gguf but essentially it is the same

zwilch commented 8 months ago

npm install gpt4all

import { loadModel, createEmbedding } from 'gpt4all'
const embedder = await loadModel("all-MiniLM-L6-v2-f16.gguf", { verbose: true, type: 'embedding'})
console.log(createEmbedding(embedder, "Hallo Welt!"))

it is working

any idea how to get it working with import {OpenAI} from "openai" ?

jacoobes commented 8 months ago

Openai and gpt4all are two different projects

zwilch commented 8 months ago

Ja @jacoobes richtig erkannt, es ist wirklich schlecht, dass man von seiner NodeJS APP nicht durch Ändern der URL einfach mal auf das langsame lokal laufende GPT4ALL Modell wechseln kann.