Skip to content

Commit

Permalink
Refactor imports and simplify module exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rileytomasek committed Oct 17, 2024
1 parent 0874859 commit 4513b78
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 64 deletions.
3 changes: 1 addition & 2 deletions examples/ai-function.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dotenv/config';

import { ChatModel, type Msg, MsgUtil } from '@dexaai/dexter';
import { createAIFunction } from '@dexaai/dexter/ai-function';
import { ChatModel, createAIFunction, type Msg, MsgUtil } from '@dexaai/dexter';
import { z } from 'zod';

/**
Expand Down
8 changes: 6 additions & 2 deletions examples/ai-runner-with-error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dotenv/config';

import { ChatModel, MsgUtil } from '@dexaai/dexter';
import { createAIFunction, createAIRunner } from '@dexaai/dexter/ai-function';
import {
ChatModel,
createAIFunction,
createAIRunner,
MsgUtil,
} from '@dexaai/dexter';
import { z } from 'zod';

/** Get the weather for a given location. */
Expand Down
8 changes: 6 additions & 2 deletions examples/ai-runner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dotenv/config';

import { ChatModel, MsgUtil } from '@dexaai/dexter';
import { createAIFunction, createAIRunner } from '@dexaai/dexter/ai-function';
import {
ChatModel,
createAIFunction,
createAIRunner,
MsgUtil,
} from '@dexaai/dexter';
import { z } from 'zod';

/** Get the weather for a given location. */
Expand Down
3 changes: 1 addition & 2 deletions examples/extract-people-names.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dotenv/config';

import { ChatModel } from '@dexaai/dexter';
import { createExtractFunction } from '@dexaai/dexter/extract';
import { ChatModel, createExtractFunction } from '@dexaai/dexter';
import { z } from 'zod';

/** A function to extract people names from text. */
Expand Down
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/model/index.d.ts",
"import": "./dist/model/index.js"
},
"./ai-function": {
"types": "./dist/ai-function/index.d.ts",
"import": "./dist/ai-function/index.js"
},
"./extract": {
"types": "./dist/extract/index.d.ts",
"import": "./dist/extract/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
},
"./swarm": {
"types": "./dist/swarm/index.d.ts",
Expand Down
6 changes: 2 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ console.log('\n\nFull response:', response.message.content);
### Extracting Structured Data

```typescript
import { ChatModel } from '@dexaai/dexter';
import { createExtractFunction } from '@dexaai/dexter/extract';
import { ChatModel, createExtractFunction } from '@dexaai/dexter';
import { z } from 'zod';

const extractPeopleNames = createExtractFunction({
Expand All @@ -129,8 +128,7 @@ console.log('peopleNames', peopleNames);
### Using AI Functions

```typescript
import { ChatModel, MsgUtil } from '@dexaai/dexter';
import { createAIFunction } from '@dexaai/dexter/ai-function';
import { ChatModel, MsgUtil, createAIFunction } from '@dexaai/dexter';
import { z } from 'zod';

const getWeather = createAIFunction(
Expand Down
2 changes: 1 addition & 1 deletion src/ai-function/ai-extract-function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type z } from 'zod';

import { type Model, MsgUtil } from '../model/index.js';
import { type Model, MsgUtil } from '../index.js';
import { createAIFunction } from './ai-function.js';
import { createAIRunner } from './ai-runner.js';
import { type ExtractFunction } from './types.js';
Expand Down
2 changes: 1 addition & 1 deletion src/ai-function/ai-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Msg,
MsgUtil,
zodToJsonSchema,
} from '../model/index.js';
} from '../index.js';
import { cleanString } from '../model/utils/message-util.js';
import { type AIFunction } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion src/ai-function/ai-runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pMap from 'p-map';

import { MsgUtil } from '../model/index.js';
import { MsgUtil } from '../index.js';
import { type Model, type Msg } from '../model/types.js';
import { getErrorMsg } from '../model/utils/errors.js';
import { type AIFunction, type AIRunner } from './types.js';
Expand Down
8 changes: 0 additions & 8 deletions src/ai-function/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/ai-function/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type SetOptional } from 'type-fest';
import { type z } from 'zod';

import { type Model, type Msg } from '../model/types.js';
import { type Model, type Msg } from '../index.js';

/**
* A runner that iteratively calls the model and handles function calls.
Expand Down
2 changes: 1 addition & 1 deletion src/extract/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { zodToJsonSchema } from 'openai-zod-to-json-schema';
import { type z } from 'zod';

import { type Model, type Msg, MsgUtil } from '../model/index.js';
import { type Model, type Msg, MsgUtil } from '../index.js';

/**
* Extract data using OpenAI structured outputs.
Expand Down
35 changes: 32 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
// This is intentionally empty, but here to make bundlers happy.

export {};
export { createAIExtractFunction } from './ai-function/ai-extract-function.js';
export { createAIFunction } from './ai-function/ai-function.js';
export {
createAIRunner,
handleFunctionCallMessage,
} from './ai-function/ai-runner.js';
export {
type AIFunction,
type AIRunner,
type ExtractFunction,
} from './ai-function/types.js';
export { createExtractFunction } from './extract/index.js';
export type { ChatModelArgs } from './model/chat.js';
export { ChatModel } from './model/chat.js';
export { createOpenAIClient } from './model/clients/openai.js';
export type { CompletionModelArgs } from './model/completion.js';
export { CompletionModel } from './model/completion.js';
export type { EmbeddingModelArgs } from './model/embedding.js';
export { EmbeddingModel } from './model/embedding.js';
export type { ModelArgs } from './model/model.js';
export { AbstractModel } from './model/model.js';
export type { SparseVectorModelArgs } from './model/sparse-vector.js';
export { SparseVectorModel } from './model/sparse-vector.js';
export type { Model, Msg } from './model/types.js';
export { type CacheKey, type CacheStorage } from './model/utils/cache.js';
export { calculateCost } from './model/utils/calculate-cost.js';
export { AbortError, RefusalError } from './model/utils/errors.js';
export { extractJsonObject } from './model/utils/extract-json.js';
export { extractZodObject } from './model/utils/extract-zod-object.js';
export { MsgUtil } from './model/utils/message-util.js';
export { createTokenizer, type Tokenizer } from './model/utils/tokenizer.js';
export { zodToJsonSchema } from './model/utils/zod-to-json-schema.js';
20 changes: 0 additions & 20 deletions src/model/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/swarm/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as readline from 'node:readline';

import chalk from 'chalk';

import { type Msg, MsgUtil } from '../model/index.js';
import { type Msg, MsgUtil } from '../index.js';
import { Swarm } from './swarm.js';
import { type Agent } from './types.js';

Expand Down
2 changes: 1 addition & 1 deletion src/swarm/swarm-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type Msg,
MsgUtil,
zodToJsonSchema,
} from '../model/index.js';
} from '../index.js';
import { getErrorMsg } from '../model/utils/errors.js';
import { cleanString } from '../model/utils/message-util.js';
import { type Agent, type SwarmFunc } from './types.js';
Expand Down
4 changes: 1 addition & 3 deletions src/swarm/swarm.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pMap from 'p-map';

import { ChatModel } from '../model/chat.js';
import { MsgUtil } from '../model/index.js';
import { type Msg } from '../model/types.js';
import { ChatModel, type Msg, MsgUtil } from '../index.js';
import { getErrorMsg } from '../model/utils/errors.js';
import {
type Agent,
Expand Down
2 changes: 1 addition & 1 deletion src/swarm/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type z } from 'zod';

import { type Msg } from '../model/types.js';
import { type Msg } from '../index.js';

export type CtxVal = Record<string, unknown>;

Expand Down

0 comments on commit 4513b78

Please sign in to comment.