Skip to content

Commit

Permalink
feat: fromLanguageModelTools helper function (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 14, 2024
1 parent 7ec279f commit 40c34e6
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/with-react-hook-form/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function RootLayout({
return (
<MyRuntimeProvider>
<html lang="en">
<body className={cn(montserrat.className, "h-[calc(100dvh)]")}>
<body className={cn(montserrat.className, "h-dvh")}>
{children}
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion examples/with-vercel-ai-rsc/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useVercelRSCRuntime } from "@assistant-ui/react-ai-sdk";

export default function Home() {
return (
<main className="h-[calc(100dvh)]">
<main className="h-dvh">
<MyRuntimeProvider>
<Thread />
</MyRuntimeProvider>
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/runtimes/edge/EdgeChatAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ export class EdgeChatAdapter implements ChatModelAdapter {
body: JSON.stringify({
system: config.system,
messages: toCoreMessages(messages),
tools: toLanguageModelTools(
config.tools,
) as EdgeRuntimeRequestOptions["tools"],
tools: config.tools ? toLanguageModelTools(config.tools) : [],
...config.callSettings,
...config.config,
} satisfies EdgeRuntimeRequestOptions),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LanguageModelV1FunctionTool } from "@ai-sdk/provider";
import { Tool } from "../../../types/ModelConfigTypes";

export const fromLanguageModelTools = (
tools: LanguageModelV1FunctionTool[],
): Record<string, Tool<any, any>> => {
return Object.fromEntries(
tools.map((tool) => [
tool.name,
{
description: tool.description,
parameters: tool.parameters,
},
]),
);
};
4 changes: 4 additions & 0 deletions packages/react/src/runtimes/edge/converters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { toLanguageModelMessages } from "./toLanguageModelMessages";
export { fromLanguageModelMessages } from "./fromLanguageModelMessages";
export { fromCoreMessages } from "./fromCoreMessage";
export { fromLanguageModelTools } from "./fromLanguageModelTools";
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import zodToJsonSchema from "zod-to-json-schema";
import { Tool } from "../../../types/ModelConfigTypes";

export const toLanguageModelTools = (
tools: Record<string, Tool<any, any>> | undefined,
tools: Record<string, Tool<any, any>>,
): LanguageModelV1FunctionTool[] => {
if (!tools) return [];
return Object.entries(tools).map(([name, tool]) => ({
type: "function",
name,
Expand Down
7 changes: 3 additions & 4 deletions packages/react/src/runtimes/edge/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from "./converters";

export { useEdgeRuntime, type EdgeRuntimeOptions } from "./useEdgeRuntime";
export { EdgeChatAdapter } from "./EdgeChatAdapter";

export { toLanguageModelMessages } from "./converters/toLanguageModelMessages";
export { fromLanguageModelMessages } from "./converters/fromLanguageModelMessages";
export { fromCoreMessages } from "./converters/fromCoreMessage";
export type { EdgeRuntimeRequestOptions } from "./EdgeRuntimeRequestOptions";

0 comments on commit 40c34e6

Please sign in to comment.