CustomModel class

Custom AI model implementation that allows for custom API endpoints and request/response handling.

Example usage:

late final Models model;

 @override
 void initState() {
   model = CustomModel(
     url: "https://api.together.xyz/v1/chat/completions",
     customHeaders: {
       "Authorization": "Bearer ${your_api_key}",
       "Content-Type": "application/json"
     },
     requestBuilder: (code, instruction){
      return {
         "model": "deepseek-ai/DeepSeek-V3",
         "messages": [
           {
             "role": "system",
            "content": instruction
           },
           {
             "role": "user",
             "content": code
          }
         ]
       };
     },
     customParser: (response) => response['choices'][0]['message']['content']
   );
   controller = CodeCrafterController();
   controller.language = python;
   super.initState();
 }

Then pass the model instance to the AiCompletion class:

@override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: CodeCrafter(
         editorTheme: anOldHopeTheme,
         controller: controller,
         aiCompletion: AiCompletion(
           model: model // Pass the custom model here
         ),
       )
     ),
   );
}
Inheritance

Constructors

CustomModel({required String url, required Map<String, String> customHeaders, required Map<String, dynamic> requestBuilder(String code, String instruction)?, required String customParser(dynamic response), String httpMethod = 'POST'})

Properties

apiKey String?
API key for the AI service, if required.
no setteroverride
customHeaders Map<String, String>
final
customParser String Function(dynamic response)
final
hashCode int
The hash code for this object.
no setterinherited
headers Map<String, String>
Headers to include in the HTTP request.
no setteroverride
httpMethod String
final
instruction String
finalinherited
model String?
The model to use for AI completion, if applicable.
no setteroverride
requestBuilder Map<String, dynamic> Function(String code, String instruction)?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
url String
The URL for the custom AI service endpoint.
final

Methods

buildRequest(String code) Map<String, dynamic>
override
completionResponse(String code) Future<String>
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
responseParser(dynamic response) String
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited