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

RFC Cleanup Configuration and naming #2

merged 1 commit into from May 5, 2023

Conversation

Flux159
Copy link
Contributor

@Flux159 Flux159 commented May 5, 2023

RFC Cleanup Configuration and naming

The initialization code is really verbose - configuration can just be an object & be initialized directly with LastMile

Currently:

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:

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",
});

Stack created with Sapling. Best reviewed with ReviewStack.

@Flux159 Flux159 marked this pull request as ready for review May 5, 2023 21:45
Copy link
Contributor

@rholinshead rholinshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. We can revisit the class later if additional configuration setup is needed instead of pushing more into the api class.

After removing the unused interface can you run the doc generation (npx typedoc index.ts) to keep it in sync?

configuration.ts Outdated
Comment on lines 3 to 5
export interface ConfigurationParameters {
apiKey: string;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove ConfigurationParameters as unused

@Flux159
Copy link
Contributor Author

Flux159 commented May 5, 2023

Updated docs & tests, but I'm having trouble running the tests successfully, don't know if it's because of jest or something else:

Node.js v20.0.0
node:internal/child_process/serialization:159
    const string = JSONStringify(message) + '\n';
                   ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'res' -> object with constructor 'Object'
    --- property 'req' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at process.target._send (node:internal/child_process:845:17)
    at process.target.send (node:internal/child_process:745:19)
    at reportSuccess (/Users/suyogsonwalkar/Projects/company/lastmileai-node/node_modules/jest-worker/build/workers/processChild.js:82:11)

Did you see that before?

@rholinshead
Copy link
Contributor

rholinshead commented May 5, 2023

Updated docs & tests, but I'm having trouble running the tests successfully, don't know if it's because of jest or something else:

Node.js v20.0.0
node:internal/child_process/serialization:159
    const string = JSONStringify(message) + '\n';
                   ^

TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'res' -> object with constructor 'Object'
    --- property 'req' closes the circle
    at stringify (<anonymous>)
    at writeChannelMessage (node:internal/child_process/serialization:159:20)
    at process.target._send (node:internal/child_process:845:17)
    at process.target.send (node:internal/child_process:745:19)
    at reportSuccess (/Users/suyogsonwalkar/Projects/company/lastmileai-node/node_modules/jest-worker/build/workers/processChild.js:82:11)

Did you see that before?

I haven't seen that before, no. I don't have jest globally, just do npm run test (or npx jest) -- does that work?

@rholinshead
Copy link
Contributor

In any case, I pulled this and ran the tests successfully on my end

@Flux159
Copy link
Contributor Author

Flux159 commented May 5, 2023

In any case, I pulled this and ran the tests successfully on my end

I'm running vianpm run test, was able to get around the circular dep thing by using "--runInBand" (found here: jestjs/jest#10577 (comment)) ; the really weird thing is that I can't get the API key passed, so the tests at trials & embeddings are failing because Authorization Bearer is empty. For some reason jest isn't taking environment vars from my shell and can't figure out why

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",
});
```
@Flux159
Copy link
Contributor Author

Flux159 commented May 5, 2023

Okay, got it working weirdly:

LASTMILEAI_API_KEY=$LASTMILEAI_API_KEY npm run test

Essentially forcing npm test to also have the api key passed in... also using jest --runInBand

Edit: Feel like I should've done the docs changes on a diff on top lol - sorry

@Flux159 Flux159 merged commit 010a631 into master May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants