# @chatjet-ai/core

> `@chatjet-ai/core` is the core library for Chatjet, a conversational AI component for your website, trained on your data.

Latest version **0.5.3** (published 2023-06-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chatjet-ai/core
pnpm add @chatjet-ai/core
yarn add @chatjet-ai/core
bun add @chatjet-ai/core
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.3 |
| Published | 2023-06-19 |
| First published | 2023-06-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | chatjet-ai |

## Links

- npm: https://www.npmjs.com/package/@chatjet-ai/core
- Repository: https://github.com/motifland/markprompt-js
- Homepage: https://github.com/motifland/markprompt-js#readme
- Issues: https://github.com/motifland/markprompt-js/issues
- npm.io page: https://npm.io/package/@chatjet-ai/core

## Dependencies (1)

- [@chatjet-ai/docusaurus-theme-search](https://npm.io/package/@chatjet-ai/docusaurus-theme-search.md) ^0.2.3

## Recent versions

- 0.5.3 (latest) — 2023-06-19
- 0.5.1 — 2023-06-17

## README

# `@chatjet-ai/core`

`@chatjet-ai/core` is the core library for Chatjet, a conversational AI component for your website, trained on your data.

It contains core functionality for Chatjet and allows you to build abstractions on top of it.

<br />
<p align="center">
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@chatjet-ai/core">
    <img alt="" src="https://badgen.net/npm/v/@chatjet-ai/core">
  </a>
  <a aria-label="License" href="https://github.com/motifland/markprompt-js/blob/main/packages/core/LICENSE">
    <img alt="" src="https://badgen.net/npm/license/@chatjet-ai/core">
  </a>
  <a aria-label="Coverage" href="https://app.codecov.io/gh/motifland/markprompt-js/tree/main/packages%2Fcore">
    <img alt="" src="https://codecov.io/gh/motifland/markprompt-js/branch/main/graph/badge.svg" />
  </a>
</p>

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
  - [`submitPrompt(prompt, projectKey, onAnswerChunk, onReferences, onError, options?)`](#submitpromptprompt-projectkey-onanswerchunk-onreferences-onerror-options)
    - [Arguments](#arguments)
    - [Options](#options)
    - [Returns](#returns)
- [Community](#community)
- [Authors](#authors)
- [License](#license)

## Installation

```sh
npm install @chatjet-ai/core
```

In browsers with [esm.sh](https://esm.sh):

```html
<script type="module">
  import { submitPrompt } from 'https://esm.sh/@chatjet-ai/core';
</script>
```

## Usage

```js
import { submitPrompt } from '@chatjet-ai/core';

// user input
const prompt = 'Hello, Markprompt!';
// can be obtained in your project settings on markprompt.com
const projectKey = '<project-key>';

// called when a new answer chunk is available
// should be concatenated to previous chunks
function onAnswerChunk(chunk) {
  // process an answer chunk
}

// called when references are available
function onReferences(references) {
  // process references
}

// called when submitPrompt encounters an error
const onError(error) {
  // handle errors
}

// optional options, defaults displayed
const options = {
  model: 'gpt-3.5-turbo', // supports all OpenAI models
  iDontKnowMessage: 'Sorry, I am not sure how to answer that.',
  completionsUrl: 'https://chatjet.co/v1/completions', // or your own completions API endpoint,
};

await submitPrompt(prompt, projectKey, onAnswerChunk, onReferences, onError, options);
```

## API

### `submitPrompt(prompt, projectKey, onAnswerChunk, onReferences, onError, options?)`

Submit a prompt the the Markprompt API.

#### Arguments

- `prompt` (`string`): Prompt to submit to the model
- `projectKey` (`string`): The key of your project
- `onAnswerChunk` (`function`): Answers come in via streaming. This function is called when a new chunk arrives
- `onReferences` (`function`): This function is called when a chunk includes references.
- `onError` (`function`): called when an error occurs
- [`options`](#options) (`object`): Optional options object

#### Options

- `completionsUrl` (`string`): URL at which to fetch completions
- `iDontKnowMessage` (`string`): Message returned when the model does not have an answer
- `model` (`OpenAIModelId`): The OpenAI model to use
- `promptTemplate` (`string`): The prompt template
- `temperature` (`number`): The model temperature
- `topP` (`number`): The model top P
- `frequencyPenalty` (`number`): The model frequency penalty
- `presencePenalty` (`number`): The model present penalty
- `maxTokens` (`number`): The max number of tokens to include in the response
- `sectionsMatchCount` (`number`): The number of sections to include in the prompt context
- `sectionsMatchThreshold` (`number`): The similarity threshold between the input question and selected sections
- `signal` (`AbortSignal`): AbortController signal

#### Returns

A promise that resolves when the response is fully handled.

## Community

- [Twitter @chatjet-ai](https://twitter.com/markprompt)
- [Twitter @motifland](https://twitter.com/motifland)
- [Discord](https://discord.gg/MBMh4apz6X)

## Authors

This library is created by the team behind [Motif](https://motif.land)
([@motifland](https://twitter.com/motifland)).

## License

[MIT](./LICENSE) © [Motif](https://motif.land)

---
_Source: https://npm.io/package/@chatjet-ai/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
