-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unpickleable fields due to openai client #79
Conversation
openai_model: str = Field(alias="model") | ||
openai_api_key: Optional[str] = Field( | ||
default=os.getenv("OPENAI_API_KEY"), alias="api_key" | ||
) | ||
max_tokens: Optional[int] = 1000 | ||
splitter: Optional[str] = None | ||
|
||
_client: OpenAI = None | ||
@computed_field | ||
def _client(self) -> OpenAI: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need computed_field here but create a client on the fly in the Async version? let's use the unique approach if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the sync runtime actually uses its _client
, but the async runtime does not, it directly sends post requests in async_create_completion
. Even if it did use the python client lib instead of requests, it wouldn't make sense for the class to carry a single client instance because it would create them on demand to use them concurrently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niklub if you feel strongly about this I'll change it, but I think it's a meaningful difference that the async openai runtime doesn't need a self._client
35627d7
to
013c75a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #79 +/- ##
==========================================
+ Coverage 53.22% 53.25% +0.03%
==========================================
Files 42 42
Lines 1704 1703 -1
==========================================
Hits 907 907
+ Misses 797 796 -1 ☔ View full report in Codecov by Sentry. |
Bugfix -
/submit
requests to the server were failing with the following stack trace:The root cause is that the
OpenAI
client object inAsyncOpenAIChatRuntime
andOpenAIChatRuntime
was attempted to be serialized usingpickle.dumps()
, which is not supported after upgrading the openai client lib: openai/openai-python#837The solution was to make it a computed field in the sync client, and remove it from the async client as it is unused.