Skip to content

Commit

Permalink
feat(thread): emulate the Assistants API using Chat Completion and Fu…
Browse files Browse the repository at this point in the history
…nction Calling
  • Loading branch information
paztek committed Dec 8, 2023
1 parent 62ea77d commit ef04001
Show file tree
Hide file tree
Showing 23 changed files with 3,312 additions and 165 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AZURE_OPENAI_API_KEY=
AZURE_OPENAI_ENDPOINT=
AZURE_OPENAI_DEPLOYMENT_NAME=
6 changes: 6 additions & 0 deletions .idea/jsLinters/eslint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/prettier.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations/examples_insurance.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
[![Package minified & gzipped size](https://badgen.net/bundlephobia/minzip/llobotomy-azure)](https://bundlephobia.com/package/llobotomy-azure)
[![Package dependency count](https://badgen.net/bundlephobia/dependency-count/reactllobotomy-azure)](https://bundlephobia.com/package/llobotomy-azure)

This library is a temporary solution for those of us who are using Azure Open AI APIs instead of the public Open AI APIs.
At the time of this writing, the Azure OpenAI API doesn't expose the Assistants API so we're emulating it using the other APIs (mainly Chat Completions with Function Calling).

The library aims at having roughly the same public API as my other NPM package [LLobotoMy](https://github.com/paztek/llobotomy).

## Installation

This library is published in the NPM registry and can be installed using any compatible package manager.
Expand All @@ -17,23 +22,6 @@ npm install llobotomy-azure --save
yarn add llobotomy-azure
```

### Installation from CDN

This module has an UMD bundle available through JSDelivr and Unpkg CDNs.

```html
<!-- For UNPKG use the code below. -->
<script src="https://unpkg.com/llobotomy-azure"></script>

<!-- For JSDelivr use the code below. -->
<script src="https://cdn.jsdelivr.net/npm/llobotomy-azure"></script>

<script>
// UMD module is exposed through the "llobotomy-azure" global variable.
console.log(llobotomy-azure);
</script>
```

## Documentation

[Documentation generated from source files by Typedoc](./docs/README.md).
Expand Down
61 changes: 9 additions & 52 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,15 @@ LLobotoMy for Azure

## Table of contents

### Type Aliases
### Classes

- [NumberParseable](README.md#numberparseable)
- [Assistant](classes/Assistant.md)
- [RequiredAction](classes/RequiredAction.md)
- [Thread](classes/Thread.md)

### Functions
### Interfaces

- [isNumberParseable](README.md#isnumberparseable)

## Type Aliases

### NumberParseable

Ƭ **NumberParseable**: `number` \| `string` \| `boolean` & { `isNumberParseble`: unique `symbol` }

A Branded Type for values parseable to number.

#### Defined in

[index.ts:4](https://github.com/paztek/llobotomy-azure/blob/18df7c7/src/index.ts#L4)

## Functions

### isNumberParseable

**isNumberParseable**(`value`): value is NumberParseable

Check if value is parseable to number.

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `value` | `unknown` | An `unknown` value to be checked. |

#### Returns

value is NumberParseable

**`Example`**

```js
isNumberParseable('AAAA');
//=> false

isNumberParseable('100');
//=> true

if (!isNumberParseable(value))
throw new Error('Value can\'t be parseable to `Number`.')
return Number(value);
```

#### Defined in

[index.ts:24](https://github.com/paztek/llobotomy-azure/blob/18df7c7/src/index.ts#L24)
- [AssistantCreateParams](interfaces/AssistantCreateParams.md)
- [FunctionTool](interfaces/FunctionTool.md)
- [ToolCall](interfaces/ToolCall.md)
- [ToolOutput](interfaces/ToolOutput.md)
96 changes: 96 additions & 0 deletions docs/classes/Assistant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
[LLobotoMy for Azure](../README.md) / Assistant

# Class: Assistant

## Table of contents

### Constructors

- [constructor](Assistant.md#constructor)

### Properties

- [client](Assistant.md#client)
- [deployment](Assistant.md#deployment)
- [functions](Assistant.md#functions)
- [instructions](Assistant.md#instructions)

### Methods

- [getChatCompletions](Assistant.md#getchatcompletions)

## Constructors

### constructor

**new Assistant**(`params`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `params` | [`AssistantCreateParams`](../interfaces/AssistantCreateParams.md) |

#### Defined in

[src/assistant/assistant.ts:20](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L20)

## Properties

### client

`Readonly` **client**: `OpenAIClient`

#### Defined in

[src/assistant/assistant.ts:14](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L14)

___

### deployment

`Private` `Readonly` **deployment**: `string`

#### Defined in

[src/assistant/assistant.ts:18](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L18)

___

### functions

`Private` `Readonly` **functions**: `FunctionDefinition`[]

#### Defined in

[src/assistant/assistant.ts:17](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L17)

___

### instructions

`Private` `Readonly` **instructions**: `string`

#### Defined in

[src/assistant/assistant.ts:16](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L16)

## Methods

### getChatCompletions

**getChatCompletions**(`messages`): `Promise`<`ChatCompletions`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `messages` | `ChatMessage`[] |

#### Returns

`Promise`<`ChatCompletions`\>

#### Defined in

[src/assistant/assistant.ts:27](https://github.com/paztek/llobotomy-azure/blob/1acaa38/src/assistant/assistant.ts#L27)
Loading

0 comments on commit ef04001

Please sign in to comment.