ItzCrazyKns / Perplexica

Perplexica is an AI-powered search engine. It is an Open source alternative to Perplexity AI
MIT License
12.68k stars 1.19k forks source link

npm build error #246

Closed devops-snap-shoot closed 1 month ago

devops-snap-shoot commented 1 month ago

Describe the bug there is shown a Conversion of type error as follow To Reproduce Steps to reproduce the behavior:

  1. npm run build (on the root backend)

Expected behavior A clear and concise description of what you expected to happen.

Additional context error log: npm run build

perplexica-backend@1.7.1 build tsc

src/agents/suggestionGeneratorAgent.ts:50:4 - error TS2352: Conversion of type 'BaseChatModel<BaseLanguageModelCallOptions, BaseMessageChunk>' to type 'ChatOpenAI' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Type 'BaseChatModel<BaseLanguageModelCallOptions, BaseMessageChunk>' is missing the following properties from type 'ChatOpenAI': temperature, topP, frequencyPenalty, presencePenalty, and 11 more.

50 (llm as ChatOpenAI).temperature = 0;


src/websocket/connectionManager.ts:52:7 - error TS2739: Type 'ChatOpenAI<ChatOpenAICallOptions>' is missing the following properties from type 'BaseChatModel<BaseLanguageModelCallOptions, BaseMessageChunk>': getLsParams, _streamEventsV2, _streamEventsV1

52       llm = new ChatOpenAI({

Found 2 errors in 2 files.

Errors Files 1 src/agents/suggestionGeneratorAgent.ts:50 1 src/websocket/connectionManager.ts:52 a I ask GPT and told me :

The errors you're encountering are related to TypeScript type incompatibilities between BaseChatModel and ChatOpenAI. These errors suggest that the types BaseChatModel and ChatOpenAI are not compatible and that explicit type conversions might be necessary.

Here's a step-by-step guide to resolve these errors:

Step 1: Examine the Type Definitions

First, let's understand the type definitions and why these errors occur. The error messages indicate that BaseChatModel and ChatOpenAI do not share the same properties. To fix this, you need to ensure that the type conversion is handled correctly.

Step 2: Update the Type Conversions

  1. Fix in src/agents/suggestionGeneratorAgent.ts:

    Update the type conversion to use unknown first, and then cast to ChatOpenAI to avoid the type incompatibility error.

    (llm as unknown as ChatOpenAI).temperature = 0;
  2. suggested Fix in src/websocket/connectionManager.ts:

import type { BaseLanguageModelCallOptions } from '@langchain/core/language_models/base'; Update the llm type:

let llm: BaseChatModel | undefined; Update the casting for ChatOpenAI:

} else if (chatModelProvider === 'custom_openai') { llm = new ChatOpenAI({ modelName: chatModel, openAIApiKey: searchParams.get('openAIApiKey') || '', temperature: 0.7, configuration: { baseURL: searchParams.get('openAIBaseURL') || '', }, }) as unknown as BaseChatModel; }

ItzCrazyKns commented 1 month ago

Hi, I am not able to reproduce this issue, can you provide more context

devops-snap-shoot commented 1 month ago

No worries and thanks for the mail, I update the Issue with some comment on a possible problem and proposed solution by CHATGPT, that works for my local repo. Many thanks for such a great work you are doing and keep creating!!! 😉 Marc

El sáb, 6 jul 2024 a la(s) 5:31 a.m., ItzCrazyKns @.***) escribió:

Hi, I am not able to reproduce this issue, can you provide more context

— Reply to this email directly, view it on GitHub https://github.com/ItzCrazyKns/Perplexica/issues/246#issuecomment-2211719659, or unsubscribe https://github.com/notifications/unsubscribe-auth/BCFWMDRBSJLCOMA42AJZK33ZK62PVAVCNFSM6AAAAABKN56CL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJRG4YTSNRVHE . You are receiving this because you authored the thread.Message ID: @.***>