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

feat: make systemPrompt sync and optional #29

Merged
merged 5 commits into from
Dec 11, 2024

Conversation

mdjastrzebski
Copy link
Member

@mdjastrzebski mdjastrzebski commented Dec 8, 2024

Summary

Two changes to systemPrompt:

  1. It is now optional, similarly you can return null value from the function form to indicate that you do not want to have a system prompt. This is required to support OpenAI's o1 model which throws error when receiving system prompt.
    • In order for this to work correctly with o1, if you indicate lack of system prompt, then entity dictionary will not be added to it.
  2. It is now synchronous. There seems to be no valid cases for async system prompts. In generate it should be either fixed string or something that you can synchronously derive from request context

Test plan

Added automated tests. Created another test model, this time on the Vercel Model/Adapter level, as system message transformation happens there.

@mdjastrzebski mdjastrzebski force-pushed the feat/do-not-require-system-prompt branch from 3cea2f1 to c0096a1 Compare December 8, 2024 10:13
@mdjastrzebski mdjastrzebski requested a review from Q1w1N December 8, 2024 10:15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it folder name intentional? Shouldn't be tests ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, good catch ;-)

const { languageModel, calls } = createMockVercelModel({ text: 'Hello, world!' });
const app = createApp({
chatModel: new VercelChatModelAdapter({ languageModel }),
systemPrompt: 'This is system prompt',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this test pass? Shouldn't systemPrompt be a function that returns string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have it both ways, function or just a string.

const messages = context.messages;

const systemPrompt = await context.systemPrompt();
let systemPrompt = context.systemPrompt();
const entitiesPrompt = formatResolvedEntities(context.resolvedEntities);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's put that logic inside "if(systemPrompt)" below. No need to check for entities if we add them only when systemPrompt is present.

@@ -33,7 +33,7 @@ export type ErrorHandler = (

export type ApplicationConfig = {
chatModel: ChatModel;
systemPrompt: (context: RequestContext) => Promise<string> | string;
systemPrompt?: ((context: RequestContext) => string | null) | string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, ok. So please fix the type in docs as it does not match.

@@ -30,7 +30,7 @@ export type RequestContext = {
tools: ApplicationTool[];
references: ReferenceStorage;
resolvedEntities: EntityInfo;
systemPrompt: () => Promise<string> | string;
systemPrompt: () => string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same case. It can also be a string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inside context, it's already standardised to a function

Copy link
Collaborator

@Q1w1N Q1w1N left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple changes needed

@mdjastrzebski mdjastrzebski force-pushed the feat/do-not-require-system-prompt branch from 22a4c3a to 76a28ea Compare December 10, 2024 12:26
@mdjastrzebski mdjastrzebski force-pushed the feat/do-not-require-system-prompt branch from 76a28ea to 8d58f19 Compare December 11, 2024 13:02
@mdjastrzebski mdjastrzebski merged commit 287c02b into main Dec 11, 2024
2 checks passed
@mdjastrzebski mdjastrzebski deleted the feat/do-not-require-system-prompt branch December 11, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants