This script gets errors for both HFTransformers and OpenAI, as the retriever and k arguments are getting passed to the llm call which throws errors as they are not supposed to be kwargs.
from datadreamer.llms import OpenAI
from datadreamer.steps import DataFromPrompt, DataFromAttributedPrompt, ProcessWithPrompt, RAGPrompt, Retrieve, TextDataSource, zipped
from datadreamer.retrievers import EmbeddingRetriever
from datadreamer.embedders import SentenceTransformersEmbedder, OpenAIEmbedder
with DataDreamer("./output"):
# Load GPT-4
gpt_4o_mini = OpenAI(model_name="gpt-4o-mini", api_key="sk...")
texts = TextDataSource(
name="load documents",
data_folder="./",
data_files="dataset.txt"
).shuffle(42).take(10).output["text"]
# Generate synthetic arXiv-style research paper abstracts with GPT-4
instruction_gen = ProcessWithPrompt(
"Generate prompts",
inputs={
'inputs': texts
},
args={
"llm": gpt_4o_mini,
"instruction": "Create a prompt for a large language model (LLM) to generate a relevant instruction, question, or command based on a given context snippet."
,
},
outputs={"generations": "instructions"},
)
instructions = instruction_gen.output["instructions"]
embedder = SentenceTransformersEmbedder("msmarco-bert-base-dot-v5")
retriever = EmbeddingRetriever(texts, embedder, truncate=True)
dataset = RAGPrompt(
name = 'Synthesizing Answers. ',
inputs = {
'prompts': instructions
},
args = {
'llm': gpt_4o_mini,
'retriever': retriever,
'k': 5,
},
outputs = {
'prompts': 'user',
'generations': 'context'
},
)
dataset.export_to_json("augmented.jsonl")
Traceback (most recent call last):
File "/home/legion/Desktop/data/gen_questions.py", line 36, in <module>
dataset = RAGPrompt(
^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step.py", line 337, in __init__
self.__setup_folder_and_resume()
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step.py", line 442, in __setup_folder_and_resume
self.__start()
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step.py", line 451, in __start
self._set_output(self.run())
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step.py", line 894, in _set_output
self.__output = _output_to_dataset(
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step_output.py", line 862, in _output_to_dataset
output = __output_to_dataset(
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/step_output.py", line 559, in __output_to_dataset
first_row = next(
^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/steps/prompt/_prompt_base.py", line 115, in get_generations
for prompt, generation, get_extra_columns in zip(
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/_cachable/_cachable.py", line 805, in _run_over_batches
yield from self._run_over_batches_locked(
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/_cachable/_cachable.py", line 771, in _run_over_batches_locked
results = self._run_over_sorted_batches(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/_cachable/_cachable.py", line 593, in _run_over_sorted_batches
run_batch(
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/llms/openai.py", line 333, in _run_batch
generated_texts_batch = list(
^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/llms/openai.py", line 316, in get_generated_texts
response = self.retry_wrapper(
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 336, in wrapped_f
return copy(f, *args, **kw)
^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/datadreamer/llms/openai.py", line 169, in _retry_wrapper
return func(**kwargs)
^^^^^^^^^^^^^^
File "/home/legion/miniconda3/envs/lilac/lib/python3.12/site-packages/openai/_utils/_utils.py", line 277, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'retriever'