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

RFC Cleanup Configuration and naming #2

Merged
merged 1 commit into from
May 5, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
9 changes: 2 additions & 7 deletions __tests__/embeddings.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import * as dotenv from 'dotenv'
import { LastMileAIApi, Visibility } from '../api';
import { Configuration } from '../configuration';
import { LastMile, Visibility } from '../api';
dotenv.config()

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

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

describe('Embeddings API Methods', () => {
test('createEmbeddingCollection', async () => {
Expand Down
9 changes: 2 additions & 7 deletions __tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import * as dotenv from 'dotenv'
import { LastMileAIApi } from '../api';
import { Configuration } from '../configuration';
import { LastMile } from '../api';
dotenv.config()

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

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

describe('Helper API Methods', () => {
test('apiHealth', async () => {
Expand Down
9 changes: 2 additions & 7 deletions __tests__/trials.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import * as dotenv from "dotenv";
import { LastMileAIApi, Visibility } from "../api";
import { Configuration } from "../configuration";
import { LastMile } from "../api";
dotenv.config();

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

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

describe("Trials API Methods", () => {
test("createTrial", async () => {
Expand Down
22 changes: 17 additions & 5 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 All @@ -2316,10 +2328,10 @@ export class LastMileAIApi {
public async apiHealth(): Promise<{ status: string }> {
// Only need the 'User-Agent' header from the default config
let headers;
if (this.configuration.defaultAxiosConfig.headers) {
if (this.configuration.defaultAxiosConfig?.headers) {
headers = {
"User-Agent":
this.configuration.defaultAxiosConfig.headers["User-Agent"],
this.configuration.defaultAxiosConfig?.headers["User-Agent"],
};
}
const res = await axios.get("health", {
Expand Down
24 changes: 3 additions & 21 deletions configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
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 @@ -16,18 +11,5 @@ export class Configuration {
* Default config for axios requests
* @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}`,
}
};
}
}
defaultAxiosConfig?: AxiosRequestConfig;
}
41 changes: 31 additions & 10 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
:root {
--light-hl-0: #000000;
--dark-hl-0: #D4D4D4;
--light-hl-1: #098658;
--dark-hl-1: #B5CEA8;
--light-hl-2: #795E26;
--dark-hl-2: #DCDCAA;
--light-hl-3: #001080;
--dark-hl-3: #9CDCFE;
--light-hl-4: #0000FF;
--dark-hl-4: #569CD6;
--light-hl-0: #795E26;
--dark-hl-0: #DCDCAA;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #A31515;
--dark-hl-2: #CE9178;
--light-hl-3: #AF00DB;
--dark-hl-3: #C586C0;
--light-hl-4: #001080;
--dark-hl-4: #9CDCFE;
--light-hl-5: #0000FF;
--dark-hl-5: #569CD6;
--light-hl-6: #0070C1;
--dark-hl-6: #4FC1FF;
--light-hl-7: #098658;
--dark-hl-7: #B5CEA8;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}
Expand All @@ -19,6 +25,9 @@
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--code-background: var(--light-code-background);
} }

Expand All @@ -28,6 +37,9 @@
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--code-background: var(--dark-code-background);
} }

Expand All @@ -37,6 +49,9 @@
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--code-background: var(--light-code-background);
}

Expand All @@ -46,6 +61,9 @@
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--code-background: var(--dark-code-background);
}

Expand All @@ -54,4 +72,7 @@
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
.hl-7 { color: var(--hl-7); }
pre, code { background: var(--code-background); }
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.