Skip to content
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

feat(ai): introduce vercel ai sdk support #316

Merged
merged 83 commits into from
Feb 19, 2025
Merged

Conversation

gladyshcodes
Copy link
Contributor

@gladyshcodes gladyshcodes commented Feb 4, 2025

Issue #291

What

Integrate Vercel AI SDK

Why

Simplify the introduction of new providers and models in the future, specifically, Amazon Bedrock (#310) and OpenAI when available

Copy link

vercel bot commented Feb 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
shortest ⬜️ Ignored (Inspect) Visit Preview Feb 19, 2025 7:38pm

@CLAassistant
Copy link

CLAassistant commented Feb 4, 2025

CLA assistant check
All committers have signed the CLA.

@gladyshcodes
Copy link
Contributor Author

In progress:

  1. Nits
  2. Testing
  3. Feedback iterations

@rmarescu rmarescu added this to the v0.4.4 milestone Feb 5, 2025
Copy link
Member

@rmarescu rmarescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some initial comments.

@gladyshcodes gladyshcodes marked this pull request as ready for review February 6, 2025 22:17
@gladyshcodes
Copy link
Contributor Author

@rmarescu Feedback addressed

@gladyshcodes gladyshcodes requested a review from rmarescu February 6, 2025 22:23
Copy link
Member

@rmarescu rmarescu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitting a partial review. High-level thoughts:

  • No need to map Vercel's models with a local list, it complicates the implementation without too much gain
  • Use AI instead of LLM (don't need 2 names that represent almost the same thing within the codebase)
  • Config schema seems complicated. Can be simplified?

}

export interface LLMPPublicConfig {
provider: LLMSupportedProvidersType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even this one can be optional. Ideally, there should be zero config to run Shortest.

No ai prop provided should default to the provider we think is the best, e.g. anthropic, which tries to read the apiKey from ENV (as Vercel AI SDK supports it by default).

Copy link
Contributor Author

@gladyshcodes gladyshcodes Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't see a strong case for simplifying the configuration. Keeping all settings in a single file actually reduces the cognitive load, as it makes it clear where each value comes from and how the final configuration is assembled

Ideally, there should be zero config to run Shortest

Achieving that is unlikely—especially as users increasingly demand more flexibility and control over Shortest (see, for example, issue #313)

What is possible, though, is keeping all non-sensitive data in config and sensitive data (e.g keys) in the env, not to duplicate them in the config

Co-authored-by: Razvan Marescu <razvan@marescu.net>
Copy link

vercel bot commented Feb 7, 2025

You must have Developer access to commit code to Antiwork on Vercel. If you contact an administrator and receive Developer access, commit again to see your changes.

Learn more: https://vercel.com/docs/accounts/team-members-and-roles/access-roles#team-level-roles

gladyshcodes and others added 7 commits February 7, 2025 19:59
Co-authored-by: Razvan Marescu <razvan@marescu.net>
Co-authored-by: Razvan Marescu <razvan@marescu.net>
Co-authored-by: Razvan Marescu <razvan@marescu.net>
Co-authored-by: Razvan Marescu <razvan@marescu.net>
Co-authored-by: Razvan Marescu <razvan@marescu.net>
Co-authored-by: Razvan Marescu <razvan@marescu.net>
@rmarescu
Copy link
Member

rmarescu commented Feb 15, 2025

  • Fix error when running examples/youtube.test.rb
Details
trace  | 11:23:13 | examples/youtube.test.ts | Visit a YouTube channel and verify latest content | 🤖 | 1 | Generating text | currentPrompt=
  Test: "Visit a YouTube channel and verify latest content"
  Context: {"channelName":"TED","sortBy":"newest"}
  Callback function:  [NO_CALLBACK]

  Expect:
  1. "Visit a YouTube channel and verify latest content" expected to be successful

  Current Page State:
  URL: http://localhost:3000/
  Title: Shortest
 messageCount=1 tools={
  "0": "computer",
  "1": "bash",
  "2": "github_login",
  "3": "check_email",
  "4": "sleep",
  "5": "run_callback",
  "6": "navigate"
}

error  | 11:23:16 | examples/youtube.test.ts | Visit a YouTube channel and verify latest content | 🤖 | 1 | Error making request | message=
  Invalid arguments for tool navigate: Type validation failed: Value: {"url":"https://www.youtube.com/@TED"}.
  Error message: [
    {
      "code": "invalid_literal",
      "expected": "navigate",
      "path": [
        "action"
      ],
      "message": "Invalid literal value, expected "navigate""
    }
  ]
 name=AI_InvalidToolArgumentsError stack=
  Error message: [
    {
      "code": "invalid_literal",

error  | 11:23:16 | examples/youtube.test.ts | Visit a YouTube channel and verify latest content | 🤖 | 1 | Invalid arguments for a tool were provided
error  | 11:23:16 | examples/youtube.test.ts | Visit a YouTube channel and verify latest content | 🤖 | Action failed | message=
  Invalid arguments for tool navigate: Type validation failed: Value: {"url":"https://www.youtube.com/@TED"}.
  Error message: [
    {
      "code": "invalid_literal",
      "expected": "navigate",
      "path": [
        "action"
      ],
      "message": "Invalid literal value, expected "navigate""
    }
  ]
 name=AI_InvalidToolArgumentsError stack=
  Error message: [
    {
      "code": "invalid_literal",

trace  | 11:23:16 | examples/youtube.test.ts | Visit a YouTube channel and verify latest content | 🤖 | Retry attempt | retries=1 maxRetries=3

Comment on lines +56 to +63
} else {
if (event.level === "warn") {
console.warn(
pc.bgYellowBright(pc.black(" WARN ")),
pc.yellow(event.message),
);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forces console output for warnings (used for deprecations at this moment)

CleanShot 2025-02-19 at 08 49 00@2x

};
this.conversationHistory.push(initialMessageOptions);
this.log.trace("💬", "New conversation message", initialMessageOptions);
this.log.trace("💬", "Conversation history initialized", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each test triggers runAction > runConversation. This tracing should make is easier to follow the AI conversation and the tools executed.

private get tools(): Record<string, CoreTool> {
if (this._tools) return this._tools;

this._tools = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tools should have the same interface internally, and be managed via a ToolsRegistry or such (can be addressed in a future PR).

@@ -607,6 +611,8 @@ export class BrowserTool extends BaseBrowserTool {
};
}
throw new ToolError(`Action failed: ${error}`);
} finally {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored all resetGroup calls to be called within a finally block. This approach ensures the log groups are properly defined with minimal logic.

try {
  this.log.setGroup("New group");
} finally {
  this.log.resetGroup();
}

@@ -122,10 +122,8 @@ function getParamValue(args: string[], paramName: string): string | undefined {
async function main() {
const args = process.argv.slice(2);
const logLevel = getParamValue(args, "--log-level");
const logFormat = getParamValue(args, "--log-format");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed to removed in a previous PR where --log-format was removed as a CLI arg.


private filesCount: number = 0;
private testsCount: number = 0;
private passedTestsCount: number = 0;
private failedTestsCount: number = 0;
private totalInputTokens: number = 0;
private totalOutputTokens: number = 0;
private totalPromptTokens: number = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to match the terminology from AI providers.

);
}

private parseMetadata():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly moved from log/output.ts, with some adjustments.

if (event.level === "error") {
message = pc.red(message);
}

let outputParts = [];
outputParts.push(colorFn(`${level}`.padEnd(LogOutput.MAX_LEVEL_LENGTH)));
outputParts.push(timestamp);
outputParts.push(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.Simplified fro full timestamp, to only HH:MM:SS

// import { LanguageModelUsage } from "ai";
import { z } from "zod";

// TODO: Validate against LanguageModelUsage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done in a follow-up PR.

@@ -20,6 +22,7 @@ IMPORTANT GLOBAL RULES:
- After invoking a tool, wait until the tool finishes its execution and you receive a success/failure result.
- You will also receive metadata about the tool's execution to help you interpret its outcome.
- Only after the tool finishes and you know the result should you request any screenshots or proceed to the next action.
- Always include the "action" field matching the tool name in your tool calls (e.g. for "navigate" tool, include 'action: "navigate"').
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is critial to ensure that Vercel AI SDK doesn't return AI_InvalidToolArgumentsError.

@rmarescu rmarescu merged commit 346ac29 into main Feb 19, 2025
6 checks passed
@rmarescu rmarescu deleted the gladish/vercel-ai-sdk branch February 19, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants