Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.25k stars 4.59k forks source link

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

Open tcihak-fqa opened 3 weeks ago

tcihak-fqa commented 3 weeks ago

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\

github-actions[bot] commented 3 weeks ago

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