GenerativeModel constructor

GenerativeModel({
  1. required String model,
  2. required String apiKey,
  3. List<SafetySetting> safetySettings = const [],
  4. GenerationConfig? generationConfig,
  5. List<Tool>? tools,
  6. Client? httpClient,
  7. RequestOptions? requestOptions,
  8. Content? systemInstruction,
  9. ToolConfig? toolConfig,
})

Create a GenerativeModel backed by the generative model named model.

The model argument can be a model name (such as 'gemini-1.5-flash-latest') or a model code (such as 'models/gemini-1.5-flash-latest' or 'tunedModels/my-model'). There is no creation time check for whether the model string identifies a known and supported model. If not, attempts to generate content will fail.

A Google Cloud apiKey is required for all requests. See documentation about API keys for more information.

The optional safetySettings and generationConfig can be used to control and guide the generation. See SafetySetting and GenerationConfig for details.

Content creation requests are sent to a server through the httpClient, which can be used to control, for example, the number of allowed concurrent requests. If the httpClient is omitted, a new http.Client is created for each request.

Functions that the model may call while generating content can be passed in tools. Tool usage by the model can be configured with toolConfig. Tools and tool configuration can be overridden for individual requests with arguments to generateContent or generateContentStream.

A Content.system can be passed to systemInstruction to give high priority instructions to the model.

Implementation

factory GenerativeModel({
  required String model,
  required String apiKey,
  List<SafetySetting> safetySettings = const [],
  GenerationConfig? generationConfig,
  List<Tool>? tools,
  http.Client? httpClient,
  RequestOptions? requestOptions,
  Content? systemInstruction,
  ToolConfig? toolConfig,
}) =>
    GenerativeModel._withClient(
      client: HttpApiClient(apiKey: apiKey, httpClient: httpClient),
      model: model,
      safetySettings: safetySettings,
      generationConfig: generationConfig,
      baseUri: _googleAIBaseUri(requestOptions),
      tools: tools,
      systemInstruction: systemInstruction,
      toolConfig: toolConfig,
    );