Skip to content

Commit

Permalink
fix: Add HuggingFaceInference includeCredentials param (#3389)
Browse files Browse the repository at this point in the history
* feat: Add HfInference includeCredentials prop

* Type fix

---------

Co-authored-by: Alex Naymushin <[email protected]>
  • Loading branch information
Xelaan and Alex Naymushin authored Nov 27, 2023
1 parent c677248 commit e4c7619
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions langchain/src/llms/hf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export interface HFInput {

/** API key to use. */
apiKey?: string;

/**
* Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
*/
includeCredentials?: string | boolean;
}

/**
Expand Down Expand Up @@ -73,6 +78,8 @@ export class HuggingFaceInference extends LLM implements HFInput {

endpointUrl: string | undefined = undefined;

includeCredentials: string | boolean | undefined = undefined;

constructor(fields?: Partial<HFInput> & BaseLLMParams) {
super(fields ?? {});

Expand All @@ -85,6 +92,7 @@ export class HuggingFaceInference extends LLM implements HFInput {
this.apiKey =
fields?.apiKey ?? getEnvironmentVariable("HUGGINGFACEHUB_API_KEY");
this.endpointUrl = fields?.endpointUrl;
this.includeCredentials = fields?.includeCredentials;

if (!this.apiKey) {
throw new Error(
Expand All @@ -104,8 +112,12 @@ export class HuggingFaceInference extends LLM implements HFInput {
): Promise<string> {
const { HfInference } = await HuggingFaceInference.imports();
const hf = this.endpointUrl
? new HfInference(this.apiKey).endpoint(this.endpointUrl)
: new HfInference(this.apiKey);
? new HfInference(this.apiKey, {
includeCredentials: this.includeCredentials,
}).endpoint(this.endpointUrl)
: new HfInference(this.apiKey, {
includeCredentials: this.includeCredentials,
});

const res = await this.caller.callWithOptions(
{ signal: options.signal },
Expand Down

2 comments on commit e4c7619

@vercel
Copy link

@vercel vercel bot commented on e4c7619 Nov 27, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on e4c7619 Nov 27, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

langchainjs-docs – ./docs/core_docs/

langchainjs-docs-git-main-langchain.vercel.app
langchainjs-docs-langchain.vercel.app
langchainjs-docs-ruddy.vercel.app
js.langchain.com

Please sign in to comment.