| Thing is: you don't read it easily. It's basically a custom DSL bolted on top of Javascript that hides actual functionality beneath an Everest of abstractions. That is, it's a yet another library trying to force Haskell/Haskellisms into Javascript and claiming with no proof other than emotions that it's so much better and more readable than something. Here's an actual readable version of that: try{
return getTurnPromptMessages(state, action)
.map(mkCCRequestFromMessages)
.map(addSchemaToRequest)
.map(handleChatCompletion)
.map(extractFirstCompletionChoice)
.map(extractChatCompletionMessage)
.map(decodeSchema)
.map(detectLocation);
} catch (e) {
mkMessageError(e);
}
It can be further simplified. For example, you don't need two separate functions to extract the first chat completion message etc.This version: - uses existing language constructs - can be immediately understood even by the most junior devs - is likely to be 1000 times faster - does not rely on an external dependency that currently has 143 issues and every two weeks releases a new version adding dozens of new methods to things Note: one thing I do wish Javascript adopted is pipes: https://github.com/tc39/proposal-pipeline-operator |
* all but the first results are not arrays, so the `.map` function doesn't apply
* doesn't handle async operations
* catches ALL exceptions here, whereas my code only handles statically typed and well-defined errors
* doesn't include the GPT-generated message and messages from the first steps in the error
* doesn't include retry functionality
I appreciate this argument and time you've taken to read my code and write this counter-argument. Please don't mistake my direct code for animosity, I clearly see that you're a smart person even though I think you're wrong about this.
Also, the fp-ts doesn't add any runtime performance overhead here. It's a couple of extra function calls for a call that has an async operation that likely takes 30 seconds (GPT-4 is slow). Obviously, if I was writing code that runs thousands of times per second, I would not use FP.