openChat method

Future<InferenceChat> openChat({
  1. double temperature = .8,
  2. int randomSeed = 1,
  3. int topK = 1,
  4. double? topP,
  5. int tokenBuffer = 256,
  6. String? loraPath,
  7. bool? supportImage,
  8. bool? supportAudio,
  9. List<Tool> tools = const [],
  10. bool? supportsFunctionCalls,
  11. bool isThinking = false,
  12. ModelType? modelType,
  13. ToolChoice toolChoice = ToolChoice.auto,
  14. int? maxFunctionBufferLength,
  15. String? systemInstruction,
})

Same as createChat, but uses openSession internally so the resulting chat owns an independent session that does not touch the legacy session field or other open chats. Use this when you need concurrent chats on a single loaded model.

Each chat's own context-overflow rotation (_recreateSessionWithReducedChunks) creates a fresh sibling session via openSession, so peer chats are unaffected.

See openSession for the memory caveat. The returned chat is NOT stored in chat — that field tracks only the legacy createChat singleton. Hold the returned chat reference yourself and close it when done.

Implementation

Future<InferenceChat> openChat({
  double temperature = .8,
  int randomSeed = 1,
  int topK = 1,
  double? topP,
  int tokenBuffer = 256,
  String? loraPath,
  bool? supportImage,
  bool? supportAudio,
  List<Tool> tools = const [],
  bool? supportsFunctionCalls,
  bool isThinking = false,
  ModelType? modelType,
  ToolChoice toolChoice = ToolChoice.auto,
  int? maxFunctionBufferLength,
  String? systemInstruction,
}) async {
  final independentChat = InferenceChat(
    sessionCreator: () => openSession(
      temperature: temperature,
      randomSeed: randomSeed,
      topK: topK,
      topP: topP,
      loraPath: loraPath,
      enableVisionModality: supportImage ?? false,
      enableAudioModality: supportAudio ?? false,
      systemInstruction: systemInstruction,
      enableThinking: isThinking,
      tools: tools,
    ),
    maxTokens: maxTokens,
    tokenBuffer: tokenBuffer,
    supportImage: supportImage ?? false,
    supportAudio: supportAudio ?? false,
    supportsFunctionCalls: supportsFunctionCalls ?? false,
    maxFunctionBufferLength:
        maxFunctionBufferLength ?? defaultMaxFunctionBufferLength,
    tools: tools,
    isThinking: isThinking,
    modelType: modelType ?? ModelType.gemmaIt,
    fileType: fileType,
    toolChoice: toolChoice,
    systemInstruction: systemInstruction,
  );
  await independentChat.initSession();
  return independentChat;
}