-
Notifications
You must be signed in to change notification settings - Fork 1
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
Serialize and deserialize chains #11
base: main
Are you sure you want to change the base?
Conversation
c9473ff
to
160ec67
Compare
44b42aa
to
c2cdd49
Compare
const compilerOptions = serialized.compilerOptions || {} | ||
|
||
if ( | ||
typeof serialized !== 'object' || |
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.
I don't think this is a rigorous check because Arrays will also be true for this. I saw this check Variable.constructor === Object
is more rigorous. https://www.geeksforgeeks.org/how-to-check-if-a-value-is-object-like-in-javascript/
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.
But an array is not a valid serialized value
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.
Then why are you checking that these are objects?
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.
Yep, honestly this was AI generated 😂
</step> | ||
`) | ||
|
||
const chain = new Chain({ prompt, adapter: Adapters.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.
Do more tests that include parameters and compile options
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.
Also a test that tests that consecutive serialize(deserialize(serialize()))
operations do not degrade the state of the chain would be nice too
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.
How is it possible to degrade the state?
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.
idk we could break something in the future, the test is to ensure we catch that
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.
What I mean is that for example, serialize(deserialize(serialize())) == serialize()
We want to allow to store prompt state half compiled. This is helpful when using tool calls where user needs to receive a response from the AI that contains a tool call, do some work and respond back with the result of that work. In this scenario we need to serialize current compilation state to restart the compilation from that point.
c2cdd49
to
e257205
Compare
const compilerOptions = serialized.compilerOptions || {} | ||
|
||
if ( | ||
typeof serialized !== 'object' || |
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.
Then why are you checking that these are objects?
</step> | ||
`) | ||
|
||
const chain = new Chain({ prompt, adapter: Adapters.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.
idk we could break something in the future, the test is to ensure we catch that
</step> | ||
`) | ||
|
||
const chain = new Chain({ prompt, adapter: Adapters.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.
What I mean is that for example, serialize(deserialize(serialize())) == serialize()
What?
The short version is that we want a way to serialize the chain to be stored in a cache system. Things that have to be serialized are the
ast
of the prompt and the scope. Now Scopes are JS classes that we need to transform into serializable JS objectsMore details in this PR
TODO
ast
scope
adapter
compilerOptions
OR
JS object or JSON-like data and build a chainAdapter
Adapter is a class so it needs to be serialized. Maybe just a reference to the identifier
default
,openai
,anthrophic
,...NOTE
Added
.prettierrc
so some unrelated changes