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

Fixed error in type hints #326

Merged
merged 2 commits into from
Sep 6, 2023
Merged

Conversation

Souryadipstan
Copy link
Contributor

Description

I encountered this error while trying to import OpenAIInstructionParser, TaskType. Then, I solved that issue and further checked that the same issue is present in other files too, so solved them. also, pre-commit was throwing FI58 error while merging the new changes to added a parameter in pre-commit config to ignore the particular error.

TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from prompt2model.prompt_parser import OpenAIInstructionParser, TaskType
3 prompt_spec = OpenAIInstructionParser(task_type=TaskType.TEXT_GENERATION)
4 prompt_spec.parse_from_prompt(prompt)

File ~/.pyenv/versions/3.8.17/lib/python3.8/site-packages/prompt2model/prompt_parser/init.py:3
1 """Import PromptSpec classes."""
2 from prompt2model.prompt_parser.base import PromptSpec, TaskType
----> 3 from prompt2model.prompt_parser.instr_parser import OpenAIInstructionParser
4 from prompt2model.prompt_parser.mock import MockPromptSpec
6 all = (
7 "PromptSpec",
8 "TaskType",
9 "MockPromptSpec",
10 "OpenAIInstructionParser",
11 )

File ~/.pyenv/versions/3.8.17/lib/python3.8/site-packages/prompt2model/prompt_parser/instr_parser.py:15
10 from prompt2model.prompt_parser.base import PromptSpec, TaskType
12 from prompt2model.prompt_parser.instr_parser_prompt import ( # isort: split
13 construct_prompt_for_instruction_parsing,
14 )
---> 15 from prompt2model.utils import (
16 OPENAI_ERRORS,
17 ChatGPTAgent,
18 get_formatted_logger,
19 handle_openai_error,
20 )
22 logger = get_formatted_logger("PromptParser")
24 os.environ["TOKENIZERS_PARALLELISM"] = "false"

File ~/.pyenv/versions/3.8.17/lib/python3.8/site-packages/prompt2model/utils/init.py:10
3 from prompt2model.utils.openai_tools import (
4 OPENAI_ERRORS,
5 ChatGPTAgent,
6 count_tokens_from_string,
7 handle_openai_error,
8 )
9 from prompt2model.utils.rng import seed_generator
---> 10 from prompt2model.utils.tevatron_utils import encode_text, retrieve_objects
12 all = ( # noqa: F401
13 "ChatGPTAgent",
14 "encode_text",
(...)
20 "get_formatted_logger",
21 )

File ~/.pyenv/versions/3.8.17/lib/python3.8/site-packages/prompt2model/utils/tevatron_utils/init.py:3
1 """Import Tevatron utility functions."""
2 from prompt2model.utils.tevatron_utils.encode import encode_text
----> 3 from prompt2model.utils.tevatron_utils.retrieve import retrieve_objects
5 all = ("encode_text", "retrieve_objects")

File ~/.pyenv/versions/3.8.17/lib/python3.8/site-packages/prompt2model/utils/tevatron_utils/retrieve.py:11
4 import numpy as np
5 from tevatron.faiss_retriever import BaseFaissIPRetriever
8 def retrieve_objects(
9 query_vector: np.ndarray,
10 encoded_datasets_path: str,
---> 11 document_names: list[str],
12 depth: int,
13 ) -> list[tuple[str, float]]:
14 """Return a ranked list of object indices and their scores.
15
16 Args:
(...)
22 Ranked list of object names and their inner product similarity to the query.
23 """
24 assert query_vector.shape[0] == 1, "Only a single query vector is expected."

TypeError: 'type' object is not subscriptable

References

Below mentioned issue is solved by this PR

@neubig neubig self-requested a review September 6, 2023 10:40
Copy link
Collaborator

@neubig neubig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, and also fixes #323

@neubig neubig merged commit 469a116 into neulab:main Sep 6, 2023
8 checks passed
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

Successfully merging this pull request may close these issues.

3 participants