Replies: 1 comment 6 replies
-
The "ValueError: Single '}' encountered in format string" error typically occurs when there are unescaped curly braces in your format string. In Python, you need to escape curly braces by doubling them ( In your code, the error might be occurring in the Here's a revised version of your code with the necessary adjustments: def retreival_qa_chain(chat_history_session, prompt, not_uuid):
embedding = OpenAIEmbeddings()
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0.5)
vector_store = PGVector(
connection_string=CONNECTION_STRING,
collection_name=not_uuid,
embedding_function=embedding,
)
retriever = vector_store.as_retriever(search_kwargs={"k": 8})
chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=retriever,
return_source_documents=True,
chain_type_kwargs={"prompt": prompt},
)
return chain
custom_message = generate_prompt(not_uuid)
qa_chains = retreival_qa_chain(
custom_message, not_uuid
)
chat_response = chat_langchain(qa_chains, query, not_uuid) Additionally, ensure that the prompt_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
{{context}}
Question: {{question}}
Helpful Answer:""" Make sure that any usage of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
I am getting below error while running the above code
Internal Server Error: /get-response/
Traceback (most recent call last):
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
return view_func(*args, **kwargs)
File "/home/ubuntu/app/CustomBot/chatbot/views.py", line 559, in GetChatResponse
chat_response = chat_langchain(qa_chains, query, not_uuid)
File "/home/ubuntu/app/CustomBot/accounts/common_langcain_qa.py", line 511, in chat_langchain
agent = initialize_agent(
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain_core/_api/deprecation.py", line 170, in warning_emitting_wrapper
return wrapped(*args, **kwargs)
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain/agents/initialize.py", line 75, in initialize_agent
agent_obj = agent_cls.from_llm_and_tools(
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain/agents/mrkl/base.py", line 134, in from_llm_and_tools
prompt = cls.create_prompt(
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain/agents/mrkl/base.py", line 104, in create_prompt
return PromptTemplate.from_template(template)
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain_core/prompts/prompt.py", line 282, in from_template
input_variables = get_template_variables(template, template_format)
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain_core/prompts/string.py", line 249, in get_template_variables
input_variables = {
File "/home/ubuntu/app/CustomBot/cenv/lib/python3.10/site-packages/langchain_core/prompts/string.py", line 249, in
input_variables = {
ValueError: Single '}' encountered in format string
System Info
langchain==0.2.11
langchain-anthropic==0.1.22
langchain-community==0.2.10
langchain-core==0.2.26
langchain-openai==0.0.5
langchain-qdrant==0.1.3
langchain-text-splitters==0.2.2
langchain-weaviate==0.0.2
langchainhub==0.1.14
Linux
Python 3.12.4
Beta Was this translation helpful? Give feedback.
All reactions