Skip to content

Instrument token usage consumption for code generation

What does this merge request do and why?

Closes #417 (closed)

How to set up and validate locally

  1. Set up Snowplow micro https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/howto/snowplow_micro.md?ref_type=heads
  2. Ensure that Snowplow tracking is enabled in .env file for AI Gateway.
    # Tracking
    AIGW_SNOWPLOW__ENABLED=true
    AIGW_SNOWPLOW__ENDPOINT="http://localhost:9090"
    AIGW_SNOWPLOW__BATCH_SIZE=1
    AIGW_SNOWPLOW__THREAD_COUNT=1
  3. Trigger code completion requests (you can toggle intent to "completion", and stream to true)
    curl -X POST -H "Content-Type: Application/json"  -H "Authorization: Bearer $GDK_AI_API_TOKEN" http://gdk.test:3000/api/v4/code_suggestions/completions --data '{   "current_file": {
       "file_name": "utils.go",
       "content_above_cursor": "// generate function that loads env variables from .env file",
       "content_below_cursor": ""
     },
     "project_path": "",
     "stream": false,
     "intent": "generation"
    }'
  4. Check that correct events were reported to snowplow micro collector curl localhost:9091/micro/good | jq '.[] | .event.se_action, .event.se_value'

Screenshot_2024-02-27_at_12.11.09

Merge request checklist

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

Merge request reports