Получение ValueError: отсутствуют некоторые входные ключи: {'\n "_id"'} в LangchainPython

Программы на Python
Anonymous
Получение ValueError: отсутствуют некоторые входные ключи: {'\n "_id"'} в Langchain

Сообщение Anonymous »

main.py

Код: Выделить всё

llm_openai = ChatOpenAI(openai_api_key=OPEN_AI_KEY, model='gpt-3.5-turbo-0125')
table_schema = ConfigData.TABLE_SCHEMA
schema_description = ConfigData.SCHEMA_DESCRIPTION
json_ex_1 = ConfigData.FEW_SHOT_EXAMPLE_1
json_ex_string = json.dumps(json_ex_1)
prompt_template_for_creating_query = """
You are an expert in crafting NoSQL queries for MongoDB with 10 years of experience, particularly in MongoDB.
I will provide you with the table_schema and schema_description in a specified format.
Your task is to read the user_question, which will adhere to certain guidelines or formats, and create a NOSQL MongoDb pipeline accordingly.

Table schema:""" +  table_schema + """
Schema Description: """ + schema_description + """

Here are some example:
Input: Find movies by Quentin Tarantino and include a count of how many actors are in each movie
Output: {json_ex_string_1}

Note: You have to just return the query nothing else. Don't return any additional text with the query.
Input: {user_question}
"""
query_creation_prompt = PromptTemplate(
template=prompt_template_for_creating_query,
input_variables=["user_question", "json_ex_string_1"],
)
llmchain = LLMChain(llm=llm_openai, prompt=query_creation_prompt, verbose=True)
def get_query(user_question):
response = llmchain.invoke({
"user_question": user_question,
"json_ex_string_1": json_ex_string
})

response_text = response['text'].replace("Output: ", "")
pattern = r'db\.collectionName\.aggregate\(\s*\['

output_string = re.sub(pattern, '', response_text)

return json.loads(output_string)
client = pymongo.MongoClient(ConfigData.MONGO_DB_URI)
db = client[ConfigData.DB_NAME]
collection_name = db[ConfigData.COLLECTION_NAME]
query_1 = get_query(user_question="when InnovateTech Solutions founded?")
Ошибка получения:

Код: Выделить всё

  ValueError: Missing some input keys: {'\n        "_id"'}
Я пытаюсь сгенерировать запросы агрегации MongoDB, используя LangChain с OpenAI GPT-3.5. Однако я обнаружил ошибку ValueError, сообщающую, что некоторые клавиши ввода отсутствуют.
Вот моя настройка:
  • У меня есть PromptTemplate, который должен генерировать запросы MongoDB на основе заданной схемы и вопроса пользователя.
  • Я вызываю цепочку с помощью метода ignore.


Подробнее здесь: https://stackoverflow.com/questions/788 ... -langchain

Вернуться в «Python»