weave
weave copied to clipboard
TypeError: op.<locals>.wrap() takes 1 positional argument but 2 were given
Adding weave.op
causes my code to break. I prepared a notebook to reproduce the issue:
https://colab.research.google.com/drive/1XRU11SIytHXqiO4mV3CYy5JePw1B2YJC?usp=sharing
TypeError Traceback (most recent call last)
[<ipython-input-16-be0796def7f5>](https://localhost:8080/#) in <cell line: 1>()
1 while True:
2 new_msg = input("Your msg:")
----> 3 await graph.run(dict(chat=[HumanMessage(content=new_msg)]))
4
[/usr/local/lib/python3.10/dist-packages/state_graph/__init__.py](https://localhost:8080/#) in run(self, input)
412 return self.context, False
413
--> 414 context_update = await self.current_node.run(self.context)
415 self.context = update_context(self.context, context_update)
416
TypeError: op.<locals>.wrap() takes 1 positional argument but 2 were given
Hello @SalamanderXing - thank you very much for your bug report and reproduction. To fix your code, please call the wrapper:
@weave.op # change this to `@weave.op()`
async def run(self, context: Context):
...
so the resulting code should be
@weave.op()
async def run(self, context: Context):
...
Note: in colab, you have to call weave.init()
in any cell that uses await
due to an odd colab bug. So add weave.init
to the cell with the while loop as well.
Note to team: this should be broken into 2 tickets:
- When wrapping a method with our wrapper, we should consider making the calling optional (especially since it takes no arguments). Or at the very least give a good error message.
- We should attempt to patch the colab bug
Hi @tssweeney, thank you for your reply That indeed fixed that issue. Still, I'm getting another error trying to apply Weave in my source code, I modified the notebook to reproduce that one too. It's most likely due to pydantic v1 vs v2 mismatch. The error is different but related to #1579. Please let me know if I should open a new issue.
ValueError Traceback (most recent call last)
[<ipython-input-8-ebb6a4560175>](https://localhost:8080/#) in <cell line: 2>()
1 new_msg = 'Hello'
----> 2 await graph.run(dict(chat=[HumanMessage(content=new_msg)]))
6 frames
[/usr/local/lib/python3.10/dist-packages/state_graph/graph.py](https://localhost:8080/#) in run(self, input)
230 return self.context, False
231
--> 232 context_update = await self.current_node.run(self.context)
233 self.context = utils.update_context(self.context, context_update)
234
[/usr/local/lib/python3.10/dist-packages/weave/trace/op.py](https://localhost:8080/#) in _run_async()
83 awaited_res = res
84 with run_context.current_run(run):
---> 85 output = await awaited_res
86 client.finish_call(run, output)
87 if not parent_run:
[<ipython-input-6-a1cb94fb5bc1>](https://localhost:8080/#) in run(self, context)
12 @weave.op()
13 async def run(self, context: Context):
---> 14 test_prompt_formatted = self.test_prompt.format(test='test')
15 new_msg = AIMessage(content=f'Thank u for ur message {test_prompt_formatted}')
16 await self.stream_token(new_msg.content)
[/usr/local/lib/python3.10/dist-packages/weave/trace/vals.py](https://localhost:8080/#) in pydantic_getattribute(self, name)
115 except AttributeError:
116 return None
--> 117 res = attribute_access_result(self, attribute, name)
118 return res
119
[/usr/local/lib/python3.10/dist-packages/weave/trace/vals.py](https://localhost:8080/#) in attribute_access_result(self, val_attr_val, attr_name)
135
136 gc = require_graph_client()
--> 137 return make_trace_obj(
138 val_attr_val,
139 new_ref,
[/usr/local/lib/python3.10/dist-packages/weave/trace/vals.py](https://localhost:8080/#) in make_trace_obj(val, new_ref, server, root, parent)
449 val = val.__get__(parent, type(parent))
450 box_val = box.box(val)
--> 451 setattr(box_val, "ref", new_ref)
452 return box_val
453
[/usr/local/lib/python3.10/dist-packages/pydantic/v1/main.py](https://localhost:8080/#) in __setattr__(self, name, value)
355
356 if self.__config__.extra is not Extra.allow and name not in self.__fields__:
--> 357 raise ValueError(f'"{self.__class__.__name__}" object has no field "{name}"')
358 elif not self.__config__.allow_mutation or self.__config__.frozen:
359 raise TypeError(f'"{self.__class__.__name__}" is immutable and does not support item assignment')
ValueError: "PromptTemplate" object has no field "ref"
Hi @SalamanderXing - thank you for the repro. There is something definitely odd going on here. Let me try to summarize:
- As discussed in https://github.com/wandb/weave/issues/1579, you cannot use Pydantic V1 as type annotations on Weave Objects.
- You have to "call" the
weave.op
decorator. My colleague @jamie-rasmussen fixed this in the next release here: https://github.com/wandb/weave/commit/2818f451c2161c4a92efe1e744e7f2cee2b18339 - In your case, the last cell in your notebook throws the error your quote above. Note: if i as
weave.init
to that cell (per my comment above), it works every other time. This is very odd.
I am going to create two internal tickets. Note: these links are not publicly accessible.
- Support PydanticV1 as properties: https://wandb.atlassian.net/browse/WB-18538
- Investigate consistent failing in this case (could be pydantic... also could be the async/await in notebooks): https://wandb.atlassian.net/browse/WB-18539
We will update this thread upon further information. Please allow us a few days to investigate.
Reopening after accidentally hitting "close" button.
Interesting. FYI the previous version of the notebook, before I put a pydantic v1 object as property of the Reply object, worked without me having to put weave.init in every cell that uses await.
Hi @SalamanderXing I just merged in some changes that should unblock you. In particular, fixed the PydanticV1 issue you described as well as another issue I noticed while working with your repro.
Open items still (although both of these have workarounds):
- Using PydanticV1 types in annotations
- using
await
in a colab removes theweave.init
status upon cell completion, requiring you to re-init after such calls
Thanks @tssweeney. In the meantime I migrated away from langchain so im now using only Pydantic v2 :)