-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2f4788
commit 4a5b3af
Showing
24 changed files
with
5,132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "restricted", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'function-gpt': major | ||
--- | ||
|
||
Initial release with minimal functionality. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[*] | ||
indent_style=space | ||
indent_size=2 | ||
tab_width=2 | ||
end_of_line=lf | ||
insert_final_newline=false | ||
charset=utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
**/*.log | ||
**/.DS_Store | ||
*. | ||
.vscode/settings.json | ||
.history | ||
.yarn | ||
bazel-* | ||
bazel-bin | ||
bazel-out | ||
bazel-qwik | ||
bazel-testlogs | ||
coverage | ||
dist | ||
dist-dev | ||
lib | ||
lib-types | ||
etc | ||
external | ||
node_modules | ||
temp | ||
tsc-out | ||
tsdoc-metadata.json | ||
target | ||
output | ||
rollup.config.js | ||
build | ||
.cache | ||
.vscode | ||
.rollup.cache | ||
tsconfig.tsbuildinfo | ||
vite.config.ts | ||
*.spec.tsx | ||
*.spec.ts | ||
.netlify | ||
pnpm-lock.yaml | ||
package-lock.json | ||
yarn.lock | ||
server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], | ||
"plugins": ["simple-import-sort"], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"rules": { | ||
"no-console": [ | ||
"error", | ||
{ | ||
"allow": ["warn", "error"] | ||
} | ||
], | ||
"simple-import-sort/imports": "warn", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"argsIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_", | ||
"caughtErrorsIgnorePattern": "^_" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
* text=auto | ||
|
||
*.ts text eol=lf | ||
*.tsx text eol=lf | ||
*.js text eol=lf | ||
*.jsx text eol=lf | ||
*.mjs text eol=lf | ||
*.cjs text eol=lf | ||
*.json text eol=lf | ||
*.md text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: build | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu | ||
node-version: | ||
- '16.x' | ||
|
||
name: build | ||
|
||
runs-on: ${{ matrix.os }}-latest | ||
|
||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: install pnpm dependencies | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8.6.12 | ||
run_install: true | ||
|
||
- name: lint | ||
run: pnpm lint | ||
|
||
- name: build | ||
run: pnpm build | ||
|
||
- name: test | ||
run: pnpm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: publish package to npmjs | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
publish: | ||
name: publish | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: install pnpm dependencies | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8.6.12 | ||
run_install: true | ||
|
||
- name: lint | ||
run: pnpm lint | ||
|
||
- name: build | ||
run: pnpm build | ||
|
||
- name: test | ||
run: pnpm test | ||
|
||
- name: codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
|
||
- name: publish to npm | ||
id: changesets | ||
uses: changesets/action@v1 | ||
with: | ||
publish: pnpm release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
engine-strict=true | ||
auto-install-peers=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
**/*.log | ||
**/.DS_Store | ||
*. | ||
.vscode/settings.json | ||
.history | ||
.yarn | ||
bazel-* | ||
bazel-bin | ||
bazel-out | ||
bazel-qwik | ||
bazel-testlogs | ||
coverage | ||
dist | ||
dist-dev | ||
lib | ||
lib-types | ||
etc | ||
external | ||
node_modules | ||
temp | ||
tsc-out | ||
tsdoc-metadata.json | ||
target | ||
output | ||
rollup.config.js | ||
build | ||
.cache | ||
.vscode | ||
.rollup.cache | ||
tsconfig.tsbuildinfo | ||
vite.config.ts | ||
*.spec.tsx | ||
*.spec.ts | ||
.netlify | ||
pnpm-lock.yaml | ||
package-lock.json | ||
yarn.lock | ||
server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "all", | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"tabWidth": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
This libray is open-source with MIT license. Contribution is highly appreciated! | ||
|
||
## Package manager | ||
|
||
This repository uses pnpm as the package manager. If you don't have pnpm installed, you can install it with npm: | ||
|
||
```bash | ||
npm install -g pnpm | ||
``` | ||
|
||
Read more about pnpm [here](https://pnpm.io/). | ||
|
||
## Install dependencies | ||
|
||
Once you have pnpm setup, run the following command to install dependencies. | ||
|
||
```bash | ||
pnpm install | ||
``` | ||
|
||
## Changeset | ||
|
||
This repository uses [changesets](https://github.com/changesets/changesets) to manage versioning and changelog. | ||
|
||
Every pull request should have a changeset associated with it. To create a changeset, run the following command: | ||
|
||
```bash | ||
pnpm changeset | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
# function-gpt | ||
# Function-GPT | ||
|
||
> This is a typescript library that helps handle [function calling](https://platform.openai.com/docs/guides/gpt/function-calling) with OpenAI's ChatGPT API. | ||
[![NPM](https://img.shields.io/npm/v/function-gpt.svg)](https://www.npmjs.com/package/function-gpt) [![Build Status](https://github.com/atinylittleshell/function-gpt/actions/workflows/publish.yml/badge.svg)](https://github.com/atinylittleshell/function-gpt/actions/workflows/publish.yml) [![MIT License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/atinylittleshell/function-gpt/blob/main/license) | ||
|
||
- Requires typescript | ||
- Leverages the official [openai](https://www.npmjs.com/package/openai) npm package for communicating with OpenAI's API | ||
- Automatically generate function calling JSON schema from decorated typescript classes | ||
- Automatically parse function calling response | ||
- Automatically call functions and send back results to OpenAI | ||
|
||
## Example | ||
|
||
```typescript | ||
// First create your own class that extends ChatGPTSession. | ||
class BrowseSession extends ChatGPTSession { | ||
// Define functions that you want to provide to ChatGPT for function calling. | ||
// Decorate each function with @gptFunction to provide necessary metadata. | ||
// The function should accept a single parameter that is a typed object. | ||
@gptFunction('make http request to a url and return its html content', BrowseParams) | ||
async browse(params: BrowseParams) { | ||
const response = await fetch(params.url); | ||
return await response.text(); | ||
} | ||
} | ||
|
||
// Define the type of the input parameter for functions above. | ||
class BrowseParams { | ||
// Decorate each field with @gptObjectField to provide necessary metadata. | ||
@gptObjectField('string', 'url of the web page to browse', true) | ||
public url: string = ''; | ||
} | ||
|
||
const session = new BrowseSession(); | ||
const response = await session.send('count characters in the html content of https://www.google.com.'); | ||
|
||
// BrowseSession will first call OpenAI's ChatGPT API with the above prompt | ||
// along with metadata about the browse function. | ||
|
||
// OpenAI's ChatGPT API will then return a function calling response that | ||
// asks for making a call to the browse function. | ||
|
||
// BrowseSession will then call the browse function with the parameters | ||
// specified in OpenAI's function calling response, and then send back the | ||
// result to OpenAI's ChatGPT API. | ||
|
||
// OpenAI's ChatGPT API will then return a message that contains the | ||
// chat response. | ||
expect(response).toBe('There are 4096 characters in the html content of https://www.google.com/.'); | ||
``` | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install function-gpt --save | ||
# or | ||
yarn add function-gpt | ||
# or | ||
pnpm add function-gpt | ||
``` | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! See [CONTRIBUTING.md](./CONTRIBUTING.md) for more info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './src/decorators.js'; | ||
export * from './src/session.js'; |
Oops, something went wrong.