1616
1717import { get } from 'http' ;
1818import { getApiToken } from '../config' ;
19- import { PLUGIN_DEFAULT_TOKEN } from '../config' ;
20-
19+ import { API_BASE , MODEL_NAME , PLUGIN_DEFAULT_TOKEN } from '../config' ;
2120
2221export async function callSimdAiWithHistory ( messages : { role : string ; content : string } [ ] ) : Promise < string > {
2322 const apiToken = getApiToken ( ) ;
2423 if ( ! apiToken ) { return '⚠️ API token missing' ; }
2524
2625 try {
27- const res = await fetch ( 'https://simd.ai/api/ chat/completions' , {
26+ const res = await fetch ( ` ${ API_BASE } / chat/completions` , {
2827 method : 'POST' ,
2928 headers : {
3029 'Content-Type' : 'application/json' ,
3130 'Authorization' : `Bearer ${ apiToken } `
3231 } ,
3332 body : JSON . stringify ( {
34- model : 'SIMD-ai-2506.1.ai:24b' ,
33+ model : MODEL_NAME ,
3534 messages
3635 } )
3736 } ) ;
@@ -56,7 +55,7 @@ let cachedIntrinsics: string[] | null = null;
5655export async function fetchIntrinsicNames ( ) : Promise < string [ ] > {
5756 let apiToken = getApiToken ( ) ;
5857
59- // if user has not specified api token, use predifined to only see Intel intrinsics
58+ // if user has not specified api token, use predifined to only see Intel intrinsics and some Preview
6059 if ( ! apiToken ) {
6160 apiToken = PLUGIN_DEFAULT_TOKEN ;
6261 }
@@ -66,7 +65,7 @@ export async function fetchIntrinsicNames(): Promise<string[]> {
6665 }
6766
6867 try {
69- const response = await fetch ( 'https://simd.ai/api/ v1/plugin-intrinsics-list/get-intrinsics-list' , {
68+ const response = await fetch ( ` ${ API_BASE } / v1/plugin-intrinsics-list/get-intrinsics-list` , {
7069 method : 'POST' ,
7170 headers : {
7271 'Content-Type' : 'application/json'
@@ -111,6 +110,32 @@ export async function fetchIntrinsicNames(): Promise<string[]> {
111110 }
112111}
113112
113+ export async function sendToSimdAI ( userPrompt : string ) {
114+ const apiToken = getApiToken ( ) ;
115+ if ( ! apiToken ) { throw new Error ( 'API token missing' ) ; }
116+
117+ const endpoint = `${ API_BASE } /chat/completions` ;
118+
119+ const response = await fetch ( endpoint , {
120+ method : 'POST' ,
121+ headers : {
122+ 'Content-Type' : 'application/json' ,
123+ 'Authorization' : `Bearer ${ apiToken } `
124+ } ,
125+ body : JSON . stringify ( {
126+ model : MODEL_NAME ,
127+ messages : [ { role : 'user' , content : userPrompt } ]
128+ } )
129+ } ) ;
130+
131+ if ( ! response . ok ) {
132+ throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` ) ;
133+ }
134+
135+ const data = await response . json ( ) ;
136+ return data ;
137+ }
138+
114139interface Prototype {
115140 key : string ;
116141 output ?: string ;
@@ -149,7 +174,7 @@ export async function fetchIntrinsicInfo(word: string): Promise<TooltipData | nu
149174 }
150175
151176 try {
152- const response = await fetch ( `https://simd.ai/api /v1/plugin-intrinsic-info/get-intrinsics-info` , {
177+ const response = await fetch ( `${ API_BASE } /v1/plugin-intrinsic-info/get-intrinsics-info` , {
153178 method : 'POST' ,
154179 headers : {
155180 'Content-Type' : 'application/json'
0 commit comments