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

feat: exports init options for external use #422

Merged
merged 1 commit into from
Mar 2, 2023

Conversation

NoodleOfDeath
Copy link
Contributor

@NoodleOfDeath NoodleOfDeath commented Mar 2, 2023

This PR simply exports the constructor options for the ChatGPTAPI class so it can be extended/used by other developers! I would rather use this type as a union for my wrapper classes rather than having to manually define it myself! Keep being awesome! Love how active this repo is

i.e.

import { ChatGPTAPI, ChatGPTAPIOptions } from 'chatgpt';

type ChatGPTServiceOptions = ChatGPTAPIOptions & {
  customOption: string;
}

class ChatGPTService {

  api: ChatGPTAPI;
  customOption: string;

  constructor({ 
    apiKey = process.env.OPENAI_API_KEY, 
    customOption = '', 
    ...other 
  }: Partial<ChatGPTServiceOptions> = {}) {
    this.api = new ChatGPTAPI({
        apiKey,
        ...other
     });
    this.customOption = customOption;
  }

}

fetch = globalFetch
} = opts

constructor({

Choose a reason for hiding this comment

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

the reason I was using opts instead of destructuring directly in the constructor is because for some reason in the past typedoc wasn't picking up the correct types to document when I did things this way.

will play w/ typedoc locally after merging this to see if that's still the case :)

@transitive-bullshit
Copy link
Owner

@NoodleOfDeath agreed this looks like a great change. always in favor of exporting types instead of trying to pickout types via ConstructorParameters<typeof ChatGPTAPI>[0]

@transitive-bullshit transitive-bullshit merged commit ad3d1f9 into transitive-bullshit:main Mar 2, 2023
@transitive-bullshit
Copy link
Owner

mi-ann0613 pushed a commit to mi-ann0613/chatgpt-api that referenced this pull request May 9, 2024
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