Skip to content

Commit

Permalink
RFC Cleanup Configuration and naming
Browse files Browse the repository at this point in the history
The initialization code is really verbose - configuration can just be an object & be initialized directly with LastMile

Currently:
```javascript
import { Configuration, LastMileAIApi} from "lastmileai";

const configuration = new Configuration({
  apiKey: process.env.LASTMILEAI_API_KEY ?? "",
});
const lastmile = new LastMileAIApi(configuration);

const completion = await lastmile.createOpenAICompletion({
  completionParams: {
    model: "text-davinci-003",
    prompt: "Your prompt here",
  },
  embeddingCollectionId: "clfpqyvpp004npmzgp1d4j4fw",
});
```

Can become:
```javascript
import { LastMile } from "lastmileai";

const lastmile = new LastMile({apiKey: process.env.LASTMILEAI_API_KEY ?? ""});

const completion = await lastmile.createOpenAICompletion({
  completionParams: {
    model: "text-davinci-003",
    prompt: "Your prompt here",
  },
  embeddingCollectionId: "clfpqyvpp004npmzgp1d4j4fw",
});
```
  • Loading branch information
Flux159 committed May 5, 2023
1 parent 6c475f3 commit 4d04d85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ npm install lastmileai
This library needs to be configured with your API Token (aka API key) obtained above. You can store the API key in an environment variable or alternative secure storage that can be accessed in your server-side code. For example, to initialize the library with the API key loaded from environment variable:

```javascript
import { Configuration, LastMileAIApi } from "lastmileai";
import { LastMile } from "lastmileai";

const configuration = new Configuration({
apiKey: process.env.LASTMILEAI_API_KEY ?? "",
});

const lastmile = new LastMileAIApi(configuration);
const lastmile = new LastMile({apiKey: process.env.LASTMILEAI_API_KEY ?? ""});
```
## Completions -- Open AI Models
Expand Down
18 changes: 15 additions & 3 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "openai";
import { JSONArray, JSONValue } from "./common";
import { Configuration } from "./configuration";
import packageJson = require("./package.json");

/**
* GENERAL TYPES
Expand Down Expand Up @@ -2293,16 +2294,27 @@ export type UpdateWorkspaceResponse = Workspace;
*/

/**
* LastMileAIApi - API for interfacing with LastMileAI
* LastMile - API for interfacing with LastMileAI
* @export
* @class LastMileAIApi
* @class LastMile
*/
export class LastMileAIApi {
export class LastMile {
protected configuration: Configuration;
protected defaultHeaders: undefined;

constructor(configuration: Configuration) {
this.configuration = configuration;
if (!this.configuration.defaultAxiosConfig) {
this.configuration.defaultAxiosConfig = {
baseURL: 'https://lastmileai.dev/api/',
headers: {
'User-Agent': `LastMileAI/NodeJS/${packageJson.version}`,
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.configuration.apiKey}`,
}
};
}
}

/**
Expand Down
18 changes: 2 additions & 16 deletions configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { AxiosRequestConfig } from "axios";
import packageJson = require("./package.json");

export interface ConfigurationParameters {
apiKey: string;
}

export class Configuration {
export type Configuration = {
/**
* LastMileAI API Key
* @memberof Configuration
Expand All @@ -17,17 +16,4 @@ export class Configuration {
* @memberof Configuration
*/
defaultAxiosConfig: AxiosRequestConfig;

constructor(param: ConfigurationParameters) {
this.apiKey = param.apiKey;
this.defaultAxiosConfig = {
baseURL: 'https://lastmileai.dev/api/',
headers: {
'User-Agent': `LastMileAI/NodeJS/${packageJson.version}`,
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
}
};
}
}
}

0 comments on commit 4d04d85

Please sign in to comment.