Skip to content

Commit

Permalink
Merge pull request #48 from mastra-ai/taofeeq/futr-817-update-bird-ch…
Browse files Browse the repository at this point in the history
…ecker-with-eval-variant-to-use-new-mastra

update bird checker with eval variant
  • Loading branch information
Joshuafolorunsho authored Nov 21, 2024
2 parents 12e48c3 + 96163cb commit c69f6e0
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 348 deletions.
57 changes: 0 additions & 57 deletions bird-checker-with-eval/mastra.config.ts

This file was deleted.

Empty file.
Empty file.
5 changes: 3 additions & 2 deletions bird-checker-with-eval/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"lint": "next lint",
"mastra:init": "pnpm dlx mastra init",
"mastra:dev": "pnpm dlx mastra dev",
"mastra:migrate": "pnpm dlx mastra migrate"
"mastra:migrate": "pnpm dlx mastra migrate",
"braintrust:eval": "npx braintrust eval src/lib/evals"
},
"dependencies": {
"@mastra/core": "^0.1.26",
"@mastra/core": "0.1.27-alpha.0",
"@prisma/client": "5.22.0",
"braintrust": "^0.0.168",
"class-variance-authority": "^0.7.0",
Expand Down
28 changes: 14 additions & 14 deletions bird-checker-with-eval/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions bird-checker-with-eval/src/app/api/mastra/[...mastra]/route.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,32 @@ import { toast } from "sonner";
import { Status } from "./bird-checker";
import { Skeleton } from "@/components/ui/skeleton";
import { Bird, Check, MapPin } from "lucide-react";
import { getObjectFromString } from "@/lib/utils";

function getObjectFromString(text: string) {
// First approach: using match()
const regex =
/(?<=bird:).*?(?=,|\n)|(?<=location:).*?(?=,|\n)|(?<=species:).*(?=\n|})/g;
const matches = text.match(regex);

if (!matches) {
return {
bird: "no",
location: text,
species: ""
};
}

const [bird, location, species] = matches;
console.log("Bird:", bird);
console.log("Location:", location);
console.log("Species:", species);

return {
bird: bird?.trim(),
location: location?.trim(),
species: species?.split("}")?.join("")?.trim()
};
}

