Skip to content

Commit b7835b3

Browse files
authored
feat: Added rendering of our AI Monitoring compatibilities (#24)
1 parent 1107143 commit b7835b3

12 files changed

Lines changed: 696 additions & 158 deletions

Readme.md

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,8 @@ This project relies on some community tools that require extra installation:
2424
./nrversions
2525
```
2626

27-
Will output a compatibility report like this
28-
29-
```
30-
+------------------------+---------------------+----------------------------+---------------+----------------------+
31-
| NAME | MINSUPPORTEDVERSION | MINSUPPORTEDVERSIONRELEASE | LATESTVERSION | LATESTVERSIONRELEASE |
32-
+------------------------+---------------------+----------------------------+---------------+----------------------+
33-
| @apollo/gateway | 2.3.0 | 2023-01-25 | 2.7.3 | 2024-04-16 |
34-
| @apollo/server | 4.0.0 | 2022-10-10 | 4.10.3 | 2024-04-15 |
35-
| @elastic/elasticsearch | 7.16.0 | 2021-12-15 | 8.13.1 | 2024-04-09 |
36-
| @grpc/grpc-js | 1.4.0 | 2021-10-13 | 1.10.6 | 2024-04-03 |
37-
| @hapi/hapi | 20.1.2 | 2021-03-20 | 21.3.9 | 2024-04-09 |
38-
| @langchain/core | 0.1.17 | 2024-01-19 | 0.1.58 | 2024-04-16 |
39-
| @nestjs/cli | 8.0.0 | 2021-07-07 | 10.3.2 | 2024-02-07 |
40-
| @prisma/client | 5.0.0 | 2023-07-11 | 5.12.1 | 2024-04-04 |
41-
| amqplib | 0.5.0 | 2016-11-01 | 0.10.4 | 2024-04-11 |
42-
| apollo-server | 2.14.0 | 2020-05-27 | 3.13.0 | 2023-11-14 |
43-
| apollo-server-express | 2.14.0 | 2020-05-27 | 3.13.0 | 2023-11-14 |
44-
| apollo-server-fastify | 2.14.0 | 2020-05-27 | 3.13.0 | 2023-11-14 |
45-
| apollo-server-hapi | 3.0.0 | 2021-07-07 | 3.13.0 | 2023-11-14 |
46-
| apollo-server-koa | 2.14.0 | 2020-05-27 | 3.13.0 | 2023-11-14 |
47-
| apollo-server-lambda | 2.14.0 | 2020-05-27 | 3.13.0 | 2023-11-14 |
48-
| bluebird | 2.0.0 | 2014-06-04 | 3.7.2 | 2019-11-28 |
49-
| bunyan | 1.8.12 | 2017-08-02 | 1.8.15 | 2021-01-08 |
50-
| cassandra-driver | 3.4.0 | 2018-02-05 | 4.7.2 | 2023-09-21 |
51-
| connect | 2.0.0 | 2012-02-28 | 3.7.0 | 2019-05-18 |
52-
| director | 1.2.0 | 2013-04-01 | 1.2.8 | 2015-02-04 |
53-
| express | 4.6.0 | 2014-07-12 | 4.19.2 | 2024-03-25 |
54-
| fastify | 2.0.0 | 2019-02-25 | 4.26.2 | 2024-03-03 |
55-
| generic-pool | 2.4.0 | 2016-01-18 | 3.9.0 | 2022-09-10 |
56-
| ioredis | 3.0.0 | 2017-05-18 | 5.3.2 | 2023-04-15 |
57-
| mongodb | 2.1.0 | 2015-12-06 | 6.5.0 | 2024-03-11 |
58-
| mysql | 2.2.0 | 2014-04-27 | 2.18.1 | 2020-01-23 |
59-
| mysql2 | 1.3.1 | 2017-05-31 | 3.9.4 | 2024-04-09 |
60-
| next | 13.0.0 | 2022-10-25 | 14.2.1 | 2024-04-12 |
61-
| openai | 4.0.0 | 2023-08-16 | 4.35.0 | 2024-04-16 |
62-
| pg | 8.2.0 | 2020-05-13 | 8.11.5 | 2024-04-02 |
63-
| pino | 7.0.0 | 2021-10-14 | 8.20.0 | 2024-04-06 |
64-
| redis | 2.0.0 | 2015-09-21 | 4.6.13 | 2024-02-05 |
65-
| restify | 5.0.0 | 2017-06-27 | 11.1.0 | 2023-02-24 |
66-
| superagent | 2.0.0 | 2016-05-29 | 8.1.2 | 2023-08-15 |
67-
| undici | 4.7.0 | 2021-09-22 | 6.13.0 | 2024-04-12 |
68-
| winston | 3.0.0 | 2018-06-12 | 3.13.0 | 2024-03-24 |
69-
+------------------------+---------------------+----------------------------+---------------+----------------------+
70-
```
27+
Will output a report document as shown in our main repo's
28+
[compatibility doc](https://github.com/newrelic/node-newrelic/blob/main/compatibility.md).
7129

7230
For optional CLI args, run:
7331

@@ -80,14 +38,15 @@ modules.
8038

8139
The following flags are supported:
8240

41+
-a, --ai-compat-json string Path to the ai-compat.json file that describes the AI Monitoring
42+
compatibility of the agent. The default is to use the JSON file included
43+
in the mainline agent repository.
44+
8345
-n, --no-externals Disable cloning and processing of external repos. An external repo is
8446
one that provides extra functionality to the "newrelic" module. This
8547
allows processing a single repo with --repo-dir. The default, i.e. not
8648
supplying this flag, is to process all known external repos.
8749

88-
-o, --output-format string Specify the format to write the results as. The default is an ASCII
89-
table. Possible values: "ascii" or "markdown".
90-
(default "markdown")
9150
-R, --replace-in-file string Specify a target file in which the results will be written. Normally,
9251
the result is written to stdout. When this flag is given, the result
9352
will be written to the specified file. The generated text will replace

Taskfile.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ tasks:
2222
sources:
2323
- "**/*.go"
2424
- "**/testdata/*"
25+
- "**/tmpl/*"
2526

2627
test-cov:
2728
cmds:
2829
- go test -cover ./...
2930
sources:
3031
- "**/*.go"
3132
- "**/testdata/*"
33+
- "**/tmpl/*"
3234

3335
test-cov-html:
3436
cmds:
@@ -37,3 +39,4 @@ tasks:
3739
sources:
3840
- "**/*.go"
3941
- "**/testdata/*"
42+
- "**/tmpl/*"

ai-compat-types.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
const AiCompatKindGateway = "gateway"
4+
const AiCompatKindAbstraction = "abstraction"
5+
const AiCompatKindSdk = "sdk"
6+
7+
type AiCompatJson []AiCompatEnvelope
8+
9+
// AiCompatEnvelope represents the generic structure of objects found within
10+
// the AI compatability JSON descriptor document.
11+
type AiCompatEnvelope struct {
12+
Kind string `json:"kind"`
13+
Title string `json:"title"`
14+
Preamble string `json:"preamble,omitempty"`
15+
Footnote string `json:"footnote,omitempty"`
16+
FeaturesPreamble string `json:"featuresPreamble,omitempty"`
17+
ProvidersPreamble string `json:"providersPreamble,omitempty"`
18+
Models []AiCompatModel `json:"models,omitempty"`
19+
Features []AiCompatFeature `json:"features,omitempty"`
20+
Providers []AiCompatProvider `json:"providers,omitempty"`
21+
}
22+
23+
// AiCompatGateway is a narrow type derived from an [AiCompatEnvelope] with
24+
// `kind = "gateway"`.
25+
type AiCompatGateway struct {
26+
Title string
27+
Preamble string
28+
Footnote string
29+
Models []AiCompatModel
30+
}
31+
32+
// AiCompatAbstraction is a narrow type derived from an [AiCompatEnvelope] with
33+
// `kind = "abstraction"`.
34+
type AiCompatAbstraction struct {
35+
Title string
36+
FeaturesPreamble string
37+
ProvidersPreamble string
38+
Features []AiCompatFeature
39+
Providers []AiCompatProvider
40+
}
41+
42+
// AiCompatSdk is a narrow type derived from an [AiCompatEnvelope] with
43+
// `kind = "sdk"`.
44+
type AiCompatSdk struct {
45+
Title string
46+
FeaturesPreamble string
47+
Features []AiCompatFeature
48+
}
49+
50+
type AiCompatFeature struct {
51+
Title string `json:"title"`
52+
Supported bool `json:"supported"`
53+
}
54+
55+
type AiCompatModel struct {
56+
Name string `json:"name"`
57+
Features []AiCompatFeature `json:"features"`
58+
}
59+
60+
type AiCompatProvider struct {
61+
Name string `json:"name"`
62+
Supported bool `json:"supported"`
63+
Transitively bool `json:"transitively"`
64+
}
65+
66+
// AiCompatTemplateData represents the context that will be utilized by the
67+
// template engine to render the human readable Markdown document.
68+
type AiCompatTemplateData struct {
69+
Abstractions []AiCompatAbstraction
70+
Gateways []AiCompatGateway
71+
Sdks []AiCompatSdk
72+
}

ai-compat-types_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"github.com/stretchr/testify/assert"
6+
"github.com/stretchr/testify/require"
7+
"os"
8+
"testing"
9+
)
10+
11+
func Test_AiCompatJson(t *testing.T) {
12+
fileData, err := os.ReadFile("testdata/ai-compat.json")
13+
require.Nil(t, err)
14+
15+
var parsed AiCompatJson
16+
err = json.Unmarshal(fileData, &parsed)
17+
require.Nil(t, err)
18+
assert.Equal(t, 4, len(parsed))
19+
20+
expectedGateway := AiCompatEnvelope{
21+
Kind: AiCompatKindGateway,
22+
Title: "Amazon Bedrock",
23+
Preamble: "Through the `@aws-sdk/client-bedrock-runtime` module, we support:",
24+
Footnote: "Note: if a model supports streaming, we also instrument the streaming variant.",
25+
Models: []AiCompatModel{
26+
{
27+
Name: "Claude",
28+
Features: []AiCompatFeature{
29+
{"Text", true},
30+
{"Image", false},
31+
},
32+
},
33+
{
34+
Name: "Cohere",
35+
Features: []AiCompatFeature{
36+
{"Text", true},
37+
{"Image", false},
38+
},
39+
},
40+
},
41+
}
42+
assert.Equal(t, expectedGateway, parsed[0])
43+
44+
expectedAbstraction := AiCompatEnvelope{
45+
Kind: AiCompatKindAbstraction,
46+
Title: "Langchain",
47+
FeaturesPreamble: "The following general features of Langchain are supported:",
48+
ProvidersPreamble: "Models/providers are generally supported transitively by our instrumentation of the provider's module.",
49+
Features: []AiCompatFeature{
50+
{"Agents", true},
51+
{"Chains", true},
52+
{"Vectorstores", true},
53+
{"Tools", true},
54+
},
55+
Providers: []AiCompatProvider{
56+
{"Azure OpenAI", false, false},
57+
{"OpenAI", true, true},
58+
},
59+
}
60+
assert.Equal(t, expectedAbstraction, parsed[2])
61+
62+
expectedSdk := AiCompatEnvelope{
63+
Kind: AiCompatKindSdk,
64+
Title: "OpenAI",
65+
FeaturesPreamble: "Through the `openai` module, we support:",
66+
Features: []AiCompatFeature{
67+
{"Completions", true},
68+
{"Chat", true},
69+
{"Embeddings", true},
70+
{"Files", false},
71+
{"Images", false},
72+
{"Audio", false},
73+
},
74+
}
75+
assert.Equal(t, expectedSdk, parsed[3])
76+
}

0 commit comments

Comments
 (0)