1+ //[genAI-Service-Detection]
2+ // uncomment for webpagetest
3+
4+ // not sure if the list is exhaustive
5+ console . log ( "Running genAI-Service-Detection metric" ) ;
6+ try {
7+ const patterns = {
8+ // GenAI Services
9+ 'Azure AI Services' : {
10+ regEx : / h t t p s : \/ \/ [ ^ \/ ] + \. s e r v i c e s \. a i \. a z u r e \. c o m \/ m o d e l s / ,
11+ } ,
12+ 'AWS SageMaker' : {
13+ regEx : / h t t p s : \/ \/ r u n t i m e \. s a g e m a k e r \. [ ^ \/ ] + \. a m a z o n a w s \. c o m / ,
14+ } ,
15+ 'IBM Watson ML' : {
16+ regEx : / h t t p s : \/ \/ [ ^ \/ ] + \. m l \. c l o u d \. i b m \. c o m / ,
17+ } ,
18+ 'Alibaba Cloud ML' : {
19+ regEx : / h t t p s : \/ \/ [ ^ \/ ] + \. f c \. [ ^ \/ ] + \. a l i y u n c s \. c o m / ,
20+ } ,
21+ 'Huawei Cloud AI' : {
22+ regEx : / h t t p s : \/ \/ i a m \. [ ^ \/ ] + \. m y h u a w e i c l o u d \. c o m \/ v 3 / ,
23+ } ,
24+ 'Google Vertex AI' : {
25+ regEx : / h t t p s : \/ \/ [ ^ \/ ] + \/ v 1 \/ [ ^ \/ ] + : p r e d i c t / ,
26+ } ,
27+ 'Amazon Bedrock' : {
28+ regEx : / h t t p s : \/ \/ b e d r o c k \. [ ^ \/ ] + \. a m a z o n a w s \. c o m / ,
29+ } ,
30+ 'Azure OpenAI' : {
31+ regEx : / h t t p s : \/ \/ [ ^ \/ ] + \. o p e n a i \. a z u r e \. c o m \/ o p e n a i \/ d e p l o y m e n t s \/ [ ^ \/ ] + / ,
32+ } ,
33+
34+ // Common GenAI APIs
35+ 'OpenAI' : {
36+ regEx : / a p i \. o p e n a i \. c o m / ,
37+ } ,
38+ 'ChatGPT' :{
39+ regEx : / c h a t g p t \. c o m / ,
40+ } ,
41+ 'Anthropic' : {
42+ regEx : / a p i \. a n t h r o p i c \. c o m / ,
43+ } ,
44+ 'Google PaLM' : {
45+ regEx : / g e n e r a t i v e l a n g u a g e \. g o o g l e a p i s \. c o m / ,
46+ } ,
47+ 'Cohere' : {
48+ regEx : / a p i \. c o h e r e \. a i / ,
49+ } ,
50+ 'Hugging Face' : {
51+ regEx : / ( .* \. ) ? h u g g i n g f a c e \. c o / ,
52+ } ,
53+ 'Mistral' : {
54+ regEx : / ( .* \. ) ? m i s t r a l \. a i / ,
55+ } ,
56+ 'Perplexity' : {
57+ regEx : / ( .* \. ) ? p e r p l e x i t y \. a i / ,
58+ } ,
59+ 'Bard' : {
60+ regEx : / ( .* \. ) ? b a r d \. g o o g l e \. c o m / ,
61+ } ,
62+ 'Groq' : {
63+ regEx : / a p i \. g r o q \. c o m / ,
64+ } ,
65+ 'Cerebras' : {
66+ regEx : / a p i \. c e r e b r a s \. a i / ,
67+ } ,
68+
69+ // Proxy Services
70+ 'OpenRouter (Proxy)' : {
71+ regEx : / h t t p s : \/ \/ o p e n r o u t e r \. a i \/ a p i \/ v 1 / ,
72+ } ,
73+ 'LangChain (Proxy)' : {
74+ regEx : / \/ l a n g s e r v e \/ | \/ a g e n t \/ | \/ l l m ( - i n v o k e ) ? \/ | \/ c h a i n \/ | \/ t o o l s ? \/ | \/ p r e d i c t \/ | \/ i n v o k e \/ / i,
75+ } ,
76+ 'Flowise (Proxy)' : {
77+ regEx : / \/ a p i \/ v 1 \/ p r e d i c t i o n | \/ f l o w i s e - a p i / i,
78+ } ,
79+ 'Poe' : {
80+ regEx : / ( .* \. ) ? p o e \. c o m / ,
81+ } ,
82+ 'Replicate' : {
83+ regEx : / ( .* \. ) ? r e p l i c a t e \. c o m / ,
84+ } ,
85+ }
86+
87+ const requestBodies = $WPT_REQUESTS ;
88+
89+ // Iterate over all response bodies and over all patterns and populate the
90+ // result object.
91+ const result = { } ;
92+
93+
94+ requestBodies . forEach ( ( har ) => {
95+ const url = har . url
96+ if ( ! url ) {
97+ return
98+ }
99+ for ( const [ key , value ] of Object . entries ( patterns ) ) {
100+ if ( value . regEx . test ( har . url ) ) {
101+ if ( result [ key ] && ! result [ key ] . includes ( url ) ) {
102+ result [ key ] . push ( url . trim ( ) . replace ( / \/ $ / , "" ) ) ;
103+ } else {
104+ result [ key ] = [ url . trim ( ) . replace ( / \/ $ / , "" ) ] ;
105+ }
106+ }
107+ }
108+ } ) ;
109+
110+ return result
111+ }
112+ catch ( e ) {
113+ return { error : e . message }
114+ }
0 commit comments