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

initial release #1

Merged
merged 1 commit into from
Aug 19, 2023
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
8 changes: 8 additions & 0 deletions .changeset/README.md
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)
11 changes: 11 additions & 0 deletions .changeset/config.json
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": []
}
5 changes: 5 additions & 0 deletions .changeset/strange-ligers-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'function-gpt': major
---

Initial release with minimal functionality.
7 changes: 7 additions & 0 deletions .editorconfig
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
38 changes: 38 additions & 0 deletions .eslintignore
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
25 changes: 25 additions & 0 deletions .eslintrc.json
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": "^_"
}
]
}
}
10 changes: 10 additions & 0 deletions .gitattributes
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
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
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
49 changes: 49 additions & 0 deletions .github/workflows/publish.yml
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 }}
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
auto-install-peers=true
38 changes: 38 additions & 0 deletions .prettierignore
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
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2
}
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
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
```
66 changes: 65 additions & 1 deletion README.md
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.
2 changes: 2 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './src/decorators.js';
export * from './src/session.js';
Loading