2.2.4 • Published 5 months ago

hypercode v2.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

WARNING: This npm package is currently in research/development mode. It is not recommended to use it for production code as the abstractions are subject to change. Use with caution!

Hypercode

Hypercode is a friendly npm package that lets you easily query language models and receive responses in various formats like strings, numbers, dates, or even custom types like tuples and records:

const howManySpeciesOfFrogsExistOnEarth = hyper.integer(
  "How many species of frogs exist on Earth?"
);
Â;
console.log(howManySpeciesOfFrogsExistOnEarth); // 7655

Getting Started

Step 1: Install Hypercode

Start by installing the Hypercode package through npm:

npm install hypercode

Step 2: Set your OpenAI API Key

In your .env file, set your OpenAI API Key:

OPENAI_API_KEY=your_api_key_here

Make sure to replace your_api_key_here with your actual OpenAI API key.

Alternatively, you can set the key yourself by calling the hyper.init method:

require("dotenv").config();
const hyper = require("hypercode");

hyper.init("API_KEY_HERE");

// Continue with other function calls

Step 3: Import Hypercode in Your Project

Import Hypercode in your JavaScript or TypeScript file.

const hyper = require("hypercode");

Step 4: Start Querying

Now you're ready to start querying language models with Hypercode!

Simple Tutorial Introduction

Let's begin by querying the capital of France and storing the answer in a variable:

const capital = hyper.string("What is the capital of France?");
console.log(capital); // "Paris"

Now let's get a little more fancy and get the coordinates of New York as a tuple:

const coordinates = hyper.tuple("What are the coordinates of New York?", [
  "number",
  "number",
]);
console.log(coordinates); // [40.7128, -74.0060]

Types in Hypercode

Primitive Types

  • string: Get a simple string answer.
    const color = hyper.string("What's the color of the sky?");
    console.log(color); // "blue"
  • integer: Get an integer answer.
    const days = hyper.integer("How many days are in a week?");
    console.log(days); // 7
  • float: Get a floating-point number answer.
    const piValue = hyper.float("What's the value of pi to the tenth digit?");
    console.log(piValue); // 3.1415926535
  • boolean: Get a true or false answer.
    const isEarthFlat = hyper.boolean("Is the Earth flat?");
    console.log(isEarthFlat); // false
  • array: Get an array as the answer.
    const primaryColors = hyper.array("Name three primary colors.");
    console.log(primaryColors); // ["red", "blue", "yellow"]
  • object: Get an object as the answer.
    const dogInfo = hyper.object("Tell me about dogs.");
    console.log(dogInfo); // { "type": "animal", "lifespan": "10-13 years" }
  • date: Get a date as the answer.
    const today = hyper.date("What is today's date?");
    console.log(today); // "2023-06-15"
  • datetime: Get a date and time as the answer.
    const currentDatetime = hyper.datetime("What is the current date and time?");
    console.log(currentDatetime); // "2023-06-15T08:30:00.000Z"
  • time: Get time as the answer.
    const currentTime = hyper.time("What time is it?");
    console.log(currentTime); // "08:30:00"
  • uuid: Get a universally unique identifier (UUID).
    const id = hyper.uuid("Generate a UUID that starts with '123'");
    console.log(id); // "123e4567-e89b-12d3-a456-426655440000"

COMING SOON: Complex Types

  • oneOf: Choose one of the provided options.
    const fruit = hyper.oneOf(["apple", "banana", "cherry"]);
    console.log(fruit); // "banana"
  • enum: Choose from an enumeration.
    const primaryColor = hyper.enum("Pick a primary color.", [
      "Red",
      "Green",
      "Blue",
    ]);
    console.log(primaryColor); // "Red"
  • tuple: Get an answer in the form of a tuple.
    const point = hyper.tuple("What is the coordinate of the origin?", [
      "number",
      "number",
    ]);
    console.log(point); // [0, 0]
  • record: Get an answer in the form of a record.
    const user = hyper.record("Tell me about user John Doe.", ["name", "age"]);
    console.log(user); // {name: "John Doe", age: 30}
  • optional: Get an answer that can either be of the specified type or undefined.
    const bonus = hyper.optional("What is the employee's bonus?", "number");
    console.log(bonus); // undefined
  • map: Get an answer in the form of a map with specified key and value types.
    const capitals = hyper.map(
      "List the capitals of France and Germany.",
      "string",
      "string"
    );
    console.log(capitals); // {"France": "Paris", "Germany": "Berlin"}

Custom Configuration using hypercode.config.js

Hypercode allows you to tailor its behavior by creating a configuration file named hypercode.config.js in the root directory of your project.

Here’s an example of what hypercode.config.js might look like:

module.exports = {
  model: "gpt-4-0613",
  maxTokens: 100,
  temperature: 0.7,
  topP: 0.9,
  retryAttempts: 3,
  errorHandling: "log",
  functionTimeout: 5000,
  logUsage: true,
};

Available Configuration Options

  • model: The OpenAI model to use (e.g., "gpt-3.5-turbo", "gpt-4-0613").
  • maxTokens: The maximum number of tokens to be generated by the model in a single response.
  • temperature: Controls the randomness of the output generated by the model. Higher values make output more random, while lower values make it more focused.
  • topP: Controls the diversity of the generated output by setting a threshold for token probability.
  • retryAttempts: Defines the number of retry attempts if the model does not return the expected format.
  • errorHandling: Options for handling errors returned from the API ("log", "throw", "silent").
  • functionTimeout: Maximum time (in milliseconds) the library should wait for the model to return a response.
  • logUsage: Enable or disable logging of API usage statistics (boolean).

Using the Configuration

Hypercode will automatically read and validate the configuration file when initialized. The configurations in hypercode.config.js are merged with any default configurations and settings passed through the hyper.init method.

If you provide conflicting settings through different methods, the precedence order is:

  1. Settings passed through the hyper.init method.
  2. Settings in hypercode.config.js.
  3. Default configurations.

This allows you to set general configurations through the file and override them for specific instances if needed.

2.2.4

5 months ago

2.2.3

5 months ago

1.1.1

6 months ago

1.1.0

6 months ago

2.2.1

6 months ago

0.1.0

6 months ago

2.2.0

6 months ago

2.2.2

6 months ago

0.0.9

6 months ago

0.0.8

6 months ago

2.1.0

6 months ago

0.0.7

6 months ago

2.0.0

6 months ago

0.0.6

6 months ago

0.0.5

9 months ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago