Skip to content

Regarding the issue of using context correlation in Windows AI Foundry ->Phi Silica #5518

Open
@qihui-liu

Description

@qihui-liu

How to use context correlation is not well demonstrated in the example, and I am not able to effectively utilize contextual content. Can you provide corresponding support.

I have used ai dev galley. But the examples it provides cannot support contextual content well.

Its example code is to add questions and answers to prompt words.

  private string GetPrompt(IEnumerable<ChatMessage> history)
  {
      if (!history.Any())
      {
          return string.Empty;
      }
  
      string prompt = string.Empty;
  
      var firstMessage = history.FirstOrDefault();
  
      _languageModelContext = firstMessage?.Role == ChatRole.System ?
          _languageModel?.CreateContext(firstMessage.Text, new ContentFilterOptions()) :
          _languageModel?.CreateContext();
  
      for (var i = 0; i < history.Count(); i++)
      {
          var message = history.ElementAt(i);
          if (message.Role == ChatRole.System)
          {
              if (i > 0)
              {
                  throw new ArgumentException("Only first message can be a system message");
              }
          }
          else if (message.Role == ChatRole.User)
          {
              string msgText = message.Text ?? string.Empty;
              prompt += msgText;
          }
          else if (message.Role == ChatRole.Assistant)
          {
              prompt += message.Text;
          }
      }
  
      return prompt;
  }

Activity

anarvekar-msft

anarvekar-msft commented on Jul 3, 2025

@anarvekar-msft

Thanks for sharing this feedback. We will look into updating our documentation with additional examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @qihui-liu@RDMacLachlan@anarvekar-msft

        Issue actions

          Regarding the issue of using context correlation in Windows AI Foundry ->Phi Silica · Issue #5518 · microsoft/WindowsAppSDK