Skip to content

Commit

Permalink
fix: default empty client instantiation templates (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Jul 10, 2024
1 parent 6102340 commit 060b219
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/template-resolver/src/SnippetTemplateResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export class SnippetTemplateResolver {
if (authPayload != null) {
return this.accessByPath(authPayload, locationPath);
}
return undefined;
const maybePayloadName = locationPath?.replace(/\[.*?\]/g, "")?.split(".")[0];

return `YOUR_${(maybePayloadName ?? "variable").toUpperCase()}`;
}

private getPayloadValue(location: PayloadInput, payloadOverride?: unknown): unknown | undefined {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ await cohere.chatStream({
`;

exports[`Snippet Template Resolver > Test empty payload 1`] = `
"const cohere = new CohereClient({
token: "YOUR_TOKEN",
clientName: "YOUR_CLIENT_NAME",
});
"const cohere = new CohereClient({ token: "YOUR_TOKEN" });
await cohere.chatStream();
"
`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SnippetTemplateResolver } from "../../SnippetTemplateResolver";
import { CHAT_COMPLETION_SNIPPET, CHAT_COMPLETION_SNIPPET_WITH_LEGACY_CLIENT_INSTANTIATION } from "../cohere";
import { CHAT_COMPLETION_SNIPPET } from "../cohere";

describe("Snippet Template Resolver", () => {
it("Test Chat Completion snippet", async () => {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("Snippet Template Resolver", () => {
it("Test empty payload", async () => {
const resolver = new SnippetTemplateResolver({
payload: {},
endpointSnippetTemplate: CHAT_COMPLETION_SNIPPET_WITH_LEGACY_CLIENT_INSTANTIATION,
endpointSnippetTemplate: CHAT_COMPLETION_SNIPPET,
});
const customSnippet = await resolver.resolveWithFormatting();

Expand Down

0 comments on commit 060b219

Please sign in to comment.