azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

Azure OpenAI chat completion citations are missing the title and url values

Open tcihak-fqa opened this issue 1 year ago • 2 comments

Library name and version

Azure.AI.OpenAI v2.0.0-beta.2

Describe the bug

I am unable to get any citation title and url values for a chat completion call using a AzureCosmosDBChatDataSource. I verified that the CosmosDB database collection contains the title and url in a "metadata" property object.

Expected behavior

The citations contain non-null title and url values.

Actual behavior

The citations contain null values for title and url.

Reproduction Steps

      var endpoint = new Uri(OpenAiEndpoint);
      var credential = new AzureKeyCredential(this.configuration.OpenAIClientKey);
      var azureClient = new AzureOpenAIClient(endpoint, credential);
      var chatClient = azureClient.GetChatClient(OpenAiChatDeploymentName);

      var allMessages = new List<ChatMessage>();
      allMessages.AddRange(chatRequest.UserPrompts.Select(p => ChatMessage.CreateUserMessage(p)));
      if (!string.IsNullOrWhiteSpace(chatRequest.SystemPrompt))
      {
          allMessages.Add(ChatMessage.CreateSystemMessage(chatRequest.SystemPrompt));
      }

      var completionOptions = new ChatCompletionOptions()
      {
          MaxTokens = 800,
          ResponseFormat = ChatResponseFormat.Text,
          Temperature = 0.0f,
      };

      var fieldMappings = new DataSourceFieldMappings()
      {
          ContentFieldNames = { "text" },
          ContentFieldSeparator = "\n",
          VectorFieldNames = { "content_vector" },
          UrlFieldName = "metadata.url",
          TitleFieldName = "metadata.title",
      };

      var connectionString = string.Format(CosmosDataSourceConnectionString,
          this.configuration.CosmosDbUsername,
          this.configuration.CosmosDbPassword);
      var chatDataSource = new AzureCosmosDBChatDataSource()
      {
          Authentication = DataSourceAuthentication.FromConnectionString(connectionString),
          DatabaseName = CosmosDatabaseName,
          ContainerName = CosmosContainerName,
          IndexName = CosmosIndexName,
          FieldMappings = fieldMappings,
          VectorizationSource = DataSourceVectorizer.FromDeploymentName(CosmosVectorizationDeploymentName),
          InScope = true,
      };

#pragma warning disable AOAI001
      completionOptions.AddDataSource(chatDataSource);
#pragma warning restore AOAI001

      var chatCompletion = await chatClient.CompleteChatAsync(allMessages, completionOptions);
      var result = chatCompletion.Value;
      var text = result.Content[0].Text

#pragma warning disable AOAI001
      var messageContext = result.GetAzureMessageContext();
#pragma warning restore AOAI001

      foreach (var citation in messageContext.Citations)
      {
          // Both are null
          var title = citation.Title;
          var url = citation.Url;
      }

Environment

.NET SDK: Version: 8.0.303 Commit: 29ab8e3268 Workload version: 8.0.300-manifests.34944930 MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.303\

tcihak-fqa avatar Aug 26 '24 21:08 tcihak-fqa

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

github-actions[bot] avatar Aug 26 '24 21:08 github-actions[bot]

This seems quite an important one, and still not fixed? Trying to use these in our implementation.

awonnink avatar Oct 01 '24 09:10 awonnink

I was able to get the title and urls to return if I did the following:

  • Copy the title and url properties from the metadata object to the "root" object in the Cosmos DB
  • Update the field mappings to remove the "metadata."

Apparently, it's not possible to nest the title and url inside another object.

tcihak-fqa avatar Nov 14 '24 20:11 tcihak-fqa