我重新安装了 llamaindex typescript 包,但我的文档无法被索引

问题描述 投票:0回答:1

前几天我发现openai发布了gpt 4o-mini,我想在我的项目中使用这个模型。所以我重新安装了 llamaindex 并且能够让这个模型工作。从该项目来看,它是一个聊天机器人,它从包含我指定的汽车数据的 json 文件中读取数据。

const { OpenAI } = require("llamaindex");
const fs = require("fs").promises;
const { Document, VectorStoreIndex, QueryEngineTool, OpenAIAgent, Settings } = require("llamaindex");
const readlineSync = require("readline-sync");
const path = require("path");

const dataPath = "data/old_nissan.json";
const errorLogFolder = "error_log";

async function main() {
    try {
        // Ensure error log directory exists
        await fs.mkdir(errorLogFolder, { recursive: true });

        // Setup OpenAI and callback events
        Settings.llm = new OpenAI({ model: "gpt-4o-mini" });
        Settings.callbackManager.on("llm-tool-call", (event) => {
            console.log("llm-tool-call :", event.detail.payload);
        });
        Settings.callbackManager.on("llm-tool-result", (event) => {
            console.log("llm-tool-result :", event.detail.payload);
        });

        // Read essay content from file
        const essay = await fs.readFile(dataPath, "utf-8");
        const document = new Document({ text: essay, id_: dataPath });

        // Create vector index from the document
        const index = await VectorStoreIndex.fromDocuments([document]);

        // Create query engine tool
        const individual_query_engine_tools = [
            new QueryEngineTool({
                queryEngine: index.asQueryEngine(),
                metadata: {
                    name: "vector_index",
                    description: `Useful when you want to answer questions about information about cars assembled in Thailand. You must specify details of the vehicles named in the list when user ask you.`,
                },
            }),
        ];

        // Initialize OpenAIAgent with tools
        const agent = new OpenAIAgent({
            tools: [...individual_query_engine_tools],
            verbose: true,
        });

        while (true) {
            const userInput = readlineSync.question("Enter your question (type 'exit' to quit): ");
            if (userInput.toLowerCase() === 'exit') {
                console.log("Exiting...");
                break;
            } else if (userInput.toLowerCase() !== '') {
                const response = await agent.chat({
                    message: userInput,
                });
                console.log('------------------------------------------------------');
                console.log("Response : ");
                console.log(response);
                console.log('------------------------------------------------------');
            }
        }
    } catch (error) {
        console.error("An error occurred:", error);

        // Generate a unique filename for the error log
        const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
        const errorLogPath = path.join(errorLogFolder, `error_log_${timestamp}.txt`);

        // Write the error details to the log file
        await fs.writeFile(errorLogPath, `Error: ${error.message}\nStack: ${error.stack}`);
    }
}

main().catch(console.error);

当我按运行时,程序给我一个像这样的语法错误。

