Find answers from the community

Updated 2 years ago

Zsh

At a glance

The community member is trying to install and use the LlamaIndex library on their Mac, but is encountering errors when querying the index. The errors involve the zsh shell and unexpected tokens. Other community members suggest running the script with python instead of directly in the shell, and putting the query code inside the script file. The issue is resolved when the community member follows this advice and runs the script correctly.

Hi! I am trying to gett LlamaIndex installed on my Mac following the installation guide and tutorial . In the Starter Tutorial I got as far as building the index (over the provided Paul Graham essay), but run into an error when print(response)
zsh: missing end of stringI then query it, as follows:
response = index.query("What did the author do growing up?")
zsh: unknown file attribute: h
which of course results in response being empty:
print(response)
zsh: missing end of string
Any idea on what causes this, what it means and how it can be fixed?
L
B
m
13 comments
That is.... super weird.

Did you run your script with python my_script.py ?

Wondering why zsh is involved lol
@mu3arid Can you confirm what is your python env and where you are running the code in? VSCOde? Jupyter ? CoLab?
I am running Python 3.11.2 on this path:
/Users/my_user_name/anaconda3/envs/llama-env/bin/python
in the (llama-env) virtual environment.
I created a script called llama-index-test.py
containing just the code from the Starter Tutorial:

from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader documents = SimpleDirectoryReader('data').load_data() index = GPTSimpleVectorIndex.from_documents(documents)
I placed this script in […]/gpt_index/examples/paul_graham_essay/ from the cloned repository and ran it from there in the Terminal (v. 2.9.5) under MacOS Mojave (10.14.6). The terminal is set to use Z shell.

Does this provide any clues to the experts here?
How did you run the script?

To me, it seems like you did

./llama-index-test.py

instead of

python ./llama-index-test.py πŸ€”
If not, then I'm a little confused on how zsh is reading the file and giving errors πŸ˜…
So I changed back to bash, and am still getting an error, albeit a slightly different one:

(llama-env) AHH-2015:paul_graham_essay albrech$ python ./llama-index-test.py INFO:llama_index.token_counter.token_counter:> [build_index_from_nodes] Total LLM token usage: 0 tokens INFO:llama_index.token_counter.token_counter:> [build_index_from_nodes] Total embedding token usage: 17617 tokens (llama-env) AHH-2015:paul_graham_essay albrech$ response = index.query("What did the author do growing up?") -bash: syntax error near unexpected token ('`
PS: that should read: unexpected token `('
The error is not in the script of llama-index-test.py (which runs correctly, and yes, I had run it using python first. The error is in the subsequent response.
Ohhh I see.

You'll want to put the response = index.query(...), line inside of the llama-index-test.py script.

Since it's python, it can't run directly in the terminal like that πŸ‘
Thank you. I was beginning to suspect as much ;-). Shall try and report here afterwards
You might want to consider saving the index to disk as well, so you don't re-build it each time. But you'll get there if you keep following the docs πŸ‘πŸ‘
Worked. Newby that I am, I had to figure out that I need to put the response part inside the llama-index-test.py script for it to find the index. I'll take it from there. Thank you for your assistance! πŸ™‚
Awesome! Good luck in your python/llama index adventure πŸ’ͺ🫑:dotsHARDSTYLE:
Add a reply
Sign up and join the conversation on Discord