Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'type' object is not subscriptable #14

Open
SvenPfiffner opened this issue May 5, 2024 · 2 comments
Open

TypeError: 'type' object is not subscriptable #14

SvenPfiffner opened this issue May 5, 2024 · 2 comments

Comments

@SvenPfiffner
Copy link

Hi there!
First of all many thanks to you for your great work on this lightweight and intuitive llama interface. I got it running and inferring within minutes and was more than impressed.

I ran into one small issue during setting it up though:

Bug:
Importing the package under python < 3.9 via

from llama_ai import LlamaAI

throws

(gguf_llama.py, line 55) - TypeError: 'type' object is not subscriptable

Suspected reason
Typing syntax in the function definition of create_embeddings is only supported from python 3.9 onwards

def create_embeddings(self, text:str) -> list[float]:

Fix
To get the package running on python < 3.9 (in my case 3.8.19), simply remove typing for the return type like this

def create_embeddings(self, text:str):

a cleaner fix could be to use the typing module there, which is compatible with previous python versions.

I am not sure whether compatibility with python < 3.9 is intended for this package at all, but I can verify that this small fix makes this amazing project work under python 3.8.

@laelhalawani
Copy link
Owner

Kind thanks for your input, I really appreciate it.
We could think up a version for 3.8, since it takes just that to make it compatible.
Did you have any other issues with 3.8?

@SvenPfiffner
Copy link
Author

No, otherwise it works like a charm for me.

What I did to get it working on 3.8 was importing "List" from the already imported "typing" package and using that instead of pythons built-in "list", which got support for typing in 3.9. So the following two changes where all that was needed to have your package working under python 3.8

from typing import Any, Optional, Union, List
...
def create_embeddings(self, text:str) -> List[float]

instead of

from typing import Any, Optional, Union
...
def create_embeddings(self, text:str) -> list[float]

Thanks again for your amazing work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants