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.
本文标签:
版权声明:本文标题:fastapi - Error: Invalid input type <class 'langchain_core.prompts.chat.ChatPromptTemplate'>. Must 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1741529556a1873805.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论