lmql icon indicating copy to clipboard operation
lmql copied to clipboard

RuntimeError: Failed to parse docstring of query function as LMQL code:

Open trummelbummel opened this issue 2 years ago • 2 comments

Platform: OSX Model: AzureModel Codex (loads successfully no issues). Interestingly this only happens when a python interpreter is used to execute the functions separately but not if it is run as part of a script. Hence it is not a major blocker but it is just something some people might run into.

Query I would like to define (but same error gets thrown at python example from documentation.)

@lmql.query(model=codex_model, decoder='argmax', top_p=1, temperature=0.0) def query_code_single_line(varname, df, question='Count occurences of distinct input_source in df.'): '''lmql """ #!/usr/bin/python3 import pandas as pd Write a single statement of code using pandas to answer the following: {question} df = {df} The output should be a new dataframe containing the result. Code : [CODE] """ '''

Error:

Traceback (most recent call last): File "", line 2, in File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/site-packages/lmql/init.py", line 161, in wrapper return query(fct, input_variables=input_variables, is_async=is_async, calling_frame=calling_frame, **extra_args) File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/site-packages/lmql/init.py", line 177, in query code = get_decorated_function_code(fct) File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/site-packages/lmql/utils/docstring_parser.py", line 65, in get_decorated_function_code raise RuntimeError("Failed to parse docstring of query function as LMQL code:\n\n" + str(source)) RuntimeError: Failed to parse docstring of query function as LMQL code:

After trying to execute the inspect method, I suspect it is an OS error related to Mac:

File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/site-packages/lmql/utils/docstring_parser.py", line 25, in get_decorated_function_code source = inspect.getsource(fct) File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/inspect.py", line 1139, in getsource lines, lnum = getsourcelines(object) File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/inspect.py", line 1121, in getsourcelines lines, lnum = findsource(object) File "/Applications/anaconda3/envs/llm_otd/lib/python3.10/inspect.py", line 958, in findsource raise OSError('could not get source code') OSError: could not get source code

trummelbummel avatar Aug 08 '23 09:08 trummelbummel

Thanks for reporting this. Can you go into more detail what you mean about "running the function separately"? There is a limitation, where Python's inspect will not be able to get the source for functions that are not defined in a file that can be found somewhere on disk, I think (cf. https://stackoverflow.com/questions/57035364/inspect-getsourcelinesobject-shows-oserror-if-run-from-python-shell-but-gives).

lbeurerkellner avatar Aug 08 '23 10:08 lbeurerkellner

Yes exactly, that is the issue. I just wanted to mention that if people want to test functions directly in their interpreter they will maybe run into this issue.

trummelbummel avatar Aug 08 '23 11:08 trummelbummel