Input is not stringable
when processing system message. system_prompt = "You are a helpful asistant." user_prompt = "Give me five reasons to try {query}." prompt = ChatPromptTemplate( ChatMessage(role="system", content=system_prompt), ChatMessage(role="user", content=user_prompt), pipeline = QueryPipeline(chain=[prompt, llm]) output = pipeline.run(query="diving")
from llama_index.core import ChatPromptTemplate from llama_index.core.llms import ChatMessage, MessageRole message_templates = [ ChatMessage(content="You are an expert system.", role=MessageRole.SYSTEM), ChatMessage( content="Generate a short story about {topic}", role=MessageRole.USER, ), ] chat_template = ChatPromptTemplate(message_templates=message_templates)
Traceback (most recent call last): File "/home/magnesium/Projects/LLM/local-rag/test.py", line 34, in <module> output = pipeline.run(query="diving") File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/query_pipeline/query.py", line 319, in run return self._run( File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/query_pipeline/query.py", line 442, in _run result_outputs = self._run_multi({root_key: kwargs}) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/query_pipeline/query.py", line 544, in _run_multi output_dict = module.run_component(**module_input) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/base/query_pipeline/query.py", line 198, in run_component kwargs = self.validate_component_inputs(kwargs) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/base/query_pipeline/query.py", line 187, in validate_component_inputs return self._validate_component_inputs(input) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/llms/llm.py", line 702, in _validate_component_inputs input["prompt"] = validate_and_convert_stringable(input["prompt"]) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/base/query_pipeline/query.py", line 57, in validate_and_convert_stringable new_input_list.append(validate_and_convert_stringable(elem)) File "/home/magnesium/.pyenv/versions/lrag/lib/python3.10/site-packages/llama_index/core/base/query_pipeline/query.py", line 64, in validate_and_convert_stringable raise ValueError(f"Input {input} is not stringable.") ValueError: Input system: You are a helpful asistant. is not stringable.
from llama_index.core.llms import ChatMessage from llama_index.core import ChatPromptTemplate from llama_index.core.query_pipeline import QueryPipeline from llama_index.llms.llama_cpp import LlamaCPP from dotenv import load_dotenv import os load_dotenv() llm = LlamaCPP( model_path=os.getenv("LLAMACPP_MODEL"), temperature=0.0, max_new_tokens=1024, context_window=8192, model_kwargs={"n_gpu_layers": -1, "n_batch": 512}, ) system_prompt = "You are a helpful asistant." user_prompt = "Give me five reasons to try {query}." prompt = ChatPromptTemplate( [ChatMessage(role="system", content=system_prompt), ChatMessage(role="user", content=user_prompt)], ) pipeline = QueryPipeline(chain=[prompt, llm], verbose=True) output = pipeline.run(query="diving")
(venv) python ./test_pipeline.py > Running module 75f80bac-9ba4-4b3b-9606-a6e767990d6e with input: query: diving > Running module 265b3d3f-28ae-41ad-9c0e-ca25bd5898d6 with input: messages: [ChatMessage(role=<MessageRole.SYSTEM: 'system'>, content='You are a helpful asistant.', additional_kwargs={}), ChatMessage(role=<MessageRole.USER: 'user'>, content='Give me five reasons to try diving... assistant: 1. Explore a whole new world: Diving allows you to discover the beauty and wonder of the underwater world, with vibrant marine life, colorful coral reefs, and fascinating underwater landscapes waiting to be explored. 2. Relaxation and stress relief: Diving can be a therapeutic and calming experience, as you immerse yourself in the peaceful underwater environment and focus on your breathing and movements. 3. Adventure and excitement: Diving offers the thrill of exploring unknown depths and encountering marine creatures up close, providing an adrenaline rush and a sense of adventure unlike any other activity. 4. Physical fitness: Diving is a great way to stay active and improve your overall fitness, as it engages multiple muscle groups and requires strength, flexibility, and endurance to navigate the water and currents. 5. Conservation and environmental awareness: Diving can also raise awareness about the importance of protecting our oceans and marine ecosystems, as you witness firsthand the beauty and fragility of underwater life, inspiring you to become a more responsible steward of the environment.
prompt = ChatPromptTemplate( [ChatMessage(role="system", content=system_prompt), ChatMessage(role="user", content=user_prompt)], ) input = prompt.format_messages(query="diving") output = llm.chat(input)
llm.metadata
-- part of that is declaring whether the LLM is a chat model or notfrom llama_index.core.llms.llm import LLMChatComponent pipeline = QueryPipeline(chain=[prompt, LLMChatComponent(llm=llm)], verbose=True)