Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0 Release #62

Merged
merged 12 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.3.0/schema.json",
"changelog": ["@changesets/changelog-github", { "repo": "jxnl/instructor-js" }],
"changelog": ["@changesets/changelog-github", { "repo": "instructor-ai/instructor-js" }],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"access": "public",
"baseBranch": "main",
"ignore": [],
"privatePackages": {
"version": true,
"version": false,
"tag": false
}
}
5 changes: 5 additions & 0 deletions .changeset/red-birds-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@instructor-ai/instructor": patch
---

V0 release
8 changes: 6 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish changesets
name: Publish

on:
pull_request:
Expand All @@ -9,13 +9,17 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
permissions: {} #reset
jobs:
publish:
if: github.repository == 'jxnl/instructor-js' && github.event.pull_request.merged == true && (startsWith(github.head_ref, 'changeset-release/main') || startsWith(github.head_ref, '_publish-trigger'))
if: github.repository == 'instructor-ai/instructor-js' && github.event.pull_request.merged == true && (startsWith(github.head_ref, 'changeset-release/main') || startsWith(github.head_ref, '_publish-trigger'))
permissions:
contents: write
pull-requests: write

name: Publish packages
runs-on: ubuntu-latest
environment: Publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}


steps:
- name: Checkout Repo
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create changeset release PR
name: RC PR

on:
push:
Expand All @@ -12,13 +12,16 @@ env:

jobs:
release:
if: github.repository == 'jxnl/instructor-js'
if: github.repository == 'instructor-ai/instructor-js'
permissions:
contents: write
pull-requests: write

name: Changeset Release
runs-on: ubuntu-latest
environment: Publish
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test-wf
name: Test
on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _Structured extraction in Typescript, powered by llms, designed for simplicity,

