Skip to content

Commit

Permalink
feat(ai): type error outputs + update OpenAI model list (#850)
Browse files Browse the repository at this point in the history
## Summary

The output typings for OpenAI and Anthropic are missing the error
scenario (ex, wrong API key), which leads to silent errors in AgentKit
(#850)



## Checklist

- [x] Performed manual QA

---------

Co-authored-by: Jack Williams <[email protected]>
  • Loading branch information
charlypoly and jpwilliams authored Feb 20, 2025
1 parent dc9fe3e commit dfe5e2a
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-llamas-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/ai": patch
---

feat(ai): type error outputs
5 changes: 5 additions & 0 deletions .changeset/short-poems-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/ai": patch
---

feat(ai): type error outputs
51 changes: 51 additions & 0 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,54 @@ jobs:

The last release was built and published from ${{ github.event.pull_request.head.sha }}.
edit-mode: replace

prerelease_ai:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
defaults:
run:
working-directory: packages/ai
if: contains(github.event.pull_request.labels.*.name, 'prerelease/ai')
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false

- uses: ./.github/actions/setup-and-build
with:
install-dependencies: false
build: false

- run: pnpm install

- run: pnpm build

- name: Prerelease PR
run: node ../../scripts/release/prerelease.js
env:
TAG: pr-${{ github.event.pull_request.number }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_ENV: test # disable npm access checks; they don't work in CI

- name: Update PR with latest prerelease
uses: edumserrano/find-create-or-update-comment@v1
with:
token: ${{ secrets.CHANGESET_GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-includes: "<!-- pr-prerelease-comment-ai -->"
comment-author: "inngest-release-bot"
body:
| # can be a single value or you can compose text with multi-line values
<!-- pr-prerelease-comment-ai -->
A user has added the <kbd>[prerelease/ai](https://github.com/inngest/inngest-js/labels/prerelease%2Fai)</kbd> label, so this PR will be published to npm with the tag `pr-${{ github.event.pull_request.number }}`. It will be updated with the latest changes as you push commits to this PR.

You can install this prerelease version with:

```sh
npm install @inngest/ai@pr-${{ github.event.pull_request.number }}
```

The last release was built and published from ${{ github.event.pull_request.head.sha }}.
edit-mode: replace
8 changes: 7 additions & 1 deletion packages/ai/src/adapters/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,14 @@ export namespace AnthropicAiAdapter {
* Object type.
*
* For Messages, this is always `"message"`.
* When an error occurs, this will be `"error"`.
*/
type: "message";
type: "message" | "error";

error?: {
type: string;
message: string;
};

/**
* Billing and rate-limit usage.
Expand Down
10 changes: 10 additions & 0 deletions packages/ai/src/adapters/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ export interface OpenAiAiAdapter extends AiAdapter {
*/
id: string;

/**
* If an error occurs, this will be an object containing the error details.
*/
error?: {
message: string;
type: string;
param: string | null;
code: string | null;
};

/**
* A list of chat completion choices. Can be more than one if `n` is
* greater than 1.
Expand Down
3 changes: 3 additions & 0 deletions packages/ai/src/models/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ export namespace OpenAi {
| "chatgpt-4o-latest"
| "gpt-4o-mini"
| "gpt-4"
| "o1"
| "o1-preview"
| "o1-mini"
| "o3-mini"
| "gpt-4-turbo"
| "gpt-3.5-turbo";

/**
Expand Down

0 comments on commit dfe5e2a

Please sign in to comment.