@@ -4,25 +4,59 @@ interface Config {
44 baseUrl ?: string ;
55}
66
7+ const DEFAULT_BASE = 'https://api.gmi-serving.com' ;
8+
79export default defineAi < Config > ( {
810 id : 'ai-gmicloud' ,
911 label : 'GMICloud' ,
10- defaultModel : 'GMICLOUD_API_KEY' ,
11- models : [ 'GMICLOUD_API_KEY' ] ,
12+ defaultModel : 'deepseek-ai/DeepSeek-R1' ,
13+ models : [ 'deepseek-ai/DeepSeek-R1' ] ,
14+
15+ async generate ( ctx , prompt , opts , config ) {
16+ const apiKey = ctx . secret ( 'GMI_API_KEY' ) ;
17+ if ( ! apiKey ) throw new Error ( 'GMI_API_KEY not in vault' ) ;
18+ const model = opts . model ?? 'deepseek-ai/DeepSeek-R1' ;
19+ ctx . log ( `gmicloud · model=${ model } · ${ prompt . length } chars in` ) ;
20+ if ( ctx . dryRun ) return { text : '[dry-run]' , model } ;
21+
22+ const messages : Array < { role : string ; content : string } > = [ ] ;
23+ if ( opts . system ) messages . push ( { role : 'system' , content : opts . system } ) ;
24+ messages . push ( { role : 'user' , content : prompt } ) ;
1225
13- async generate ( ctx , prompt , _opts , _config ) {
14- const apiKey = ctx . secret ( 'https://gmicloud.ai' ) ;
15- if ( ! apiKey ) throw new Error ( 'https://gmicloud.ai not in vault — run `sh1pt promote ai setup`' ) ;
16- ctx . log ( `[stub] ai-gmicloud · ${ prompt . length } chars in — integration pending` ) ;
17- return { text : '[stub — ai-gmicloud integration not yet implemented]' , model : 'GMICLOUD_API_KEY' } ;
26+ const res = await fetch ( `${ config . baseUrl ?? DEFAULT_BASE } /v1/chat/completions` , {
27+ method : 'POST' ,
28+ headers : {
29+ authorization : `Bearer ${ apiKey } ` ,
30+ 'content-type' : 'application/json' ,
31+ } ,
32+ body : JSON . stringify ( {
33+ model,
34+ messages,
35+ ...( opts . maxTokens !== undefined ? { max_tokens : opts . maxTokens } : { } ) ,
36+ ...( opts . temperature !== undefined ? { temperature : opts . temperature } : { } ) ,
37+ ...opts . extra ,
38+ } ) ,
39+ } ) ;
40+ if ( ! res . ok ) throw new Error ( `GMICloud ${ res . status } : ${ ( await res . text ( ) ) . slice ( 0 , 200 ) } ` ) ;
41+ const data = ( await res . json ( ) ) as {
42+ choices : Array < { message ?: { content ?: string } } > ;
43+ model : string ;
44+ usage ?: { prompt_tokens ?: number ; completion_tokens ?: number } ;
45+ } ;
46+ return {
47+ text : data . choices [ 0 ] ?. message ?. content ?? '' ,
48+ model : data . model ,
49+ inputTokens : data . usage ?. prompt_tokens ,
50+ outputTokens : data . usage ?. completion_tokens ,
51+ } ;
1852 } ,
1953
2054 setup : tokenSetup < Config > ( {
21- secretKey : 'https://gmicloud.ai ' ,
55+ secretKey : 'GMI_API_KEY ' ,
2256 label : 'GMICloud' ,
23- vendorDocUrl : '' ,
57+ vendorDocUrl : 'https://docs.gmicloud.ai/inference-engine/api-reference ' ,
2458 steps : [
25- 'Sign in at and create an API key' ,
59+ 'Sign in at https://www.gmicloud.ai and create an API key' ,
2660 'Copy the key — usually shown once' ,
2761 'Paste below; sh1pt encrypts it in the vault' ,
2862 ] ,
0 commit comments