Skip to content

Commit

Permalink
Fix eslint config to not exclude js/d.ts files (langchain-ai#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos authored Feb 27, 2023
1 parent 772f0cc commit 91fe9ac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion langchain/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
sourceType: "module",
},
plugins: ["@typescript-eslint"],
ignorePatterns: ["dist", "docs", "node_modules", "*.d.ts", "*.cjs", "*.js"],
ignorePatterns: [".eslintrc.cjs", "node_modules"],
rules: {
"@typescript-eslint/explicit-module-boundary-types": 0,
"@typescript-eslint/no-empty-function": 0,
Expand Down
2 changes: 1 addition & 1 deletion langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"scripts": {
"build": "yarn clean && tsc --declaration --outDir dist/ && node create-entrypoints.js",
"lint": "eslint .",
"lint": "eslint src",
"doc": "typedoc",
"lint:fix": "yarn lint --fix",
"precommit": "tsc --noEmit && lint-staged",
Expand Down
24 changes: 22 additions & 2 deletions langchain/src/types/huggingface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,80 @@ declare module "huggingface" {
// exports.types key in package.json
declare class HuggingFace {
private readonly apiKey;

private readonly defaultOptions;

constructor(apiKey: string, defaultOptions?: Options);

/**
* Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.
*/
fillMask(args: FillMaskArgs, options?: Options): Promise<FillMaskReturn>;

/**
* This task is well known to summarize longer text into shorter text. Be careful, some models have a maximum length of input. That means that the summary cannot handle full books for instance. Be careful when choosing your model.
*/
summarization(
args: SummarizationArgs,
options?: Options
): Promise<SummarizationReturn>;

/**
* Want to have a nice know-it-all bot that can answer any question?. Recommended model: deepset/roberta-base-squad2
*/
questionAnswer(
args: QuestionAnswerArgs,
options?: Options
): Promise<QuestionAnswerReturn>;

/**
* Don’t know SQL? Don’t want to dive into a large spreadsheet? Ask questions in plain english! Recommended model: google/tapas-base-finetuned-wtq.
*/
tableQuestionAnswer(
args: TableQuestionAnswerArgs,
options?: Options
): Promise<TableQuestionAnswerReturn>;

/**
* Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english
*/
textClassification(
args: TextClassificationArgs,
options?: Options
): Promise<TextClassificationReturn>;

/**
* Use to continue text from a prompt. This is a very generic task. Recommended model: gpt2 (it’s a simple model, but fun to play with).
*/
textGeneration(
args: TextGenerationArgs,
options?: Options
): Promise<TextGenerationReturn>;

/**
* Usually used for sentence parsing, either grammatical, or Named Entity Recognition (NER) to understand keywords contained within text. Recommended model: dbmdz/bert-large-cased-finetuned-conll03-english
*/
tokenClassification(
args: TokenClassificationArgs,
options?: Options
): Promise<TokenClassificationReturn>;

/**
* This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.
*/
translation(
args: TranslationArgs,
options?: Options
): Promise<TranslationReturn>;

/**
* This task is super useful to try out classification with zero code, you simply pass a sentence/paragraph and the possible labels for that sentence, and you get a result. Recommended model: facebook/bart-large-mnli.
*/
zeroShotClassification(
args: ZeroShotClassificationArgs,
options?: Options
): Promise<ZeroShotClassificationReturn>;

/**
* This task corresponds to any chatbot like structure. Models tend to have shorter max_length, so please check with caution when using a given model if you need long range dependency or not. Recommended model: microsoft/DialoGPT-large.
*
Expand All @@ -73,13 +85,15 @@ declare module "huggingface" {
args: ConversationalArgs,
options?: Options
): Promise<ConversationalReturn>;

/**
* This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
*/
featureExtraction(
args: FeatureExtractionArgs,
options?: Options
): Promise<FeatureExtractionReturn>;

/**
* This task reads some audio input and outputs the said words within the audio files.
* Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
Expand All @@ -88,6 +102,7 @@ declare module "huggingface" {
args: AutomaticSpeechRecognitionArgs,
options?: Options
): Promise<AutomaticSpeechRecognitionReturn>;

/**
* This task reads some audio input and outputs the likelihood of classes.
* Recommended model: superb/hubert-large-superb-er
Expand All @@ -96,6 +111,7 @@ declare module "huggingface" {
args: AudioClassificationArgs,
options?: Options
): Promise<AudioClassificationReturn>;

/**
* This task reads some image input and outputs the likelihood of classes.
* Recommended model: google/vit-base-patch16-224
Expand All @@ -104,6 +120,7 @@ declare module "huggingface" {
args: ImageClassificationArgs,
options?: Options
): Promise<ImageClassificationReturn>;

/**
* This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
* Recommended model: facebook/detr-resnet-50
Expand All @@ -112,6 +129,7 @@ declare module "huggingface" {
args: ObjectDetectionArgs,
options?: Options
): Promise<ObjectDetectionReturn>;

/**
* This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
* Recommended model: facebook/detr-resnet-50-panoptic
Expand All @@ -120,14 +138,16 @@ declare module "huggingface" {
args: ImageSegmentationArgs,
options?: Options
): Promise<ImageSegmentationReturn>;

request(
args: Args & {
data?: any;
data?: unknown;
},
options?: Options & {
binary?: boolean;
}
): Promise<any>;
): Promise<unknown>;

private static toArray;
}

Expand Down
1 change: 1 addition & 0 deletions langchain/src/util/axios-fetch-adapter.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { AxiosRequestConfig, AxiosPromise } from "axios";

export default function fetchAdapter(config: AxiosRequestConfig): AxiosPromise;
12 changes: 7 additions & 5 deletions langchain/src/util/axios-fetch-adapter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
/* eslint-disable import/no-extraneous-dependencies */

/**
Expand Down Expand Up @@ -30,7 +31,7 @@ export default async function fetchAdapter(config) {
setTimeout(() => {
const message = config.timeoutErrorMessage
? config.timeoutErrorMessage
: "timeout of " + config.timeout + "ms exceeded";
: `timeout of ${config.timeout}ms exceeded`;
res(createError(message, config, "ECONNABORTED", request));
}, config.timeout);
})
Expand All @@ -42,6 +43,7 @@ export default async function fetchAdapter(config) {
if (data instanceof Error) {
reject(data);
} else {
// eslint-disable-next-line no-unused-expressions
Object.prototype.toString.call(config.settle) === "[object Function]"
? config.settle(resolve, reject, data)
: settle(resolve, reject, data);
Expand All @@ -66,7 +68,7 @@ async function getResponse(request, config) {
status: stageOne.status,
statusText: stageOne.statusText,
headers: new Headers(stageOne.headers), // Make a copy of headers
config: config,
config,
request,
};

Expand Down Expand Up @@ -105,12 +107,12 @@ function createRequest(config) {
const password = config.auth.password
? decodeURI(encodeURIComponent(config.auth.password))
: "";
headers.set("Authorization", `Basic ${btoa(username + ":" + password)}`);
headers.set("Authorization", `Basic ${btoa(`${username}:${password}`)}`);
}

const method = config.method.toUpperCase();
const options = {
headers: headers,
headers,
method,
};
if (method !== "GET" && method !== "HEAD") {
Expand Down Expand Up @@ -178,7 +180,7 @@ function createError(message, config, code, request, response) {
);
}

var error = new Error(message);
const error = new Error(message);
return enhanceError(error, config, code, request, response);
}

Expand Down

0 comments on commit 91fe9ac

Please sign in to comment.