Error: Expected "http://", "https://", [ \t\n\r], [([{"'`‘], [0-9], [^ \t\n\r!?([}"`)\]}"`0-9@], [^ \t\n\r!?.([})\]}`"0-9@], [a-z0-9], [a-z], or end of input but "}" found.
Stack: SyntaxError: Expected "http://", "https://", [ \t\n\r], [([{"'`‘], [0-9], [^ \t\n\r!?([}"`)\]}"`0-9@], [^ \t\n\r!?.([})\]}`"0-9@], [a-z0-9], [a-z], or end of input but "}" found.
    at peg$buildStructuredError (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:473:24)
    at Object.peg$parse [as parse] (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1597:23)
    at SentenceTokenizer.tokenize (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1630:31)
    at E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1660:26
    at #getSplitsByFns (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1774:28)
    at #split (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1755:67)
    at Function._splitText (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1737:35)
    at Function.splitTextMetadataAware (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:1722:21)
    at E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:97:33
    at Array.reduce (<anonymous>)
    at Function.parseNodes (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:95:22)
    at Function.getNodesFromDocuments (E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:59:56)
    at E:\js chat\node_modules\@llamaindex\core\dist\node-parser\index.cjs:10:25
    at transform (E:\js chat\node_modules\@llamaindex\core\dist\schema\index.cjs:746:20)
    at runTransformations (E:\js chat\node_modules\llamaindex\dist\cjs\ingestion\IngestionPipeline.js:46:27)
    at async VectorStoreIndex.fromDocuments (E:\js chat\node_modules\llamaindex\dist\cjs\indices\vectorStore\index.js:508:22)

当我遇到这个问题时,我想可能是我的代码没有更新并且某些包不再可用。但是当我尝试将数据更改为这样的简单 json 格式时,

{
    "cars": [{
            "make": "Toyota",
            "model": "Corolla",
            "year": 2023,
            "type": "Sedan",
            "engine": "1.8L",
            "assembled_in": "Thailand"
        },
        {
            "make": "Honda",
            "model": "Civic",
            "year": 2023,
            "type": "Sedan",
            "engine": "1.5L Turbo",
            "assembled_in": "Thailand"
        },
        {
            "make": "Mitsubishi",
            "model": "Xpander",
            "year": 2023,
            "type": "SUV",
            "engine": "1.5L",
            "assembled_in": "Thailand"
        },
        {
            "make": "Mazda",
            "model": "CX-5",
            "year": 2023,
            "type": "SUV",
            "engine": "2.5L",
            "assembled_in": "Thailand"
        },
        {
            "make": "Isuzu",
            "model": "D-Max",
            "year": 2023,
            "type": "Truck",
            "engine": "3.0L",
            "assembled_in": "Thailand"
        }
    ]
}

当我使用这个 json 数据运行代码时,它工作正常,但是当我将其更改为像这样的普通数据时

{
    "Car": "Car",
    "year": 2024,
    "active": true,
    "models": [{
            "Brand": "Nissan",
            "Model": "Almera 1.0L Turbo",
            "Year": 2024,
            "Price": "฿549,000 - ฿699,000",
            "Style": {
                "Color": "9 color\nblack (black star) ,\ngrey (gun metalic) ,\ngrey (sky pearl) ,\nwhite (strom white) ,\nred (radiant red) ,\nblue (night blue) ,\nblack (black star) with black roof , \nblack (black star) with black roof ,\nblack (black star) with black roof",
                "Body Type": "Sedan",
                "Segment": "eco car",
                "Door": 4,
                "Seat": 4
            },
            "Performance": {
                "Gear": "auto",
                "Powered by": "gasoline",
                "Fuel type": "Benzene",
                "Fuel tank capacity, liters": 35,
                "Consumption rate": "23.3 kilometers/liter",
                "Cylinder volume, cc": 1000,
                "Horsepower": 100
            },
            "Feature": {
                "Safety System": "- Dual front SRS airbags\n- Side airbags (Side Airbags)\n- Side Curtain Airbags\n- Anti-lock Braking System (ABS)\n- Electronic Brake Force Distribution System (EBD)\n- Brake Assist (BA) braking system\n- Immobilizer key system\n- Anti-theft alarm\n- Central locking system control button\n- ELR driver seat belt with retracting and automatic two-way tensioning (Double Pre-tensioner with Load Limiter)\n- Front passenger seat belt ELR with pre-tensioner and automatic tension release (Single Pre-tensioner with Load Limiter)\n- 3-point ELR rear seat belts, 3 positions\n- ISOFIX child seat mounting points\n- Child protection system for opening rear doors from inside the vehicle\n- Safety structure system Zone Body Concept\n- Third brake light",
                "Features": "- NISSANCONNECT SERVICES\n-Tire Pressure Monitoring Sensor System (TPMS)\n- High Beam Assist (HBA) automatic high beam on-off system\n- Warning system when the car leaves the lane Lane Departure Warning (LDW)\n- Engine starting system from a remote key (Remote Engine Start)\n- Black synthetic leather seats\n- Black cloth seats decorated with dark blue edges.\n- Side mirrors the same color as the car electrically adjustable\n- Intelligent Key - I-Key\n- Engine start button (Push Start Button)\n- Dual front SRS airbags\n- Side Airbags and Side Curtain Airbags\n- Intelligent Forward Collision Warning (IFWC)\n- Intelligent Emergency Braking (IEB) system\n- Control switch for automatic speed control (Cruise Control)\n- Automatic air conditioning system\n- Side mirrors the same color as the car Electrically adjustable and foldable Automatically when locking the car\n- 15\"\" alloy wheels\n- NISSANCONNECT SERVICES\n- Intelligent Around View Monitor (IAVM)\n- System for detecting and sending warning signals of moving objects and people from cameras around the car, Moving Object Detection (MOD)\n- LED headlights with LED Signature Light and automatic headlight on-off system.\n- Engine starting system from a remote key (Remote Engine Start)\n- Wireless charging device"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "KICKSe-POWER",
            "Year": 2024,
            "Price": "฿779900 - ฿939,900",
            "Style": {
                "Color": "12 color \nblack (black star) , \nred (radiant red) , \norange (monarch orange) , \nsilver (brilliant silver) , \nwhite (storm white) , \ngrey (gun meatllic) , \nblue (night blue) , \nred (radiant red) with black roof , \norange (monarch orange) with black roof , \nwhite (storm white) with black roof , \ngrey (gun meatllic) with black roof , \nblue (night blue) with black roof",
                "Body Type": "SUV",
                "Segment": "hybrid (e:HEV)",
                "Door": 5,
                "Seat": 5
            },
            "Performance": {
                "Gear": "auto",
                "Powered by": "gasoline , electric",
                "Fuel type": "Benzene",
                "Fuel tank capacity, liters": 41,
                "Consumption rate": "26.3 kilometers/liter",
                "Cylinder volume, cc": 1200,
                "Horsepower": 136
            },
            "Feature": {
                "Safety System": "- Dual front SRS airbags \n- Side airbags (Side Airbags) \n- Side Curtain Airbags \n- Anti-lock Braking System (ABS) \n- Electronic Brake Force Distribution System (EBD) \n- Brake Assist (BA) braking system \n- Immobilizer key system \n- Anti-theft alarm \n- Central locking system control button \n- ELR driver seat belt with retracting and automatic two-way tensioning (Double Pre-tensioner with Load Limiter) \n- Front passenger seat belt ELR with pre-tensioner and automatic tension release (Single Pre-tensioner with Load Limiter) \n- 3-point ELR rear seat belts, 3 positions \n- ISOFIX child seat mounting points \n- Child protection system for opening rear doors from inside the vehicle \n- Safety structure system Zone Body Concept \n- Third brake light",
                "Features": "- 6 airbags (Dual front SRS airbags, side airbags curtain airbag)\n- Sporty leather-wrapped steering wheel decorated with silver material, adjustable in 4 directions.\n- Rear parking distance warning\n- Technology to help warn you when you're tired while driving Driver Attention Alert (DAA)\n- Intelligent Forward Collision Warning (IFCW) technology to warn before collisions.\n- Intelligent Emergency Braking (IEB) technology\n- Automatic headlight on-off system\n- NissanConnect 8-inch touch screen with Apple CarPlay and Android auto connectivity\n- Intelligent Around View Monitor (IAVM) technology that detects and sends warning signals about moving objects. Moving Object Detection (MOD)\n- Intelligent Cruise Control (ICC) technology\n- Intelligent Rear View Mirror (IRVM) technology\n- Technology to detect objects behind the car while reversing, Rear Cross Traffic Alert (RCTA)\n- Technology to warn when the car leaves the Lane Departure Warning (LDW) lane.\n- High Beam Assist (HBA) automatic high beam on-off technology\n- Alloy wheels 17 x 6.5 J, gloss black"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "TERRA SPORT",
            "Year": 2024,
            "Price": "฿1,199,000 - ฿1,555,000",
            "Style": {
                "Color": "7 color\nblack (black star) ,\nwhite (white pearl) ,\nred (Coulis Red) ,\ngrey (stealth grey) ,",
                "Body Type": "SUV",
                "Segment": "versatile",
                "Door": 5,
                "Seat": 7
            },
            "Performance": {
                "Gear": "auto",
                "Powered by": "gasoline",
                "Fuel type": "Diesel",
                "Fuel tank capacity, liters": 78,
                "Consumption rate": "14.43 kilometers/liter",
                "Cylinder volume, cc": 2300,
                "Horsepower": 190
            },
            "Feature": {
                "Safety System": "- ABS braking system with EBD and BA\n- 6 airbags, front / side / and curtain airbags\n- B-LSD limited slip system\n- Vehicle Dynamic Control (VDC) automatic stability control technology\n- Rear window defogger wire panel\n- Third brake light, LED type\n- 1st row ELR seat belts, 3 points, 2 positions, adjustable. Equipped with an automatic pull-back and tension-relieving system. and a reminder system to fasten seat belts\n- 2nd row ELR seat belts, 3 points, 3 positions\n- 3rd row ELR seat belts, 3 points, 2 positions\n- ISOFIX child seat mounting points\n- Intelligent key system\n- Immobilizer key system with anti-theft alarm\n- Rear view camera\n- 4 rear parking distance warning signs\n- Zone Body safety structure\n- Side impact beams\n- collapsible steering wheel When a frontal collision occurs\n- Automatic fuel valve cut-off system In the case of a car overturning",
                "Features": "- Quad-Eye LED headlights and Daytime lights\n- 8\" touchscreen radio with Nissan Connect to connect to smartphones\n- The design allows the seat to be adjusted in many ways and the seat can be folded with just your fingertips with the Auto Tumble Seat.\n- Smart TFT meter screen displays 7-inch 3D driving information with Off-Road Meter.\n- 360 degree safety technology around the car (IFCW, IEB, LDW, IDA)\n- 2.3 liter twin turbo diesel engine, 190 horsepower, with 7 speed automatic transmission - with manual mode"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "NAVARA PRO-4X / PRO-2X",
            "Year": 2024,
            "Price": "฿1,030,000-฿1,160,000",
            "Style": {
                "Color": "4 color\ngrey (stealth grey) ,\nblack (black star) , \nwhite (white pearl) , \nred (burning red)",
                "Body Type": "Pickup",
                "Segment": "versatile",
                "Door": 4,
                "Seat": 5
            },
            "Performance": {
                "Gear": "auto",
                "Powered by": "gasoline",
                "Fuel type": "Diesel",
                "Fuel tank capacity, liters": 80,
                "Consumption rate": "14.56 kilometers/liter",
                "Cylinder volume, cc": 2300,
                "Horsepower": 190
            },
            "Feature": {
                "Safety System": "- ABS with EBD and BA\n- Rear Differential Lock\n- Dual front airbag with driver knee airbag driver side\n- Side airbag and Curtain airbag\n- Active Brake Limited Slip (ABLS)\n- Vehicle Dynamic Control (VDC)\n- Traction Control System (TCS)\n- Trailer Stability Assist (TSA)\n- Rear defogger\n- High mount stop lamp (LED Type)\n- Adjustable Front seat belt: ELR 3 points X 2 with pretensioner and load limiter\n- Rear seat seatbelt - ELR 3 points X 3\n- ISOFIX\n- Intelligent Key\n- Immobilizer\n- VSS Alarm\n- Rear view camera\n- Rear Parking Sensor\n- Zone body structure\n- Side impact door beam\n- Crashable steering column\n- Automatic fuel valve cut (When rollover)",
                "Features": "- Interlock front grille in an intense black color, decorated with red & orange Nissan emblem, Quad-eye LED headlamps, and the Daytime Running Light.\n- New 2.3-liter twin-turbo diesel engine of 190 horsepower and the 7-speed automatic transmission. Powerful, quiet, and fuel-saving.\n- INTELLIGENT FORWARD COLLISION WARNING (IFCW), INTELLIGENT EMERGENCY BRAKING (IEB), INTELLIGENT DRIVER ALERTNESS (IDA), and 7 SRS airbags.\n- INTELLIGENT BLIND SPOT INTERVENTION (IBSI), INTELLIGENT LANE INTERVENTION (ILI), and HIGH BEAM ASSIST (HBA).\n- Black sporty interior with the red-threaded Quole Modure seats and the power driver seat adjustable in 8 directions.\n- Interlock front grille in an intense black color, decorated with red & orange Nissan emblem, Quad-eye LED headlamps, and the Daytime Running Light.\n- New Black alloy wheels with the off-road All-terrain tires and fender flares.\n- INTELLIGENT AROUND VIEW MONITOR (IAVM) with 4x4 OFF-ROAD MODE.\n- INTELLIGENT BLIND SPOT INTERVENTION (IBSI), INTELLIGENT LANE INTERVENTION (ILI), and HIGH BEAM ASSIST (HBA).\n- Black sporty interior with the Quole Modure embroidered with PRO-4X emblem seats and the power driver seat adjustable in 8 directions.\n\n"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "NAVARA CALIBRE",
            "Year": 2024,
            "Price": "฿765,000-฿934,000",
            "Style": {
                "Color": "7 color\ngrey (stealth grey) ,\nred (burning red) ,\nblack (black star) , \nwhite (white pearl) , \ncopper (forged copper),\ngrey (twilight grey) ,\nsilver (brilliant silver)",
                "Body Type": "Pickup",
                "Segment": "versatile",
                "Door": "2,4",
                "Seat": "2,4"
            },
            "Performance": {
                "Gear": "manual",
                "Powered by": "gasoline",
                "Fuel type": "Diesel",
                "Fuel tank capacity, liters": 80,
                "Consumption rate": "15.23 kilometers/liter",
                "Cylinder volume, cc": 2300,
                "Horsepower": 163
            },
            "Feature": {
                "Safety System": "- ABS with EBD and BA\n- Dual front airbag\n- Active Brake Limited Slip (ABLS)\n- Vehicle Dynamic Control (VDC)\n- Traction Control System (TCS)\n- Trailer Stability Assist (TSA)\n- Rear defogger\n- High mount stop lamp (LED Type)\n- Adjustable Front seat belt: ELR 3 points X 2 with pretensioner and load limiter\n- Intelligent Key\n- Immobilizer\n- VSS Alarm\n- Rear view camera\n- Rear Parking Sensor\n- Zone body structure\n- Side impact door beam\n- Crashable steering column\n- Automatic fuel valve cut (When rollover)\n\n",
                "Features": "- Interlock front grille with Quad-eye LED headlamps and the Daytime Running Light\n- New 2.3-liter VGS turbo diesel engine of 163 horsepower. Powerful and fuel-saving\n- INTELLIGENT AROUND VIEW MONITOR (IAVM) with the MOVING OBJECT DETECTION (MOD) system\n- 8\" Touch screen radio display with the NissanConnect technology for smartphones connection\n- VEHICLE DYNAMIC CONTROL (VDC), TRACTION CONTROL SYSTEM (TCS), and the HILL START ASSIST (HSA) system\n- Tri-zone climate control A/C system, including the back passenger's zone\n- Exclusive black accessories: 18\" Black Alloy wheels with the full-car Black Edition graphic pattern to enhance the fierceness like no other\n- New 2.3-liter twin-turbo diesel engine of 190 horsepower with the 7-speed automatic transmission. Powerful, quiet, and fuel-saving.\nFront and side acoustic glass for a quiet cabin\n- INTELLIGENT FORWARD COLLISION WARNING (IFCW), \n- INTELLIGENT EMERGENCY BRAKING (IEB), and INTELLIGENT DRIVER ALERTNESS (IDA) system\n- INTELLIGENT BLIND SPOT INTERVENTION (IBSI), INTELLIGENT LANE INTERVENTION (ILI), and HIGH BEAM ASSIST (HBA)\n- Quole Modure leather seats with 8-direction adjustable power driver seat\n- 18\" Two-tone Alloy wheels"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "NAVARA KING CAB",
            "Year": 2024,
            "Price": "฿649,000-฿689,000",
            "Style": {
                "Color": "5 color \nblack (black star) , \ncopper (forged copper) , \nsilver (brilliant silver) , \nwhite (white solid) , \nwhite (white pearl) ,",
                "Body Type": "Pickup",
                "Segment": "versatile",
                "Door": 2,
                "Seat": 2
            },
            "Performance": {
                "Gear": "manual",
                "Powered by": "gasoline",
                "Fuel type": "Diesel",
                "Fuel tank capacity, liters": 80,
                "Consumption rate": "14.56 kilometers/liter",
                "Cylinder volume, cc": 2500,
                "Horsepower": 163
            },
            "Feature": {
                "Safety System": "- ABS with EBD and BA\n- Dual Front airbag\n- Laminated Glass\n- Rear defogger\n- High mount stop lamp (LED Type)\n- Adjustable Front seat belt: ELR 3 points X 2 with pretensioner and load limiter\n- Intelligent Key\n- Immobilizer with VSS alarm\n- Rear view camera\n- Zone body structure\n- Side impact door beam\n- Crashable steering column\n- Automatic fuel valve cut (When rollover)",
                "Features": "- 2.5-liter diesel engine with a maximum power of 163 horsepower (HPs) and maximum torque of 403 Newton-meters (Nm)\n- 205 mm. ground clearance with high-floor grade fender flares\n- Black interlock front grille with the tailgate spoiler for a touch of sportiness\n- 7-inch touch screen with NissanConnect that supports smartphone connectivity\n- New interior design with a sporty steering wheel, newly designed seats, and back area A/C\n- Remote control key with the central lock and auto door lock systems\n- 215 mm. ground clearance with 17\" alloy wheels and high-floor grade fender flares\n- Chromium interlock front grille with the automatically adjustable and foldable body-colored side mirrors\n- 8-inch touch screen with NissanConnect that supports smartphone connectivity\n- New interior design with a 3D color display and a sporty steering wheel installed with audio control buttons and cruise control system\n- Push Start, intelligent key and auto halogen headlamps"
            }
        },
        {
            "Brand": "Nissan",
            "Model": "NAVARA SINGLE CAB",
            "Year": 2024,
            "Price": "฿595,000-฿659,000",
            "Style": {
                "Color": "3 color\nwhite (white solid) ,\nsliver (brillaint sliver) ,\ngrey (twilight grey),\n",
                "Body Type": "Pickup",
                "Segment": "versatile",
                "Door": 2,
                "Seat": 2
            },
            "Performance": {
                "Gear": "manual",
                "Powered by": "gasoline",
                "Fuel type": "Diesel",
                "Fuel tank capacity, liters": 80,
                "Consumption rate": "14.56 kilometers/liter",
                "Cylinder volume, cc": 2500,
                "Horsepower": 163
            },
            "Feature": {
                "Safety System": "- ABS with EBD and BA\n- Dual Front airbag\n- Laminated Glass\n- Rear defogger\n- High mount stop lamp (LED Type)\n- Adjustable Front seat belt: ELR 3 points X 2 with pretensioner and load limiter\n- Intelligent Key\n- Immobilizer with VSS alarm\n- Rear view camera\n- Zone body structure\n- Side impact door beam\n- Crashable steering column\n- Automatic fuel valve cut (When rollover)",
                "Features": "- 2.5-liter diesel engine with a maximum power of 163 horsepower (HPs) and 403 Newton-meters (Nm) of torque.\n- Mono-Frame Chassis made from one single steel structure.\n- Side step for easier access to your truck bed.\n- Designed to carry cargo and lots of it; capable to fit 14 baskets or 14 boxes per layer and up to 40 pieces when carrying 3 layers with a total weight of 1,090 kg. Note: Box with dimension 35 cm x 50 cm x 32 cm. Baskets with dimension 37.2 cm x 57 cm x 30.3 cm.\n- 7-inch touch screen with NissanConnect that supports smartphone connectivity.\n- Speed sensing auto door lock.\n- Choose full-time 2WD for maximum efficiency or shift to 4WD at speeds up to 100 km/h. Select low range 4WD (4LO) for mud, sandy, or difficult terrain.\n\n\n\n\n\n"
            }
        }
    ]
}

当我运行我的代码时它不起作用。我尝试只删除两辆车的数据,但不起作用。但是当我删除线上很长的数据时,它就起作用了。当我尝试在没有长数据的情况下添加其他汽车时,它不起作用。如果有人能回答我的问题,非常感谢。我不太擅长编码,只是在学习。非常感谢您阅读这个问题,如果您回答的话,非常感谢!

node.js typescript parsing llama-index rag
1个回答
0
投票

如果只是按原样提供,LLM 在解释和输出 JSON 时往往会遇到问题,至少目前是这样。根据您发生错误的位置,LLM 似乎正在努力处理 JSON 格式,它可能不太理解这些长行中的一些数据

在查询 JSON 文档时,使用 llamaindex 的 JSON 查询引擎 会更方便。本质上,这允许您为 JSON 文件定义一个 LLM 可以理解的架构。在您的情况下,您的模式的骨架将是这样的:

const schema = {
  type: 'object',
  properties: {
    Car: {
      type: 'string',
    }, 
    year: {
      type: 'number',
    }
    active: {
      type: 'boolean',
    },
    models: {
      type: 'array',
      items: {
        type: 'object',
        properties: {
          ...
        }
      }
    }
  }
}

然后您可以使用以下代码致电您的法学硕士:

const jqe = new JSONQueryEngine({
  jsonValue: essay,
  jsonSchema: schema,
});

const answer = jqe.query({ query: 'your question' });
© www.soinside.com 2019 - 2024. All rights reserved.