Skip to content

Support Anthropic params in v1 chat agent API

Shinya Maeda requested to merge v1-agent-chat-support-anthropic-params into main

What does this merge request do and why?

In Pass `stop_sequences` to AI Gateway `v1/agent/c... (gitlab-org/gitlab#434925 - closed), the AI Gateway client in GitLab-Rails needs to pass stop_sequences, temperature and max_tokens_to_sample parameters in order to ensure that the Duo Chat behavior is same with the original Anthropic client implementation.

This MR adds these parameters to the /v1/chat/agent API according to the AI Gateway blueprint.

How to set up and validate locally

Request to /v1/chat/agent with payload.params:

{
  "prompt_components": [
    {
      "type": "string",
      "metadata": {
        "source": "string",
        "version": "string"
      },
      "payload": {
        "content": "\n\nHuman: Hi, How are you?\n\nAssistant:",
        "provider": "anthropic",
        "model": "claude-2.0",
        "params": {
          "stop_sequences": [
            "\n\nHuman",
            "Hoge:"
          ],
          "temperature": 0.3,
          "max_tokens_to_sample": 1024
        }
      }
    }
  ],
  "stream": false
}

Scraped log of log.debug("codegen anthropic call:", **opts):

{
    "timeout": "Timeout(connect=5.0, read=30.0, write=30.0, pool=30.0)",
    "max_tokens_to_sample": 1024,
    "stop_sequences": [
        "\n\nHuman",
        "Hoge:"
    ],
    "temperature": 0.3,
    "top_k": "<anthropic._types.NotGiven object at 0x7f851801b400>",
    "top_p": "<anthropic._types.NotGiven object at 0x7f851801b400>",
    "correlation_id": "ac4ee41b593a4e7e9b75c9694a35c681",
    "logger": "codesuggestions",
    "level": "debug",
    "type": "mlops",
    "stage": "main",
    "timestamp": "2023-12-12T06:09:17.255828Z",
    "message": "codegen anthropic call:"
}

Request to /v1/chat/agent without payload.params:

{
  "prompt_components": [
    {
      "type": "string",
      "metadata": {
        "source": "string",
        "version": "string"
      },
      "payload": {
        "content": "\n\nHuman: Hi, How are you?\n\nAssistant:",
        "provider": "anthropic",
        "model": "claude-2.0"
      }
    }
  ],
  "stream": false
}

Scraped log of log.debug("codegen anthropic call:", **opts):

{
    "timeout": "Timeout(connect=5.0, read=30.0, write=30.0, pool=30.0)",
    "max_tokens_to_sample": 2048,
    "stop_sequences": "<anthropic._types.NotGiven object at 0x7f851801b400>",
    "temperature": 0.2,
    "top_k": "<anthropic._types.NotGiven object at 0x7f851801b400>",
    "top_p": "<anthropic._types.NotGiven object at 0x7f851801b400>",
    "correlation_id": "27a25ee98fd5407a99153f48107ebb2d",
    "logger": "codesuggestions",
    "level": "debug",
    "type": "mlops",
    "stage": "main",
    "timestamp": "2023-12-12T06:10:17.720806Z",
    "message": "codegen anthropic call:"
}

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Shinya Maeda

Merge request reports