forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 98f0df2
Showing
21 changed files
with
942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module.exports = { | ||
extends: [ | ||
"airbnb-base", | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:@typescript-eslint/recommended", | ||
], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
parser: "@typescript-eslint/parser", | ||
sourceType: "module", | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
rules: { | ||
"@typescript-eslint/explicit-module-boundary-types": 0, | ||
"@typescript-eslint/no-empty-function": 0, | ||
"@typescript-eslint/no-shadow": ["error"], | ||
"@typescript-eslint/no-use-before-define": ["error", "nofunc"], | ||
"@typescript-eslint/no-unused-vars": ["warn", { args: "none" }], | ||
"comma-dangle": ["error", "never"], | ||
"camelcase": 0, | ||
"class-methods-use-this": 0, | ||
"import/extensions": 0, | ||
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.test.ts"]}], | ||
"import/no-unresolved": 0, | ||
"import/prefer-default-export": 0, | ||
"keyword-spacing": "error", | ||
"max-classes-per-file": 0, | ||
"max-len": ["error", { code: 100, tabWidth: 2, ignoreComments: true }], | ||
"no-bitwise": "off", | ||
"no-console": 0, | ||
"no-restricted-syntax": 0, | ||
"no-shadow": 0, | ||
"no-underscore-dangle": 0, | ||
"no-use-before-define": 0, | ||
"semi": ["error", "always"], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/ | ||
dist/ | ||
lib/ | ||
.turbo | ||
.eslintcache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
yarn precommit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
babel.config.js | ||
jest.config.js | ||
.eslintrc.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# langchainjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
//babel.config.js | ||
module.exports = {presets: ['@babel/preset-env']} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest/presets/js-with-ts', | ||
testEnvironment: 'node', | ||
transform: { | ||
"^.+\\.(ts|tsx)$": "ts-jest", | ||
"^.+\\.(js)$": "babel-jest", | ||
}, | ||
transformIgnorePatterns: [ | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "langchain", | ||
"version": "0.0.1", | ||
"description": "Typescript bindings for langchain", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build": "tsc --declaration --outDir dist/", | ||
"lint": "eslint src", | ||
"lint:fix": "yarn lint --fix", | ||
"precommit": "tsc --noEmit && lint-staged", | ||
"clean": "rm -rf dist/", | ||
"prepack": "yarn build", | ||
"test": "jest", | ||
"prepare": "husky install" | ||
}, | ||
"author": "Langchain", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@babel/preset-env": "^7.20.2", | ||
"@jest/globals": "^29.4.2", | ||
"@tsconfig/recommended": "^1.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.51.0", | ||
"@typescript-eslint/parser": "^5.51.0", | ||
"babel-jest": "^29.4.2", | ||
"eslint": "^8.33.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.3", | ||
"jest": "^29.4.2", | ||
"lint-staged": "^13.1.1", | ||
"prettier": "^2.8.3", | ||
"ts-jest": "^29.0.5", | ||
"typescript": "^4.9.5" | ||
}, | ||
"dependencies": { | ||
"node-fetch": "^3.3.0", | ||
"yaml": "^2.2.1" | ||
}, | ||
"lint-staged": { | ||
"src/**/*.{ts,tsx}": [ | ||
"prettier --write --ignore-unknown", | ||
"eslint --cache --fix" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { | ||
PromptTemplate, | ||
BasePromptTemplate, | ||
FewShotPromptTemplate, | ||
} from "./prompt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { BaseOutputParser } from "./parser"; | ||
import { | ||
PromptTemplateInput, | ||
SerializedPromptTemplate, | ||
PromptTemplate, | ||
FewShotPromptTemplateInput, | ||
SerializedFewShotTemplate, | ||
FewShotPromptTemplate, | ||
} from "./index"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type InputValues = Record<string, any>; | ||
|
||
type SerializedBasePromptTemplate = | ||
| SerializedPromptTemplate | ||
| SerializedFewShotTemplate | ||
| (Omit<SerializedPromptTemplate, "_type"> & { _type: undefined }); | ||
|
||
export interface BasePromptTemplateInput { | ||
inputVariables: string[]; | ||
outputParser?: BaseOutputParser; | ||
} | ||
|
||
type ConstructorInput = FewShotPromptTemplateInput | PromptTemplateInput; | ||
|
||
export abstract class BasePromptTemplate implements BasePromptTemplateInput { | ||
inputVariables: string[]; | ||
|
||
outputParser?: BaseOutputParser; | ||
|
||
constructor(input: ConstructorInput) { | ||
const { inputVariables } = input; | ||
if (inputVariables.includes("stop")) { | ||
throw new Error( | ||
"Cannot have an input variable named 'stop', as it is used internally, please rename." | ||
); | ||
} | ||
Object.assign(this, input); | ||
} | ||
|
||
abstract format(values: InputValues): string; | ||
|
||
abstract _getPromptType(): string; | ||
|
||
abstract serialize(): SerializedBasePromptTemplate; | ||
|
||
// Deserializing needs to be async because templates (e.g. few_shot) can | ||
// reference remote resources that we read asynchronously with a web | ||
// request. | ||
static async deserialize( | ||
data: SerializedBasePromptTemplate | ||
): Promise<BasePromptTemplate> { | ||
switch (data._type) { | ||
case "prompt": | ||
return PromptTemplate.deserialize(data); | ||
case undefined: | ||
return PromptTemplate.deserialize({ ...data, _type: "prompt" }); | ||
case "few_shot": | ||
return FewShotPromptTemplate.deserialize(data); | ||
default: | ||
throw new Error( | ||
`Invalid prompt type in config: ${ | ||
(data as SerializedBasePromptTemplate)._type | ||
}` | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.