Skip to content

Commit

Permalink
Merge pull request #35 from route06inc/handling-error-on-web-search
Browse files Browse the repository at this point in the history
Handling error on web search
  • Loading branch information
toyamarinyon authored Oct 22, 2024
2 parents de4dc0f + 2f214f4 commit 7e8f6c2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const CircleCheckIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<title>Circle Check Icon</title>
<g clip-path="url(#clip0_6417_28902)">
<path d="M9.90909 0.5C4.43636 0.5 0 4.93636 0 10.4091C0 15.8818 4.43636 20.3182 9.90909 20.3182C15.3818 20.3182 19.8182 15.8818 19.8182 10.4091C19.8182 4.93636 15.3818 0.5 9.90909 0.5ZM14.4727 8.18182L9.05455 13.6C8.92727 13.7273 8.75455 13.8 8.57273 13.8C8.39091 13.8 8.21818 13.7273 8.09091 13.6L5.35455 10.8636C5.09091 10.6 5.09091 10.1636 5.35455 9.9C5.61818 9.63636 6.05455 9.63636 6.31818 9.9L8.57273 12.1545L13.5091 7.21818C13.7727 6.95455 14.2091 6.95455 14.4727 7.21818C14.7364 7.48182 14.7364 7.91818 14.4727 8.18182Z" />
</g>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { FC, SVGProps } from "react";

export const CircleXIcon: FC<SVGProps<SVGSVGElement>> = (props) => (
<svg
width="20"
height="21"
viewBox="0 0 20 21"
xmlns="http://www.w3.org/2000/svg"
{...props}
>
<title>Circle X Icon</title>
<g clipPath="url(#clip0_6417_28957)">
<path d="M9.78182 0.5C4.38182 0.5 0 4.88182 0 10.2818C0 15.6818 4.38182 20.0636 9.78182 20.0636C15.1818 20.0636 19.5636 15.6818 19.5636 10.2818C19.5636 4.88182 15.1818 0.5 9.78182 0.5ZM14.0545 13.2636C14.4091 13.6182 14.4091 14.1909 14.0545 14.5455C13.8727 14.7273 13.6455 14.8091 13.4091 14.8091C13.1727 14.8091 12.9455 14.7182 12.7636 14.5455L9.77273 11.5545L6.78182 14.5455C6.6 14.7273 6.37273 14.8091 6.13636 14.8091C5.9 14.8091 5.67273 14.7182 5.49091 14.5455C5.13636 14.1909 5.13636 13.6182 5.49091 13.2636L8.48182 10.2727L5.49091 7.28182C5.13636 6.92727 5.13636 6.35455 5.49091 6C5.84545 5.64545 6.41818 5.64545 6.77273 6L9.76364 8.99091L12.7545 6C13.1091 5.64545 13.6818 5.64545 14.0364 6C14.3909 6.35455 14.3909 6.92727 14.0364 7.28182L11.0455 10.2727L14.0364 13.2636H14.0545Z" />
</g>
<defs>
<clipPath id="clip0_6417_28957">
<rect width="20" height="20" transform="translate(0 0.5)" />
</clipPath>
</defs>
</svg>
);
48 changes: 34 additions & 14 deletions app/(playground)/p/[agentId]/beta-proto/web-search/server-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { GiselleNode } from "../giselle-node/types";
import { webSearchSchema } from "./schema";
import { search } from "./tavily";
import {
type FailedWebSearchItemReference,
type WebSearch,
type WebSearchItemReference,
webSearchItemStatus,
Expand Down Expand Up @@ -119,26 +120,45 @@ export async function generateWebSearchStream(
await Promise.all(
chunkedArray.map(async (webSearchItems) => {
for (const webSearchItem of webSearchItems) {
const scrapeResponse = await app.scrapeUrl(webSearchItem.url, {
formats: ["markdown"],
});
if (scrapeResponse.success) {
const blob = await put(
`webSearch/${webSearchItem.id}.md`,
scrapeResponse.markdown ?? "",
{
access: "public",
contentType: "text/markdown",
},
);
try {
const scrapeResponse = await app.scrapeUrl(webSearchItem.url, {
formats: ["markdown"],
});
if (scrapeResponse.success) {
const blob = await put(
`webSearch/${webSearchItem.id}.md`,
scrapeResponse.markdown ?? "",
{
access: "public",
contentType: "text/markdown",
},
);
mutableItems = mutableItems.map((item) => {
if (item.id !== webSearchItem.id) {
return item;
}
return {
...webSearchItem,
contentBlobUrl: blob.url,
status: webSearchItemStatus.completed,
};
});
stream.update({
...result,
webSearch: {
...webSearch,
items: mutableItems,
},
});
}
} catch {
mutableItems = mutableItems.map((item) => {
if (item.id !== webSearchItem.id) {
return item;
}
return {
...webSearchItem,
contentBlobUrl: blob.url,
status: webSearchItemStatus.completed,
status: webSearchItemStatus.failed,
};
});
stream.update({
Expand Down
16 changes: 13 additions & 3 deletions app/(playground)/p/[agentId]/beta-proto/web-search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const webSearchItemStatus = {
pending: "pending",
processing: "processing",
completed: "completed",
failed: "failed",
} as const;

type WebSearchItemStatus =
Expand All @@ -44,23 +45,32 @@ export interface WebSearchItem {
interface PendingWebSearchItemReference {
id: WebSearchContentId;
object: "webSearch.item.reference";
status: Extract<WebSearchStatus, "pending">;
status: Extract<WebSearchItemStatus, "pending">;
title: string;
url: string;
relevance: number;
}
interface CompletedWebSearchItemReference {
id: WebSearchContentId;
object: "webSearch.item.reference";
status: Extract<WebSearchStatus, "completed">;
status: Extract<WebSearchItemStatus, "completed">;
title: string;
contentBlobUrl: string;
url: string;
relevance: number;
}
export interface FailedWebSearchItemReference {
id: WebSearchContentId;
object: "webSearch.item.reference";
status: Extract<WebSearchItemStatus, "failed">;
title: string;
url: string;
relevance: number;
}
export type WebSearchItemReference =
| PendingWebSearchItemReference
| CompletedWebSearchItemReference;
| CompletedWebSearchItemReference
| FailedWebSearchItemReference;
export interface GeneratedObject {
plan: string;
webSearch: WebSearch;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CopyIcon } from "lucide-react";
import { Dialog, DialogContent, DialogTrigger } from "../components/dialog";
import { CircleCheckIcon } from "../components/icons/circle-check";
import { CircleXIcon } from "../components/icons/circle-x";
import { DocumentIcon } from "../components/icons/document";
import { SpinnerIcon } from "../components/icons/spinner";
import { Block } from "../giselle-node/components/panel/block";
Expand Down Expand Up @@ -62,6 +63,8 @@ export function WebSearchBlock(props: WebSearchBlockProps) {
<td>
{item.status === webSearchItemStatus.completed ? (
<CircleCheckIcon className="w-[20px] h-[20px] fill-green" />
) : item.status === webSearchItemStatus.failed ? (
<CircleXIcon className="w-[20px] h-[20px] fill-[hsla(11,100%,50%,1)]" />
) : (
""
)}
Expand Down

0 comments on commit 7e8f6c2

Please sign in to comment.