From 667f740315a076338cf4b30cd424cf6fb6797f3c Mon Sep 17 00:00:00 2001 From: Caleb Peffer <44934913+calebpeffer@users.noreply.github.com> Date: Sun, 28 Apr 2024 19:28:28 -0700 Subject: [PATCH] Caleb: converted llm response to json --- apps/api/src/__tests__/e2e_noAuth/index.test.ts | 3 ++- apps/api/src/__tests__/e2e_withAuth/index.test.ts | 11 ++++------- apps/api/src/lib/LLM-extraction/models.ts | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/apps/api/src/__tests__/e2e_noAuth/index.test.ts b/apps/api/src/__tests__/e2e_noAuth/index.test.ts index 271e848..356fe76 100644 --- a/apps/api/src/__tests__/e2e_noAuth/index.test.ts +++ b/apps/api/src/__tests__/e2e_noAuth/index.test.ts @@ -199,7 +199,8 @@ describe("E2E Tests for API Routes with No Authentication", () => { expect(completedResponse.body.data[0]).toHaveProperty("content"); expect(completedResponse.body.data[0]).toHaveProperty("markdown"); expect(completedResponse.body.data[0]).toHaveProperty("metadata"); - expect(completedResponse.body.data[0].content).toContain("🔥 FireCrawl"); + + }, 60000); // 60 seconds }); diff --git a/apps/api/src/__tests__/e2e_withAuth/index.test.ts b/apps/api/src/__tests__/e2e_withAuth/index.test.ts index ad4910a..9e3fed1 100644 --- a/apps/api/src/__tests__/e2e_withAuth/index.test.ts +++ b/apps/api/src/__tests__/e2e_withAuth/index.test.ts @@ -289,13 +289,10 @@ describe("E2E Tests for API Routes", () => { let llmExtraction = response.body.data.llm_extraction; - // Check if llm_extraction is a string and parse it if necessary - if (typeof llmExtraction === 'string') { - llmExtraction = JSON.parse(llmExtraction); - } - - - console.log('llm extraction', llmExtraction); + // // Check if llm_extraction is a string and parse it if necessary + // if (typeof llmExtraction === 'string') { + // llmExtraction = JSON.parse(llmExtraction); + // } // Print the keys of the response.body for debugging purposes diff --git a/apps/api/src/lib/LLM-extraction/models.ts b/apps/api/src/lib/LLM-extraction/models.ts index 7f50f72..71daa27 100644 --- a/apps/api/src/lib/LLM-extraction/models.ts +++ b/apps/api/src/lib/LLM-extraction/models.ts @@ -1,6 +1,5 @@ import OpenAI from 'openai' import { z } from 'zod' -import { ScraperLoadResult } from './types' import { Document, ExtractorOptions } from "../../lib/entities"; // import { @@ -76,7 +75,8 @@ export async function generateOpenAICompletions({ const c = completion.choices[0].message.tool_calls[0].function.arguments // Extract the LLM extraction content from the completion response - const llmExtraction = c; + const llmExtraction = JSON.parse(c); + // Return the document with the LLM extraction content added return {