lmql
lmql copied to clipboard
RuntimeError: Failed to parse docstring of query function as LMQL code:
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 "
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
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).
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.