Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,24 @@
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"",
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,md}\""
},
"keywords": [],
"keywords": [
"stripe",
"documentation",
"loader",
"langchain",
"sitemap"
],
"author": "hideokamoto",
"license": "ISC",
"description": "",
"license": "MIT",
"description": "A collection of utility libraries for easily retrieving and processing Stripe data",
"repository": {
"type": "git",
"url": "https://github.com/wpkyoto/stripe-docs-loader"
},
"bugs": {
"url": "https://github.com/wpkyoto/stripe-docs-loader/issues"
},
"homepage": "https://github.com/wpkyoto/stripe-docs-loader#readme",
"devDependencies": {
"@types/node": "^22.13.10",
"prettier": "^3.2.5",
Expand Down
25 changes: 22 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,29 @@
"scripts": {
"dev": "vite build --watch",
"build": "vite build && tsc --emitDeclarationOnly",
"test": "vitest run"
"test": "vitest run",
"prepublishOnly": "npm run build"
},
"keywords": [],
"keywords": [
"stripe",
"documentation",
"sitemap",
"processor",
"utility"
],
"author": "hideokamoto",
"license": "MIT",
"description": "Core library for Stripe loaders"
"description": "Core library for Stripe loaders",
"repository": {
"type": "git",
"url": "https://github.com/wpkyoto/stripe-docs-loader",
"directory": "packages/core"
},
"bugs": {
"url": "https://github.com/wpkyoto/stripe-docs-loader/issues"
},
"homepage": "https://github.com/wpkyoto/stripe-docs-loader/tree/main/packages/core#readme",
"publishConfig": {
"access": "public"
}
}
30 changes: 24 additions & 6 deletions packages/langchain-stripe-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,36 @@
"scripts": {
"dev": "vite build --watch",
"build": "vite build && tsc --emitDeclarationOnly",
"test": "vitest run"
"test": "vitest run",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@langchain/core": "^0.3.42",
"stripe-loaders-core": "*",
"turndown": "^7.2.0"
"node-html-markdown": "^1.3.0",
"stripe-loaders-core": "^0.0.0"
},
"keywords": [],
"keywords": [
"stripe",
"documentation",
"loader",
"langchain",
"llm",
"ai",
"document-loader"
],
"author": "hideokamoto",
"license": "MIT",
"description": "LangChain loader for Stripe data",
"devDependencies": {
"@types/turndown": "^5.0.5"
"repository": {
"type": "git",
"url": "https://github.com/wpkyoto/stripe-docs-loader",
"directory": "packages/langchain-stripe-loader"
},
"bugs": {
"url": "https://github.com/wpkyoto/stripe-docs-loader/issues"
},
"homepage": "https://github.com/wpkyoto/stripe-docs-loader/tree/main/packages/langchain-stripe-loader#readme",
"publishConfig": {
"access": "public"
}
}
9 changes: 6 additions & 3 deletions packages/langchain-stripe-loader/src/StripeComLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SitemapProcessor } from 'stripe-loaders-core';
import { BaseDocumentLoader } from '@langchain/core/document_loaders/base';
import { Document } from '@langchain/core/documents';
import Turndown from 'turndown';
import { NodeHtmlMarkdown } from 'node-html-markdown';
import { extractBodyFromHTML } from './utils';

/**
Expand Down Expand Up @@ -95,9 +95,12 @@ export class StripeComDocumentLoader extends BaseDocumentLoader {
const articles = urls
? await this.fetchArticlesFromURLs(urls, locale)
: await this.fetchArticlesFromSitemap(resource, locale);
const encoder = new Turndown();

// NodeHtmlMarkdownを使用してHTMLをMarkdownに変換
const nhm = new NodeHtmlMarkdown();

const documents = articles.map(article => {
const markdownContent = encoder.turndown(article.content);
const markdownContent = nhm.translate(article.content);
Comment on lines 102 to +103

Choose a reason for hiding this comment

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

high

Consider adding error handling around the nhm.translate function. If this function throws an error, it could crash the application. Wrapping it in a try-catch block would make the code more robust.

    const documents = articles.map(article => {
      let markdownContent;
      try {
        markdownContent = nhm.translate(article.content);
      } catch (error) {
        console.error("Error converting HTML to Markdown:", error);
        markdownContent = ""; // Or some default value or error handling
      }
      return new Document({

return new Document({
pageContent: markdownContent,
metadata: {
Expand Down
9 changes: 6 additions & 3 deletions packages/langchain-stripe-loader/src/StripeDocsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SitemapProcessor } from 'stripe-loaders-core';
import { BaseDocumentLoader } from '@langchain/core/document_loaders/base';
import { Document } from '@langchain/core/documents';
import Turndown from 'turndown';
import { NodeHtmlMarkdown } from 'node-html-markdown';
import { extractArticleFromHTML } from './utils';
/**
* Interface representing a Stripe documentation article
Expand Down Expand Up @@ -61,9 +61,12 @@ export class StripeDocsDocumentLoader extends BaseDocumentLoader {
*/
async load(locale: string = 'en-US'): Promise<Document[]> {
const articles = await this.fetchArticlesFromSitemap(locale);
const encoder = new Turndown();

// NodeHtmlMarkdownを使用してHTMLをMarkdownに変換
const nhm = new NodeHtmlMarkdown();

const documents = articles.map(article => {
const markdownContent = encoder.turndown(article.content);
const markdownContent = nhm.translate(article.content);
Comment on lines 68 to +69

Choose a reason for hiding this comment

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

high

Consider adding error handling around the nhm.translate function. If this function throws an error, it could crash the application. Wrapping it in a try-catch block would make the code more robust.

    const documents = articles.map(article => {
      let markdownContent;
      try {
        markdownContent = nhm.translate(article.content);
      } catch (error) {
        console.error("Error converting HTML to Markdown:", error);
        markdownContent = ""; // Or some default value or error handling
      }
      return new Document({

return new Document({
pageContent: markdownContent,
metadata: {
Expand Down