@@ -392,12 +392,31 @@ private static List<SystemContentBlock> CreateSystem(List<SystemContentBlock>? r
392392
393393 if ( options ? . Instructions is { } instructions )
394394 {
395- system . Add ( new SystemContentBlock ( ) { Text = instructions } ) ;
395+ system . Add ( new SystemContentBlock ( )
396+ {
397+ Text = instructions ,
398+ } ) ;
396399 }
397400
398- system . AddRange ( messages
399- . Where ( m => m . Role == ChatRole . System && m . Contents . Any ( c => c is TextContent ) )
400- . Select ( m => new SystemContentBlock ( ) { Text = string . Concat ( m . Contents . OfType < TextContent > ( ) ) } ) ) ;
401+ foreach ( var message in messages
402+ . Where ( m => m . Role == ChatRole . System && m . Contents . Any ( c => c is TextContent ) ) )
403+ {
404+ system . Add ( new SystemContentBlock ( )
405+ {
406+ Text = string . Concat ( message . Contents . OfType < TextContent > ( ) ) ,
407+ } ) ;
408+
409+ if ( message . AdditionalProperties ? . TryGetValue ( nameof ( ContentBlock . CachePoint ) , out var maybeCachePoint ) == true )
410+ {
411+ if ( maybeCachePoint is CachePointBlock cachePointBlock )
412+ {
413+ system . Add ( new SystemContentBlock ( )
414+ {
415+ CachePoint = cachePointBlock ,
416+ } ) ;
417+ }
418+ }
419+ }
401420
402421 return system ;
403422 }
@@ -440,6 +459,17 @@ private static List<Message> CreateMessages(List<Message>? rawMessages, IEnumera
440459 }
441460 }
442461
462+ if ( chatMessage . AdditionalProperties ? . TryGetValue ( nameof ( ContentBlock . CachePoint ) , out var maybeCachePoint ) == true )
463+ {
464+ if ( maybeCachePoint is CachePointBlock cachePointBlock )
465+ {
466+ contents . Add ( new ( )
467+ {
468+ CachePoint = cachePointBlock
469+ } ) ;
470+ }
471+ }
472+
443473 messages . Add ( new ( )
444474 {
445475 Role = chatMessage . Role == ChatRole . Assistant ? ConversationRole . Assistant : ConversationRole . User ,
@@ -573,6 +603,18 @@ private static List<ContentBlock> CreateContents(ChatMessage message)
573603 } ) ;
574604 break ;
575605 }
606+
607+
608+ if ( content . AdditionalProperties ? . TryGetValue ( nameof ( ContentBlock . CachePoint ) , out var maybeCachePoint ) == true )
609+ {
610+ if ( maybeCachePoint is CachePointBlock cachePointBlock )
611+ {
612+ contents . Add ( new ( )
613+ {
614+ CachePoint = cachePointBlock
615+ } ) ;
616+ }
617+ }
576618 }
577619
578620 return contents ;
0 commit comments