@@ -63,7 +63,7 @@ public void Dispose() { }
6363 public async Task < ChatResponse > GetResponseAsync (
6464 IEnumerable < ChatMessage > messages , ChatOptions ? options = null , CancellationToken cancellationToken = default )
6565 {
66- var result = _executor . InferAsync ( CreatePrompt ( messages ) , CreateInferenceParams ( options ) , cancellationToken ) ;
66+ var result = _executor . InferAsync ( CreatePrompt ( messages , options ) , CreateInferenceParams ( options ) , cancellationToken ) ;
6767
6868 StringBuilder text = new ( ) ;
6969 await foreach ( var token in _outputTransform . TransformAsync ( result ) )
@@ -86,7 +86,7 @@ public async Task<ChatResponse> GetResponseAsync(
8686 public async IAsyncEnumerable < ChatResponseUpdate > GetStreamingResponseAsync (
8787 IEnumerable < ChatMessage > messages , ChatOptions ? options = null , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
8888 {
89- var result = _executor . InferAsync ( CreatePrompt ( messages ) , CreateInferenceParams ( options ) , cancellationToken ) ;
89+ var result = _executor . InferAsync ( CreatePrompt ( messages , options ) , CreateInferenceParams ( options ) , cancellationToken ) ;
9090
9191 string messageId = Guid . NewGuid ( ) . ToString ( "N" ) ;
9292 await foreach ( var token in _outputTransform . TransformAsync ( result ) )
@@ -100,7 +100,7 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
100100 }
101101
102102 /// <summary>Format the chat messages into a string prompt.</summary>
103- private string CreatePrompt ( IEnumerable < ChatMessage > messages )
103+ private string CreatePrompt ( IEnumerable < ChatMessage > messages , ChatOptions ? options = null )
104104 {
105105 if ( messages is null )
106106 {
@@ -120,6 +120,11 @@ private string CreatePrompt(IEnumerable<ChatMessage> messages)
120120 AuthorRole . User ,
121121 string . Concat ( message . Contents . OfType < TextContent > ( ) ) ) ;
122122 }
123+
124+ if ( options ? . Instructions is { } instructions )
125+ {
126+ history . AddMessage ( AuthorRole . System , instructions ) ;
127+ }
123128 }
124129 else
125130 {
0 commit comments