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

fix passing of the assistant options to the invoke #57

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
47 changes: 40 additions & 7 deletions src/LangtailAssistants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class MockLangtailPrompts implements ILangtailPrompts {
}

describe("LangtailAssistants", () => {
describe("public API", () => {
const createLt = () => {
const promptsMock = new MockLangtailPrompts()
return {
lt: new LangtailAssistants(promptsMock),
promptsMock
}
const createLt = () => {
const promptsMock = new MockLangtailPrompts()
return {
lt: new LangtailAssistants(promptsMock),
promptsMock
}
}

describe("public API", () => {
it("should translate assistant to prompt option in langtailPrompts.invoke call", async () => {
const { lt, promptsMock } = createLt();
const assistant = "test-assistant";
Expand All @@ -43,6 +43,7 @@ describe("LangtailAssistants", () => {

expect(promptsMock.invoke).toHaveBeenCalledWith(
expect.objectContaining({
assistant: true,
prompt: assistant,
})
);
Expand Down Expand Up @@ -90,6 +91,7 @@ describe("LangtailAssistants", () => {
});

expect(promptsMock.invoke).toHaveBeenCalledWith({
assistant: true,
prompt: assistant,
messages,
});
Expand All @@ -106,4 +108,35 @@ describe("LangtailAssistants", () => {
expect(result).toBe(mockResponse);
});
})

it("should pass assistant: true by default to langtailPrompts.invoke call", async () => {
const { lt, promptsMock } = createLt();
const assistant = "test-assistant";

await lt.invoke({ assistant });

expect(promptsMock.invoke).toHaveBeenCalledWith(
expect.objectContaining({
assistant: true,
prompt: "test-assistant",
})
);
});

it("should pass threadId to langtailPrompts.invoke call when provided", async () => {
const { lt, promptsMock } = createLt();
const assistant = "test-assistant";
const threadId = "test-thread-id";

await lt.invoke({ assistant, threadId });

expect(promptsMock.invoke).toHaveBeenCalledWith(
expect.objectContaining({
assistant: true,
prompt: assistant,
threadId: threadId,
})
);
});

})
5 changes: 3 additions & 2 deletions src/LangtailAssistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ export class LangtailAssistants {
this.langtailPrompts = langtailPrompts
}

invoke<P extends PromptSlug, E extends Environment<P> = undefined, V extends Version<P, E> = undefined, S extends boolean = false>(options: Omit<IRequestParamsStream<P, E, V, S>, "prompt"> & {
invoke<P extends PromptSlug, E extends Environment<P> = undefined, V extends Version<P, E> = undefined, S extends boolean = false>(options: Omit<IRequestParamsStream<P, E, V, S>, "prompt" | "assistant"> & {
assistant: P
}): Promise<S extends true ? StreamResponseType : OpenAIResponseWithHttp> {
const { assistant, ...rest } = options
return this.langtailPrompts.invoke<P, E, V, S>({
...rest,
prompt: assistant
prompt: assistant,
assistant: true,
})
}
}
2 changes: 2 additions & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {

export interface ILangtailExtraProps {
doNotRecord?: boolean
threadId?: string
assistant?: boolean
metadata?: Record<string, any>
}

Expand Down
Loading