export const BirdCheckerResponse = ({
imageUrl,
Expand All @@ -33,8 +58,6 @@ export const BirdCheckerResponse = ({
const getRandomImage = async () => {
if (!imageUrl) return;

console.log("imageUrl==", imageUrl);

setMetadataStatus("loading");
const res = await promptClaude({ imageUrl });

Expand All @@ -45,7 +68,7 @@ export const BirdCheckerResponse = ({
}
console.log("res===", res.data);
setMetadataStatus("success");
const object = getObjectFromString(res.data.content[0].text);
const object = getObjectFromString(res.data.text);

setMedata(object);
};
Expand Down
14 changes: 7 additions & 7 deletions bird-checker-with-eval/src/app/components/bird-checker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { getImage } from "@/lib/mastra/actions";
import { getImage, ImageQuery } from "@/lib/mastra/actions";
import { cn } from "@/lib/utils";
import { Bird, Camera, Feather, Plane } from "lucide-react";
import Image from "next/image";
Expand Down Expand Up @@ -43,7 +43,7 @@ export const BirdChecker = () => {
const getRandomImage = async () => {
setStatus("loading");
console.log("got here");
const res = await getImage({ query });
const res = await getImage({ query: query as ImageQuery });
if (!res.ok) {
setStatus("error");
toast.error("Failed to fetch image");
Expand Down Expand Up @@ -74,8 +74,8 @@ export const BirdChecker = () => {
<p className="md:hidden text-sm text-center font-base font-normal italic font-serif">
Inspired by{" "}
<a
href="https://xkcd.com/1425/"
rel="noopener"
href="https://xkcd.com/1425/"
target="_blank"
className="text-[#0057ff] font-medium">
Randall Munroe
Expand Down Expand Up @@ -159,9 +159,9 @@ export const BirdChecker = () => {
<span className="sm:hidden bottom-2 right-2 w-fit mx-auto py-1 bg-gray-100 duration-300 ease-out transition-all rounded-full px-2 border-[hsla(256,2%,99%,.08)] justify-center items-center font-medium border text-sm">
<div className="flex gap-2">
<a
rel="noopener"
href="https://github.com/mastra-ai/examples/tree/main/bird-checker"
target="_blank"
rel="noopener"
className="uppercase inline-flex items-center h-4 rounded-full text-black px-1.5 leading-tight tracking-widest text-[9px] bg-gray-50 font-semibold">
see the code
</a>
Expand All @@ -180,8 +180,8 @@ export const BirdChecker = () => {
<p className="absolute hidden md:block right-2 bottom-2 italic font-serif">
Inspired by{" "}
<a
href="https://xkcd.com/1425/"
rel="noopener"
href="https://xkcd.com/1425/"
target="_blank"
className="text-[#0057ff] font-medium">
Randall Munroe
Expand All @@ -192,17 +192,17 @@ export const BirdChecker = () => {
<span className="hidden md:block md:fixed bottom-2 right-2 w-fit mx-auto py-1 bg-gray-100 duration-300 ease-out transition-all rounded-full px-2 border-[hsla(256,2%,99%,.08)] justify-center items-center font-medium border text-sm">
<div className="flex gap-2">
<a
rel="noopener"
href="https://github.com/mastra-ai/examples/tree/main/bird-checker"
target="_blank"
rel="noopener"
className="uppercase inline-flex items-center h-4 rounded-full text-black px-1.5 leading-tight tracking-widest text-[9px] bg-gray-50 font-semibold">
see the code
</a>
<span className="text-xs text-black font-semibold">
Built with{" "}
<a
href="https://mastra.ai/"
rel="noopener"
href="https://mastra.ai/"
className="underline"
target="_blank">
Mastra.ai
Expand Down
4 changes: 2 additions & 2 deletions bird-checker-with-eval/src/lib/evals/data.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const IMAGES = {
notBird: {
bird: "no",
species: "not applicable",
species: "Panthera leo",
image:
"https://images.unsplash.com/photo-1731009918047-1e02c93a28f0?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w2NzI1Mzd8MHwxfHNlYXJjaHw0MXx8d2lsZGxpZmV8ZW58MHx8Mnx8MTczMTMyODAyOHww&ixlib=rb-4.0.3&q=80&w=1080"
"https://images.unsplash.com/photo-1470848051974-964b789cb6fa?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w2NzI1Mzd8MHwxfHNlYXJjaHwzNXx8d2lsZGxpZmV8ZW58MHx8fHwxNzMyMTIwMTMyfDA&ixlib=rb-4.0.3&q=80&w=1080"
},
isBird: {
bird: "yes",
Expand Down
6 changes: 3 additions & 3 deletions bird-checker-with-eval/src/lib/evals/index.eval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Eval } from "braintrust";
import { IMAGES } from "./data";
import { BirdObj } from "../utils";
import { getImageMetadataFromClaude } from "../mastra/system-apis";
import { promptClaude } from "../mastra/actions";

export function getObjectFromString(text: string): BirdObj {
// First approach: using match()
Expand Down Expand Up @@ -60,11 +60,11 @@ Eval("Is a bird", {
];
},
task: async (input) => {
const claudeResponse = await getImageMetadataFromClaude({ imageUrl: input });
const claudeResponse = await promptClaude({ imageUrl: input });
if (!claudeResponse.ok) {
return { bird: "", location: "", species: "" };
}
const object = getObjectFromString(claudeResponse.data.content[0].text);
const object = getObjectFromString(claudeResponse.data.text);

return object;
},
Expand Down
Loading

0 comments on commit c69f6e0

Please sign in to comment.