diff --git a/.changeset/config.json b/.changeset/config.json index 15320837..4d63c8ac 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -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 } } diff --git a/.changeset/red-birds-march.md b/.changeset/red-birds-march.md new file mode 100644 index 00000000..273c32b0 --- /dev/null +++ b/.changeset/red-birds-march.md @@ -0,0 +1,5 @@ +--- +"@instructor-ai/instructor": patch +--- + +V0 release diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 99787459..e8a07507 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish changesets +name: Publish on: pull_request: @@ -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 diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml index 991fb138..9a1dd432 100644 --- a/.github/workflows/release-pr.yml +++ b/.github/workflows/release-pr.yml @@ -1,4 +1,4 @@ -name: Create changeset release PR +name: RC PR on: push: @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e68f751..d0dc8c6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test-wf +name: Test on: push: branches: diff --git a/README.md b/README.md index cd51767b..190e737f 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/docs/contributing.md b/docs/contributing.md index 5a323a4d..4532730f 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -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. @@ -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 @@ -36,7 +36,7 @@ If you need ideas, you can check out the [help wanted](https://github.com/jxnl/i - + diff --git a/docs/examples/index.md b/docs/examples/index.md index cbe01648..693360f7 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -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) diff --git a/docs/help.md b/docs/help.md index 7be0b9f1..8aeb0e8d 100644 --- a/docs/help.md +++ b/docs/help.md @@ -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 diff --git a/docs/index.md b/docs/index.md index a9a7e0f1..3ceffd37 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. @@ -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 diff --git a/docs/overrides/main.html b/docs/overrides/main.html index bae22937..4d6412f2 100644 --- a/docs/overrides/main.html +++ b/docs/overrides/main.html @@ -11,7 +11,7 @@ {% include ".icons/fontawesome/solid/star.svg" %} us on - + {% include ".icons/fontawesome/brands/github.svg" %} diff --git a/examples/extract_user_stream/index.ts b/examples/extract_user_stream/index.ts index 4e5e964b..0f0813de 100644 --- a/examples/extract_user_stream/index.ts +++ b/examples/extract_user_stream/index.ts @@ -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, diff --git a/mkdocs.yml b/mkdocs.yml index 40ea5eb9..13841fc3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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 © 2024 Jason Liu diff --git a/package.json b/package.json index 50fa56cb..aa63aaba 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", diff --git a/src/instructor.ts b/src/instructor.ts index 0dd2184e..eafad33a 100644 --- a/src/instructor.ts +++ b/src/instructor.ts @@ -246,16 +246,25 @@ class Instructor { response_model, ...params }: ChatCompletionCreateParamsWithModel): 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) diff --git a/src/oai/params.ts b/src/oai/params.ts index 54a1a706..ad05821d 100644 --- a/src/oai/params.ts +++ b/src/oai/params.ts @@ -15,7 +15,7 @@ export function OAIBuildFunctionParams(definition, params) { { name: name, description: description ?? undefined, - paramaters: definitionParams + parameters: definitionParams } ] } @@ -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) } } } @@ -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} diff --git a/tests/mode.test.ts b/tests/mode.test.ts index 26fd3cdf..4caec77f 100644 --- a/tests/mode.test.ts +++ b/tests/mode.test.ts @@ -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