npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fore-ai

v0.0.4

Published

fore client library

Downloads

520

Readme

The fore client package

The foresight library within fore SDK allows you to easily evaluate the performance of your LLM system based on a variety of metrics.

You can try out foresight for free at https://foresight.foreai.co.

Quick start

  1. Install the package using npm:

    npm install fore-ai
    • Get started with the following lines:
    const { Foresight } = require("fore-ai");
    
    const foresight = new Foresight({ apiToken: "<YOUR_API_TOKEN>" });
    
    await foresight.log({
    	query: "What is the easiest programming language?",
    	response: "Python",
    	contexts: ["Python rated the easiest programming language"],
    	tag: "my_awesome_experiment",
    });
    
    // You can add more such queries using foresight.log
    // ....
    
    await foresight.flush();
    • Or alternatively to curate your evalsets and run regular evals against them do:
    const { Foresight, MetricType } = require("fore-ai");
    
    const foresight = new Foresight({ apiToken: "<YOUR_API_TOKEN>" });
    
    const evalset = await foresight.createSimpleEvalset({
    	evalsetId: "programming-languages",
    	queries: [
    		"hardest programming language?",
    		"easiest programming language?",
    	],
    	referenceAnswers: ["Malbolge", "Python"],
    });
    
    const runConfig = {
    	evalsetId: "programming-languages",
    	experimentId: "my-smart-llm",
    	metrics: [MetricType.GROUNDEDNESS, MetricType.REFERENCE_FACT_RECALL],
    };
    
    const myGenerateGn = (query) => {
    	// Do the LLM processing with your model...
    	// Here is some demo code:
    
    	return {
    		generatedResponse: query.includes("hardest")
    			? "Malbolge"
    			: "Python",
    		contexts: [
    			"Malbolge is the hardest language",
    			"Python is the easiest language",
    		],
    	};
    };
    
    await foresight.generateAnswersAndRunEval({
    	generateFn: myGenerateGn,
    	runConfig,
    });

Metrics

Groundedness

Depends on:

  • LLM's generated response;
  • Context used for generating the answer.

The metric answers the question: Is the response based on the context and nothing else?

This metric estimates the fraction of facts in the generated response that can be found in the provided context.

Example:

  • Context: The front door code has been changed from 1234 to 7945 due to security reasons.
  • Q: What is the current front door code?
  • A1: 7945. [groundedness score = 0.9]
  • A2: 0000. [groundedness score = 0.0]
  • A3: 1234. [groundedness score = 0.04]

Reference Fact Recall

Depends on:

  • A user query;
  • An LLM's generated response to be evaluated;
  • A reference response to compare the generated response with.

The metric answers the question: How many facts from the reference answer does the candidate answer mention?

This metric checks that the answer given by the LLM is mentioning all the facts listed in the reference answer. Additional information is not penalised.

Example:

  • Question: Give me a checklist to prepare for my hiking trip to the mountains.
  • Reference response: You should bring your a water bottle, hiking shoes and sunscreen.
  • Candidate answer 1: Here is a list of items to bring: 1) hiking shoes; 2) a water bottle. [reference fact recall score = 0.67]
  • Candidate answer 2: Here is a list of items to bring: 1) backpack with food; 2) hiking shoes; 3) a water bottle.[reference fact recall score = 0.67]
  • Candidate answer 3: Here is a list of items to bring: 1) backpack with food; 2) hiking shoes; 3) a water bottle; 4) sunscreen.[reference fact recall score = 1.0]