Skip to content

Commit

Permalink
make resolveWith required
Browse files Browse the repository at this point in the history
  • Loading branch information
hassiebp committed Dec 11, 2024
1 parent 51e2c13 commit 141fcf2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions integration-test/langfuse-integration-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ describe("Langfuse (fetch)", () => {

const mediaReplacedTrace = await langfuse.resolveMediaReferences({
obj: res.data,
resolveWith: "base64DataUri",
});

// Check that the replaced base64 data is the same as the original
Expand Down
2 changes: 1 addition & 1 deletion langfuse-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ export abstract class LangfuseCore extends LangfuseCoreStateless {
* @param params - Configuration object
* @param params.obj - The object to process. Can be a primitive value, array, or nested object
* @param params.langfuseClient - Langfuse client instance used to fetch media content
* @param params.resolveWith - Optional. Default is "base64DataUri". The type of data to replace the media reference string with. Currently only "base64DataUri" is supported.
* @param params.resolveWith - The representation of the media content to replace the media reference string with. Currently only "base64DataUri" is supported.
* @param params.maxDepth - Optional. Default is 10. The maximum depth to traverse the object.
*
* @returns A deep copy of the input object with all media references replaced with base64 data URIs where possible
Expand Down
4 changes: 2 additions & 2 deletions langfuse-core/src/media/LangfuseMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface ParsedMediaReference {
export type LangfuseMediaResolveMediaReferencesParams<T> = {
obj: T;
langfuseClient: LangfuseCore;
resolveWith?: "base64DataUri";
resolveWith: "base64DataUri";
maxDepth?: number;
};

Expand Down Expand Up @@ -216,7 +216,7 @@ class LangfuseMedia {
* @param params - Configuration object
* @param params.obj - The object to process. Can be a primitive value, array, or nested object
* @param params.langfuseClient - Langfuse client instance used to fetch media content
* @param params.resolveWith - Optional. Default is "base64DataUri". The type of data to replace the media reference string with. Currently only "base64DataUri" is supported.
* @param params.resolveWith - The representation of the media content to replace the media reference string with. Currently only "base64DataUri" is supported.
* @param params.maxDepth - Optional. Default is 10. The maximum depth to traverse the object.
*
* @returns A deep copy of the input object with all media references replaced with base64 data URIs where possible
Expand Down
5 changes: 5 additions & 0 deletions langfuse-core/test/langfuse.flush.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("Langfuse Core", () => {
status: 400,
text: async () => "err",
json: async () => ({ status: "err" }),
arrayBuffer: async () => new Uint8Array(),
});
});

Expand All @@ -59,6 +60,7 @@ describe("Langfuse Core", () => {
status: 207,
text: async () => "err",
json: async () => ({ successes: [], errors: [{ id: trace.id, message: "Something failed" }] }),
arrayBuffer: async () => new Uint8Array(),
});
});

Expand Down Expand Up @@ -90,13 +92,15 @@ describe("Langfuse Core", () => {
status: 207,
text: async () => "err",
json: async () => ({ successes: [], errors: [{ id: "someId", message: "Something failed" }] }),
arrayBuffer: async () => new Uint8Array(),
});
} else {
index++;
return Promise.resolve({
status: 200,
text: async () => "ok",
json: async () => ({ successes: [], errors: [] }),
arrayBuffer: async () => new Uint8Array(),
});
}
});
Expand Down Expand Up @@ -168,6 +172,7 @@ describe("Langfuse Core", () => {
status: 200,
text: async () => "ok",
json: async () => ({ status: "ok" }),
arrayBuffer: async () => new Uint8Array(),
});
}, 500); // add delay to simulate network request
});
Expand Down
1 change: 1 addition & 0 deletions langfuse-core/test/langfuse.prompts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ describe("Langfuse Core", () => {
status: 200,
json: async () => ({ status: "200" }),
text: async () => "ok",
arrayBuffer: async () => new Uint8Array(),
});
}, 1000);
});
Expand Down
1 change: 1 addition & 0 deletions langfuse-node/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export const fetch = async (url: string, options: LangfuseFetchOptions): Promise
status: res.status,
text: async () => res.data,
json: async () => res.data,
arrayBuffer: async () => res.data,
};
};

0 comments on commit 141fcf2

Please sign in to comment.