admin管理员组

文章数量:1130349

I'm trying to make small project, which can save text from flutter app to mongo db and get text with fastAPI, make good answer with langchain openai llm.

what I finally want is generating RAG answer with text data but now I just want to make just answer with small string data.

so I wrote codes like below,

@app.post("/generate-rag")
async def generate_rag(request: RAGRequest):
    try:
        # JSON 데이터를 문서 형식으로 로드
        documents = [{"id": doc["id"], "text": doc["text"]} for doc in request.texts]

        # LangChain 설정
        chat = ChatOpenAI(
            temperature=0.1,
            model_name = "gpt-3.5-turbo"
        )
        user_prompts = "\n".join([doc["text"] for doc in documents])

        f = open("prompts.txt", "w")
        f.write(user_prompts)
        # it saved as a string,  but documents was written as Korean, so there has a encoding issue.

        chat_prompt = ChatPromptTemplate([
            ("system", "당신은 일기 속의 뛰어난 상담가입니다. 일기의 내용을 바탕으로 적합한 상담 답변을 해주세요."),
            ("user", user_prompts)
        ])

        # 답변 생성
        response = chat.invoke(chat_prompt)

        return {"answer": response}
    except Exception as e:
        print(f"Error: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error generating RAG answer: {str(e)}")

but I got this..

Error: Invalid input type <class 'langchain_core.prompts.chat.ChatPromptTemplate'>. Must be a PromptValue, str, or list of BaseMessages.

where am I wrong? I tried googling, asking to gpt, but still can't solve the error.

I tried to see what is in user prompts so I wrote them in text file, so I found they are just a string as I respected.

I'm trying to make small project, which can save text from flutter app to mongo db and get text with fastAPI, make good answer with langchain openai llm.

what I finally want is generating RAG answer with text data but now I just want to make just answer with small string data.

so I wrote codes like below,

@app.post("/generate-rag")
async def generate_rag(request: RAGRequest):
    try:
        # JSON 데이터를 문서 형식으로 로드
        documents = [{"id": doc["id"], "text": doc["text"]} for doc in request.texts]

        # LangChain 설정
        chat = ChatOpenAI(
            temperature=0.1,
            model_name = "gpt-3.5-turbo"
        )
        user_prompts = "\n".join([doc["text"] for doc in documents])

        f = open("prompts.txt", "w")
        f.write(user_prompts)
        # it saved as a string,  but documents was written as Korean, so there has a encoding issue.

        chat_prompt = ChatPromptTemplate([
            ("system", "당신은 일기 속의 뛰어난 상담가입니다. 일기의 내용을 바탕으로 적합한 상담 답변을 해주세요."),
            ("user", user_prompts)
        ])

        # 답변 생성
        response = chat.invoke(chat_prompt)

        return {"answer": response}
    except Exception as e:
        print(f"Error: {str(e)}")
        raise HTTPException(status_code=500, detail=f"Error generating RAG answer: {str(e)}")

but I got this..

Error: Invalid input type <class 'langchain_core.prompts.chat.ChatPromptTemplate'>. Must be a PromptValue, str, or list of BaseMessages.

where am I wrong? I tried googling, asking to gpt, but still can't solve the error.

I tried to see what is in user prompts so I wrote them in text file, so I found they are just a string as I respected.

本文标签: