GithubHelp home page GithubHelp logo

calvinusesyourcode / instructor-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from instructor-ai/instructor-js

0.0 0.0 0.0 1.05 MB

structured extraction for llms

Home Page: https://instructor-ai.github.io/instructor-js/

License: MIT License

Shell 0.27% JavaScript 2.09% TypeScript 81.15% HTML 16.49%

instructor-js's Introduction

instructor-js

Structured extraction in Typescript, powered by llms, designed for simplicity, transparency, and control.


Twitter Follow Twitter Follow Documentation GitHub issues Discord

Dive into the world of Typescript-based structured extraction, by OpenAI's function calling API and Zod, typeScript-first schema validation with static type inference. Instructor stands out for its simplicity, transparency, and user-centric design. Whether you're a seasoned developer or just starting out, you'll find Instructor's approach intuitive and steerable.

Check us out in Python, Elixir and PHP.

If you want to port Instructor to another language, please reach out to us on Twitter we'd love to help you get started!

Usage

To check out all the tips and tricks to prompt and extract data, check out the documentation.

import Instructor from "@instructor-ai/instructor";
import OpenAI from "openai"
import { z } from "zod"

const oai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY ?? undefined,
  organization: process.env.OPENAI_ORG_ID ?? undefined
})

const client = Instructor({
  client: oai,
  mode: "FUNCTIONS"
})

const UserSchema = z.object({
  // Description will be used in the prompt
  age: z.number().describe("The age of the user"), 
  name: z.string()
})


// User will be of type z.infer<typeof UserSchema>
const user = await client.chat.completions.create({
  messages: [{ role: "user", content: "Jason Liu is 30 years old" }],
  model: "gpt-3.5-turbo",
  response_model: { 
    schema: UserSchema, 
    name: "User"
  }
})

console.log(user)
// { age: 30, name: "Jason Liu" }

Why use Instructor?

The question of using Instructor is fundamentally a question of why to use zod.

  1. Powered by OpenAI SDK — Instructor is powered by OpenAI's API. This means you can use the same API for both prompting and extraction across multiple providers that support the OpenAI API.

  2. Customizable — Zod is highly customizable. You can define your own validators, custom error messages, and more.

  3. Ecosystem Zod is the most widely used data validation library for Typescript.

  4. Battle Tested — Zod is downloaded over 24M times per month, and supported by a large community of contributors.

More Examples

If you'd like to see more check out our cookbook.

Installing Instructor is a breeze.

Contributing

If you want to help out, checkout some of the issues marked as good-first-issue or help-wanted. Found here. They could be anything from code improvements, a guest blog post, or a new cook book.

License

This project is licensed under the terms of the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.