-
-
Notifications
You must be signed in to change notification settings - Fork 424
Refactor the Effect AI SDKs #5469
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
Conversation
🦋 Changeset detectedLatest commit: 8785bac The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dfa9d9e to
29a6755
Compare
| over time based upon necessity / use case. | ||
|
|
||
| ```ts | ||
| type AiError = |
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.
It would be great to have the OverloadedError be extracted out into a separate case
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 different providers implement these errors differently, I'm keeping the AiError union intentionally lean for now. You should be able to get all the information about why a request / response failed as well as the associated headers and whatnot via the HttpRequestError / HttpResponseError cases.
That being said, I'm open to re-evaluating what error cases we expose after more folks are able to test / provide feedback.
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.
That's true, but having this kind of error unification would be valuable addition to the library. Providers have different errors, but most users would want to implement retry on overloads, for example.
Type
Description
This pull request contains a complete refactor of the base Effect AI SDK package
as well as the associated provider integration packages to improve flexibility
and enhance ergonomics. Major changes are outlined below.
Modules
All modules in the base Effect AI SDK have had the leading
Aiprefix droppedfrom their name (except for the
AiErrormodule).For example, the
AiLanguageModelmodule is now theLanguageModelmodule.In addition, the
AiInputmodule has been renamed to thePromptmodule.Prompts
The
Promptmodule has been completely redesigned with flexibility in mind.The
Promptmodule now supports building a prompt using either the constructorsexposed from the
Promptmodule, or using raw prompt content parts / messages,which should be familiar to those coming from other AI SDKs.
In addition, the
systemoption has been removed from allLanguageModelmethodsand must now be provided as part of the prompt.
Prompt Constructors
Raw Prompt Input
NOTE: Providing a plain string as a prompt is still supported, and will be converted
internally into a user message with a single text content part.
Provider-Specific Options
To support specification of provider-specific options when interacting with large
language model providers, support has been added for adding provider-specific
options to the parts of a
Prompt.Responses
The
Responsemodule has also been completely redesigned to support a widervariety of response parts, particularly when streaming.
Streaming Responses
When streaming text via the
LanguageModel.streamTextmethod, you will nowreceive a stream of content parts instead of a stream of responses, which should
make it much simpler to filter down the stream to the parts you are interested in.
In addition, additional content parts will be present in the stream to allow you to track,
for example, when a text content part starts / ends.
Tool Calls / Tool Call Results
The decoded parts of a
Response(as returned by the methods ofLanguageModel)are now fully type-safe on tool calls / tool call results. Filtering the content parts of a
response to tool calls will narrow the type of the tool call
paramsbased on the toolname. Similarly, filtering the response to tool call results will narrow the type of thetool call
resultbased on the toolname.Provider Metadata
As with provider-specific options, provider-specific metadata is now returned as
part of the response from the large language model provider.
Tool Calls
The
Toolmodule has been enhanced to support provider-defined tools (e.g.web search, computer use, etc.). Large language model providers which support
calling their own tools now have a separate module present in their provider
integration packages which contain definitions for their tools.
These provider-defined tools can be included alongside user-defined tools in
existing
Toolkits. Provider-defined tools that require a user-space handlerwill be raise a type error in the associated
Toolkitlayer if no such handleris defined.
AiError
The
AiErrortype has been refactored into a union of different error typeswhich can be raised by the Effect AI SDK. The goal of defining separate error
types is to allow providing the end-user with more granular information about
the error that occurred.
For now, the following errors have been defined. More error types may be added
over time based upon necessity / use case.
Related
test/mytool) results in an opaque error #5249