8000 initial commit · mirnes-cajlakovic/openai-schemas@b6ce13c · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mirnes-cajlakovic committed Dec 4, 2023
0 parents commit b6ce13c
Show file tree
Hide file tree
Showing 81 changed files with 4,840 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_DOC_URL="https://platform.openai.com/docs/api-reference/chat/create"
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "standard",
"env": {
"browser": true,
"mocha": true
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*.sw*
node_modules
package-lock.json
coverage
.nyc_output
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@mirnes-cajlakovic:registry=https://npm.pkg.github.com
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# openai-schemas
[![npm version](https://badge.fury.io/js/openai-schemas.svg)](https://badge.fury.io/js/openai-schemas)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com)

This is a collection json schema objects for validating openai endpoints requests and responses. This library also contains tools for scraping new schemas from the official api docs on openai.com when they are updated.

## Installation
To install the package, use the following command:
```
npm install openai-schemas
```

## Usage
This package can be used in several ways to access the `create` function within the `chat` schema. Below are the methods to require or import this function:

##### Method 1
Using destructuring at the top level:
```javascript
const { create } = require('openai-schemas').schemas.chat;
console.log(create);
```

##### Method 2
Destructuring one level deeper:
```javascript
const { chat: { create } } = require('openai-schemas').schemas;
console.log(create);
```

##### Method 3
Destructuring with full path:
```javascript
const { schemas: { chat: { create } } } = require('openai-schemas');
console.log(create);
```
5 changes: 5 additions & 0 deletions bin/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { Update } = require('../index')

Update.updateSchemas()
.then((path) => console.log('Schemas have been updated.\n', path))
.catch((error) => console.log('Schemas failed to update.\n', error))
36 changes: 36 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require('fs')
const path = require('path')

const schemasIndex = []
const schemasPath = path.join(__dirname, 'schemas')
fs.readdirSync(schemasPath)
.filter((dir) => {
return fs.statSync(path.join(schemasPath, dir)).isDirectory()
})
.map((dir) => {
const dirPath = path.join(schemasPath, dir)
fs.readdirSync(dirPath)
.filter((file) => {
return path.extname(file) === '.json'
})
.map((file) => {
const name = path.basename(file, path.extname(file))
schemasIndex.push({ name, dir, src: path.join('./schemas/', dir, name) })
})
})

const modules = {
Parse: require('./src/Parse'),
Scrape: require('./src/Scrape'),
Update: require('./src/Update'),
schemas: {}
}

for (const schema of schemasIndex) {
if (!modules.schemas[schema.dir]) {
modules.schemas[schema.dir] = {}
}
modules.schemas[schema.dir][schema.name] = require('./' + schema.src)
}

module.exports = modules
55 changes: 55 additions & 0 deletions package.json 10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "openai-schemas",
"version": "1.0.0",
"description": "This is a collection json schema objects for validating openai endpoints requests and responses. This library also contains tools for scraping new schemas from the official api docs on openai.com when they are updated.",
"keywords": [
"openai",
"openai-api",
"machine-learning",
"artificial-intelligence",
"chatgpt",
"chat-gpt",
"gpt",
"gpt-3",
"gpt-4",
"ai",
"agi",
"node",
"node.js",
"json",
"schemas"
],
"author": "Mirnes Cajlakovic",
"license": "MIT",
"main": "index.js",
"repository": {
"type": "git",
"url": "git@github.com:mirnes-cajlakovic/openai-schemas.git"
},
"publishConfig": {
"@mirnes-cajlakovic:registry": "https://npm.pkg.github.com/"
},
"scripts": {
"update": "node -r dotenv/config bin/update.js",
"lint": "eslint src/ test/",
"test": "npm run lint && nyc --reporter=html --reporter=text mocha",
"coverage": "nyc check-coverage --lines 100 --branches 100 --functions 100 --statements 100"
},
"dependencies": {
"puppeteer": "^21.5.2"
},
"devDependencies": {
"chai": "^4.3.10",
"dotenv": "^16.3.1",
"eslint": "^8.55.0",
"eslint-config-standard": "^17.1.0",
"jsdom": "^23.0.1",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"sinon": "^17.0.1"
},
"nyc": {
"include": "src/"
}
}
106 changes: 106 additions & 0 deletions schemas/assistants/createAssistant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"title": "assistants/createAssistant",
"description": "Create an assistant with a model and instructions.",
"type": [
"object"
],
"properties": {
"model": {
"type": [
""
],
"description": "ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them."
},
"name": {
"type": [
"string",
"null"
],
"description": "The name of the assistant. The maximum length is 256 characters."
},
"description": {
"type": [
"string",
"null"
],
"description": "The description of the assistant. The maximum length is 512 characters."
},
"instructions": {
"type": [
"string",
"null"
],
"description": "The system instructions that the assistant uses. The maximum length is 32768 characters."
},
"tools": {
"type": [
"array"
],
"description": "A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, retrieval, or function.",
"items": {
"oneOf": [
{
"title": "Code interpreter tool",
"type": [
"object"
],
"properties": {
"type": {
"type": [
"string"
],
"description": "The type of tool being defined: code_interpreter"
}
}
},
{
"title": "Retrieval tool",
"type": [
"object"
],
"properties": {
"type": {
"type": [
"string"
],
"description": "The type of tool being defined: retrieval"
}
}
},
{
"title": "Function tool",
"type": [
"object"
],
"properties": {
"type": {
"type": [
"string"
],
"description": "The type of tool being defined: function"
},
"function": {
"type": [
"object"
],
"description": null
}
}
}
]
}
},
"file_ids": {
"type": [
"array"
],
"description": "A list of file IDs attached to this assistant. There can be a maximum of 20 files attached to the assistant. Files are ordered by their creation date in ascending order."
},
"metadata": {
"type": [
"map"
],
"description": "Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maxium of 512 characters long."
}
}
}
15 changes: 15 additions & 0 deletions schemas/assistants/createAssistantFile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "assistants/createAssistantFile",
"description": "Create an assistant file by attaching a File to an assistant.",
"type": [
"object"
],
"properties": {
"assistant_id": {
"type": [
"string"
],
"description": "The ID of the assistant for which to create a File."
}
}
}
15 changes: 15 additions & 0 deletions schemas/assistants/deleteAssistant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "assistants/deleteAssistant",
"description": "Delete an assistant.",
"type": [
"object"
],
"properties": {
"assistant_id": {
"type": [
"string"
],
"description": "The ID of the assistant to delete."
}
}
}
21 changes: 21 additions & 0 deletions schemas/assistants/deleteAssistantFile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"title": "assistants/deleteAssistantFile",
"description": "Delete an assistant file.",
"type": [
"object"
],
"properties": {
"assistant_id": {
"type": [
"string"
],
"description": "The ID of the assistant that the file belongs to."
},
"file_id": {
"type": [
"string"
],
"description": "The ID of the file to delete."
}
}
}
32 changes: 32 additions & 0 deletions schemas/assistants/fileObject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"title": "assistants/fileObject",
"type": [
"object"
],
"properties": {
"id": {
"type": [
"string"
],
"description": "The identifier, which can be referenced in API endpoints."
},
"object": {
"type": [
"string"
],
"description": "The object type, which is always assistant.file."
},
"created_at": {
"type": [
"integer"
],
"description": "The Unix timestamp (in seconds) for when the assistant file was created."
},
"assistant_id": {
"type": [
"string"
],
"description": "The assistant ID that the file is attached to."
}
}
}
15 changes: 15 additions & 0 deletions schemas/assistants/getAssistant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"title": "assistants/getAssistant",
"description": "Retrieves an assistant.",
"type": [
"object"
],
"properties": {
"assistant_id": {
"type": [
"string"
],
"description": "The ID of the assistant to retrieve."
}
}
}
21 changes: 21 additions & 0 deletions schemas/assistants/getAssistantFile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"title": "assistants/getAssistantFile",
"description": "Retrieves an AssistantFile.",
"type": [
"object"
],
"properties": {
"assistant_id": {
"type": [
"string"
],
"description": "The ID of the assistant who the file belongs to."
},
"file_id": {
"type": [
"string"
],
"description": "The ID of the file we're getting."
}
}
}
Loading

0 comments on commit b6ce13c

Please sign in to comment.
0