Find answers from the community

Updated 3 months ago

Encode

Error 'list' object has no attribute 'encode'
on this
response = chat_engine.chat("What is this book about?")

my code is from tutorial https://gpt-index.readthedocs.io/en/latest/examples/chat_engine/chat_engine_react.html#get-started-in-5-lines-of-code
L
А
16 comments
You followed that exactly? Can I see your code?
I disabled "just my code debugging". Error is here
Oh its llama cpp error

Add blank space to start of prompt to match OG llama tokenizer

prompt_tokens: List[int] = (
self.tokenize(prompt.encode("utf-8"))
Following the example hey 😉
Your messages to prompt function is incorrect
It should take a list of ChatMessage objects and return a single string prompt
response = chat_engine.chat(
"Use the tool to answer what did Paul Graham do in the summer of 1995?"
)
This is in tutorial
Right but there's a bunch of other stuff you've changed 😅

Fix the function I mentioned about and you'll be good
Did I used part of tutorial for OpenAI and part for cutom LLM and this is wrong?
Did not specified service_context It needed if use custom llm
You probably want something like this

Plain Text
LLM_TEMPLATE = "### Instruction:\n\n{instruction}\n\n### Response:\n\n"

def messages_to_prompt(messages):
    message_str = "\n".join([str(x) for x in messages])
    prompt = LLM_TEMPLATE.format(instruction=message_str)
    return prompt

def completion_to_prompt(completion):
    prompt = LLM_TEMPLATE.format(instruction=completion)
    return completion
Oh Im sorry. I understand where the problem was. I defined messages_to_prompt function and used this wrong. It should return string, not list.
Add a reply
Sign up and join the conversation on Discord