File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -86,4 +86,25 @@ export class MistralHandler implements ApiHandler {
8686 info : mistralModels [ mistralDefaultModelId ] ,
8787 }
8888 }
89+
90+ async completePrompt ( prompt : string ) : Promise < string > {
91+ try {
92+ const response = await this . client . chat . complete ( {
93+ model : this . options . apiModelId || mistralDefaultModelId ,
94+ messages : [ { role : "user" , content : prompt } ] ,
95+ temperature : this . options . modelTemperature ?? MISTRAL_DEFAULT_TEMPERATURE ,
96+ } )
97+
98+ const content = response . choices ?. [ 0 ] ?. message . content
99+ if ( Array . isArray ( content ) ) {
100+ return content . map ( ( c ) => ( c . type === "text" ? c . text : "" ) ) . join ( "" )
101+ }
102+ return content || ""
103+ } catch ( error ) {
104+ if ( error instanceof Error ) {
105+ throw new Error ( `Mistral completion error: ${ error . message } ` )
106+ }
107+ throw error
108+ }
109+ }
89110}
You can’t perform that action at this time.
0 commit comments