jodendaal / OpenAI.Net

OpenAI library for .NET
MIT License
126 stars 28 forks source link

Serialization method affects output #76

Closed graemefoster closed 1 year ago

graemefoster commented 1 year ago

The serialization method used on ChatCompletions produces \u0022 unicode quote strings. This affects the output from ChatGPT.

As an example, given this system prompt:

You are a bank teller.

Work out what the customer wants to do and respond with the function named "customerInformation"

You must return only the parameters in the sample.
You must return the value "UNKNOWN" for missing parameters.
Do not make up parameters.

FUNCTION:
{
  "name": "customerInformation",
  "description": "get some information on the customers bank account",
  "parameters": {
    "type": "object",
    "properties": {
      "accountNumber": {
        "type": "string",
        "description": "The bank account number"
      },
      "service": {
        "type": "string",
        "enum": [
          "balance",
          "details",
          "payments",
          "schedules",
          "unknown"
        ],
        "description": "What the user wants to do"
      }
    }
  }
}

This is created by OpenAI studio:

{"messages":[{"role":"system","content":"You are a bank teller.\n\nWork out what the customer wants to do and respond with the function named \"customerInformation\"\n\nYou must return only the parameters in the sample.\nYou must return the value \"UNKNOWN\" for missing parameters.\nDo not make up parameters.\n\nFUNCTION:\n{\n  \"name\": \"customerInformation\",\n  \"description\": \"get some information on the customers bank account\",\n  \"parameters\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"accountNumber\": {\n        \"type\": \"string\",\n        \"description\": \"The bank account number\"\n      },\n      \"service\": {\n        \"type\": \"string\",\n        \"enum\": [\n          \"balance\",\n          \"details\",\n          \"payments\",\n          \"schedules\",\n          \"unknown\"\n        ],\n        \"description\": \"What the user wants to do\"\n      }\n    }\n  }\n}"},{"role":"user","content":"what's my balance?"}],"temperature":0,"top_p":0,"frequency_penalty":0,"presence_penalty":0,"max_tokens":800,"stop":null,"stream":true}

This is created by the .Net Open AI Client:

{"messages":[{"role":"system","content":"You are a bank teller.\n\nWork out what the customer wants to do and respond with the function named \u0022customerInformation\u0022\n\nYou must return only the parameters in the sample.\nYou must return the value \u0022UNKNOWN\u0022 for missing parameters.\nDo not make up parameters.\r\n\r\nFUNCTION:\r\n{\r\n  \u0022name\u0022: \u0022customerInformation\u0022,\r\n  \u0022description\u0022: \u0022get some information on the customers bank account\u0022,\r\n  \u0022parameters\u0022: {\r\n    \u0022type\u0022: \u0022object\u0022,\r\n    \u0022properties\u0022: {\r\n      \u0022accountNumber\u0022: {\r\n        \u0022type\u0022: \u0022string\u0022,\r\n        \u0022description\u0022: \u0022The bank account number\u0022\r\n      },\r\n      \u0022service\u0022: {\r\n        \u0022type\u0022: \u0022string\u0022,\r\n        \u0022enum\u0022: [\r\n          \u0022balance\u0022,\r\n          \u0022details\u0022,\r\n          \u0022payments\u0022,\r\n          \u0022schedules\u0022,\r\n          \u0022unknown\u0022\r\n        ],\r\n        \u0022description\u0022: \u0022What the user wants to do\u0022\r\n      }\r\n    }\r\n  }\r\n}"},{"role":"user","content":"what\u0027s my balance?"}],"max_tokens":800,"temperature":0,"top_p":0,"presence_penalty":0,"frequency_penalty":0}

The output from both is different. The OpenAI studio produces a more consistent output than the .Net Open AI Client.

Would you take a Pull Request to switch to an output that uses consistent \" instead of the \u0022 encodings?