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

Braintrust traced returns promise instead of raw object, requires await #2068

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
queryTurbopuffer,
toDocuments,
} from "@fern-docs/search-server/turbopuffer";
import { initLogger, traced, wrapAISDKModel } from "braintrust";
import { COOKIE_FERN_TOKEN, withoutStaging } from "@fern-docs/utils";
import { embed, EmbeddingModel, streamText, tool } from "ai";
import { cookies } from "next/headers";
Expand Down Expand Up @@ -78,18 +79,33 @@ export async function POST(req: NextRequest) {
date: new Date().toDateString(),
documents,
});
const result = streamText({
model: languageModel,
system,
messages,
maxSteps: 10,
maxRetries: 3,
tools: {
search: tool({
description:
"Search the knowledge base for the user's query. Semantic search is enabled.",
parameters: z.object({
query: z.string(),
const result = await traced(() =>
streamText({
model: languageModel,
system,
messages,
maxSteps: 10,
maxRetries: 3,
tools: {
search: tool({
description:
"Search the knowledge base for the user's query. Semantic search is enabled.",
parameters: z.object({
query: z.string(),
}),
async execute({ query }) {
const response = await runQueryTurbopuffer(query, {
embeddingModel,
namespace,
authed: user != null,
roles: user?.roles ?? [],
});
return response.map((hit) => {
const { domain, pathname, hash } = hit.attributes;
const url = `https://${domain}${pathname}${hash ?? ""}`;
return { url, ...hit.attributes };
});
},
}),
async execute({ query }) {
const response = await runQueryTurbopuffer(query, {
Expand Down
Loading