hrishioa / wishful-search

Natural language search for complex JSON arrays, with AI Quickstart.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

autoAnalyzeObject throws error "No response from LLM while generating typespec!"

sweeetland opened this issue · comments

Following the example on the readme. My code looks like:

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const GPTLLMAdapter = LLMAdapters.getOpenAIAdapter(openai, {
  model: "gpt-4",
});

const results = await autoAnalyzeObject(
  data[0],
  GPTLLMAdapter.callLLM,
  "~/tmp",
);

I am receiving error error: No response from LLM while generating typespec! which is coming from file auto-analyze.js.

When I look at the code: https://github.com/hrishioa/wishful-search/blob/master/src/auto-analyze.ts#L190-L204 I can see:

  if (!typespec) {
    console.log('Generating typespec...');

    if (!typespec)
      throw new Error('No response from LLM while generating typespec!');

    const extractedTypeSpecs = typespec.match(/```typescript([\s\S]*?)```/g);

    if (extractedTypeSpecs?.length) {
      typespec = extractedTypeSpecs[0]
        .replace(/```typescript/g, '')
        .replace(/```/g, '')
        .trim();
    }
  }

This must be a bug, seems like we are forgetting to generate the typespec if it doesn't exist?

Good catch - fixed here! Reopen if it recurs or there's another issue.