holoviz / holoviz/param

Getting a "'_thread.RLock'" object error when instantiating a LangChain model as a default object

Open
#948 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
521
Forks
86
Avg merge
1d 13h
Merged PRs (30d)
35

Description

#### ALL software version info
param==2.1.0
langchain-openai==0.1.9

#### Description of expected behavior and the observed behavior
The following errors out when setting the default instantiation of a ChatOpenAI object on a parameter:

```python
import param
from langchain_openai import ChatOpenAI

class TestClass(param.Parameterized):
model = param.ClassSelector(class_=ChatOpenAI, default=ChatOpenAI())

TestClass()
```
![image](https://github.com/holoviz/param/assets/6779278/3976d180-74cd-43cb-86b5-40acc8a29103)

This is likely because `ChatOpenAI` is meant to handle concurrency.

I am able to work around this by instantiating the model in the __init__:

```python
import param
from langchain_openai import ChatOpenAI

class TestClass(param.Parameterized):
model = param.ClassSelector(class_=ChatOpenAI, default=None)

def __init__(self, **params):
super().__init__(**params)
self.model = ChatOpenAI()

TestClass()
```
This isn't an ideal solution, as it feels like a hacky workaround and adds overhead to the codebase.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.