[![Twitter Follow](https://img.shields.io/twitter/follow/jxnlco?style=social)](https://twitter.com/jxnlco)
[![Documentation](https://img.shields.io/badge/docs-available-brightgreen)](https://jxnl.github.io/instructor-js)
[![GitHub issues](https://img.shields.io/github/issues/jxnl/instructor-js.svg)](https://github.com/jxnl/instructor-js/issues)
[![GitHub issues](https://img.shields.io/github/issues/instructor-ai/instructor-js.svg)](https://github.com/instructor-ai/instructor-js/issues)
[![Discord](https://img.shields.io/discord/1192334452110659664?label=discord)](https://discord.gg/CV8sPM5k5Y)

Dive into the world of Python-based structured extraction, by OpenAI's function calling API and Pydantic, the most widely used data validation library for Python. 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.
Expand Down Expand Up @@ -74,7 +74,7 @@ If you'd like to see more check out our [cookbook](examples/index.md).

## Contributing

If you want to help out, checkout some of the issues marked as `good-first-issue` or `help-wanted`. Found [here](https://github.com/jxnl/instructor-js/labels/good%20first%20issue). They could be anything from code improvements, a guest blog post, or a new cook book.
If you want to help out, checkout some of the issues marked as `good-first-issue` or `help-wanted`. Found [here](https://github.com/instructor-ai/instructor-js/labels/good%20first%20issue). They could be anything from code improvements, a guest blog post, or a new cook book.

## License

Expand Down
10 changes: 5 additions & 5 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ We would love for you to contribute to `Instructor-js`.

Theres a bunch of examples in the python version, including documentation here [python docs](https://jxnl.github.io/instructor/examples/)

If you want to contribute, please check out [issues](https://github.com/jxnl/instructor-js/issues/8)
If you want to contribute, please check out [issues](https://github.com/instructor-ai/instructor-js/issues/8)

## Issues

If you find a bug, please file an issue on [our issue tracker on GitHub](https://github.com/jxnl/instructor-js/issues).
If you find a bug, please file an issue on [our issue tracker on GitHub](https://github.com/instructor-ai/instructor-js/issues).

To help us reproduce the bug, please provide a minimal reproducible example, including a code snippet and the full error message.

Expand All @@ -20,9 +20,9 @@ To help us reproduce the bug, please provide a minimal reproducible example, inc

We welcome pull requests! There is plenty to do, and we are happy to discuss any contributions you would like to make.

If it is not a small change, please start by [filing an issue](https://github.com/jxnl/instructor-js/issues) first.
If it is not a small change, please start by [filing an issue](https://github.com/instructor-ai/instructor-js/issues) first.

If you need ideas, you can check out the [help wanted](https://github.com/jxnl/instructor-js/labels/help%20wanted) or [good first issue](https://github.com/jxnl/instructor-js/labels/good%20first%20issue) labels.
If you need ideas, you can check out the [help wanted](https://github.com/instructor-ai/instructor-js/labels/help%20wanted) or [good first issue](https://github.com/instructor-ai/instructor-js/labels/good%20first%20issue) labels.

# Contributors

Expand All @@ -36,7 +36,7 @@ If you need ideas, you can check out the [help wanted](https://github.com/jxnl/i
<!-- ALL-CONTRIBUTORS-LIST:END -->

<a href="https://github.com/jxnl/instructor/graphs/contributors">
<img src="https://contrib.rocks/image?repo=jxnl/instructor-js" />
<img src="https://contrib.rocks/image?repo=instructor-ai/instructor-js" />
</a>


Expand Down
2 changes: 1 addition & 1 deletion docs/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This page is under construction. Please check back later. Consider contributing to this page by opening a PR! Theres a bunch of examples in the python version, including documentation here [python docs](https://jxnl.github.io/instructor/examples/)

If you want to contribute, please check out [issues](https://github.com/jxnl/instructor-js/issues/8)
If you want to contribute, please check out [issues](https://github.com/instructor-ai/instructor-js/issues/8)



Expand Down
4 changes: 2 additions & 2 deletions docs/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ The [cookbooks](examples/index.md) are a great place to start. They contain a va

## :material-github: GitHub Discussions

[GitHub discussions](https://github.com/jxnl/instructor-js/discussions) are useful for asking questions, your question and the answer will help everyone.
[GitHub discussions](https://github.com/instructor-ai/instructor-js/discussions) are useful for asking questions, your question and the answer will help everyone.

## :material-github: GitHub Issues

[GitHub issues](https://github.com/jxnl/instructor-js/issues) are useful for reporting bugs or requesting new features.
[GitHub issues](https://github.com/instructor-ai/instructor-js/issues) are useful for reporting bugs or requesting new features.

## :material-twitter: Twitter

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _Structured extraction in Typescript, powered by llms, designed for simplicity,

[![Twitter Follow](https://img.shields.io/twitter/follow/jxnlco?style=social)](https://twitter.com/jxnlco)
[![Documentation](https://img.shields.io/badge/docs-available-brightgreen)](https://jxnl.github.io/instructor-js)
[![GitHub issues](https://img.shields.io/github/issues/jxnl/instructor-js.svg)](https://github.com/jxnl/instructor-js/issues)
[![GitHub issues](https://img.shields.io/github/issues/instructor-ai/instructor-js.svg)](https://github.com/instructor-ai/instructor-js/issues)

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.

Expand Down Expand Up @@ -73,7 +73,7 @@ If you'd like to see more check out our [cookbook](examples/index.md).

## Contributing

If you want to help out, checkout some of the issues marked as `good-first-issue` or `help-wanted`. Found [here](https://github.com/jxnl/instructor-js/labels/good%20first%20issue). They could be anything from code improvements, a guest blog post, or a new cook book.
If you want to help out, checkout some of the issues marked as `good-first-issue` or `help-wanted`. Found [here](https://github.com/instructor-ai/instructor-js/labels/good%20first%20issue). They could be anything from code improvements, a guest blog post, or a new cook book.

## License

Expand Down
2 changes: 1 addition & 1 deletion docs/overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
{% include ".icons/fontawesome/solid/star.svg" %}
</span>
us on
<a href="https://www.github.com/jxnl/instructor-js">
<a href="https://www.github.com/instructor-ai/instructor-js">
<span class="twemoji github">
{% include ".icons/fontawesome/brands/github.svg" %}
</span>
Expand Down
3 changes: 2 additions & 1 deletion examples/extract_user_stream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const extractionStream = await client.chat.completions.create({
messages: [{ role: "user", content: textBlock }],
model: "gpt-4-1106-preview",
response_model: {
schema: ExtractionValuesSchema
schema: ExtractionValuesSchema,
name: "value extraction"
},
max_retries: 3,
stream: true,
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ site_name: Instructor (JS)
site_author: Jason Liu
site_description: Enhancing OpenAI function calling with Zod
repo_name: instructor
repo_url: https://github.com/jxnl/instructor-js
repo_url: https://github.com/instructor-ai/instructor-js
site_url: https://jxnl.github.io/instructor-js/
edit_uri: edit/main/docs/
copyright: Copyright &copy; 2024 Jason Liu
Expand Down
33 changes: 19 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{
"name": "instructor-js",
"version": "0.0.1",
"name": "@instructor-ai/instructor",
"version": "0.0.0",
"description": "structured outputs for llms",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
},
"publishConfig": {
"access": "public"
},
"main": "./dist/instructor.js",
"module": "./dist/instructor.mjs",
"types": "./dist/instructor.d.ts",
"exports": {
".": {
"import": "./dist/instructor.mjs",
"require": "./dist/instructor.js"
},
"./*": "./dist/*.mjs"
},
"files": [
"dist/**"
],
"sideEffects": false,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "tsup",
Expand All @@ -28,7 +33,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/jxnl/instructor-js.git"
"url": "git+https://github.com/instructor-ai/instructor-js.git"
},
"keywords": [
"llm",
Expand All @@ -39,9 +44,9 @@
"author": "Jason Liu",
"license": "MIT",
"bugs": {
"url": "https://github.com/jxnl/instructor-js/issues"
"url": "https://github.com/instructor-ai/instructor-js/issues"
},
"homepage": "https://github.com/jxnl/instructor-js#readme",
"homepage": "https://github.com/instructor-ai/instructor-js#readme",
"dependencies": {
"schema-stream": "1.6.0",
"zod-to-json-schema": "^3.22.3",
Expand Down
19 changes: 14 additions & 5 deletions src/instructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,25 @@ class Instructor {
response_model,
...params
}: ChatCompletionCreateParamsWithModel<T>): ChatCompletionCreateParams => {
const jsonSchema = zodToJsonSchema(response_model.schema, {
name: "response_model",
const { schema, name = "response_model", description } = response_model
const safeName = name.replace(/[^a-zA-Z0-9]/g, "_").replace(/\s/g, "_")

const { definitions } = zodToJsonSchema(schema, {
name: safeName,
errorMessages: true
})

this.log("JSON Schema from zod: ", jsonSchema)
if (!definitions || !definitions?.[safeName]) {
console.warn("Could not extract json schema definitions from your schema", schema)
throw new Error("Could not extract json schema definitions from your schema")
}

this.log("JSON Schema from zod: ", definitions)

const definition = {
name: "response_model",
...jsonSchema.definitions?.response_model
name: safeName,
description,
...definitions[safeName]
}

const paramsForMode = MODE_TO_PARAMS[this.mode](definition, params, this.mode)
Expand Down
6 changes: 3 additions & 3 deletions src/oai/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function OAIBuildFunctionParams(definition, params) {
{
name: name,
description: description ?? undefined,
paramaters: definitionParams
parameters: definitionParams
}
]
}
Expand Down Expand Up @@ -52,7 +52,7 @@ export function OAIBuildMessageBasedParams(definition, params, mode) {
[MODE.JSON_SCHEMA]: {
response_format: {
type: "json_object",
schema: omit(["name"], definition)
schema: omit(["name", "description"], definition)
}
}
}
Expand All @@ -68,7 +68,7 @@ export function OAIBuildMessageBasedParams(definition, params, mode) {
role: "system",
content: `
Given a user prompt, you will return fully valid JSON based on the following description and schema.
You will return no other prose. You will take into account any descriptions or required paramaters within the schema
You will return no other prose. You will take into account any descriptions or required parameters within the schema
and return a valid and fully escaped JSON object that matches the schema and those instructions.

description: ${definition?.description}
Expand Down
2 changes: 1 addition & 1 deletion tests/mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MODE } from "@/constants/modes"

const models_latest = ["gpt-3.5-turbo-1106", "gpt-4-1106-preview"]
const models_old = ["gpt-3.5-turbo", "gpt-4"]
const models_anyscale = ["mistralai/Mixtral-8x7B-Instruct-v0.1"]
const models_anyscale = ["Open-Orca/Mistral-7B-OpenOrca"]

const createTestCases = (): { model: string; mode: MODE }[] => {
const { FUNCTIONS, JSON_SCHEMA, ...rest } = MODE
Expand Down