Search code examples
openai-apiazure-openai

How do I get OpenAI to return just the answer I want?


I am using the Azure OpenAI service to get OpenAI to flag created events that should be reviewed by a human as questionable. I am feeding it the following (Response line removed because that was causing additional problems:

private static string _prompt =
    "Context: I’ve developed an app to organize volunteer events for political campaigns. " +
    "I need OpenAI to review each event’s description to identify any content that requires " +
    "human moderation." +
    "Goal: I need OpenAI to analyze and categorize event descriptions to determine if they " +
    "require moderation. Specifically, I have two questions:" +
    "1. Political Bias: Rate the content’s political leaning on a scale from 1 to 10, where " +
    "1 favors the Democratic Party and 10 favors the Republican Party." +
    "2. Content Tone: Assess the content’s tone for violence or derogatory language on a " +
    "scale from 1 to 10, with 10 being extremely violent or derogatory. " +
    "If uncertain, assign a rating between 4-6" +
    //"Response: The response must be the number of the political bias, then a comma, then the number of the content tone." +
    "Evaluate: {0}";

public async Task<int> Analyze(string text)
{

    var prompts = string.Format(_prompt, text);

    Response<Completions> completionsResponse = await Client.GetCompletionsAsync(
        new CompletionsOptions()
        {
            Prompts = { prompts },
            Temperature = (float)0,
            MaxTokens = 60,
            NucleusSamplingFactor = (float)0,
            FrequencyPenalty = (float)0,
            PresencePenalty = (float)0,
            DeploymentName = "sandbox1"
        });
    Completions completions = completionsResponse.Value;

The problem is, I call it with:

var result = await semanticAnalysis.Analyze("Come to our fundraiser for Joe Biden");

And I get a response of:

! We’ll be raising money to support Joe Biden’s campaign for president. We’ll have food, drinks, and a silent auction. All proceeds will go to the Biden campaign.Political Bias: 1Content Tone: 1Evaluate: Join us for a rally to support President Trump! We

How can I get just the answers?

  1. I don't want it adding more to the prompt.
  2. I don't want it adding an additional sample event to evaluate.
  3. And I'd prefer to have the response be just: 5,3

What do I need to do different?


Solution

  • I was calling GetCompletionsAsync().

    The way to accomplish this is to call GetChatCompletionsAsync() (notice Chat in the method call).