{"version":3,"sources":["../../../src/modelgarden/legacy/mistral.ts"],"sourcesContent":["/**\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { MistralGoogleCloud } from '@mistralai/mistralai-gcp';\nimport {\n  ChatCompletionChoiceFinishReason,\n  ToolTypes,\n  type AssistantMessage,\n  type ChatCompletionRequest,\n  type ChatCompletionResponse,\n  type CompletionChunk,\n  type FunctionCall,\n  type Tool as MistralTool,\n  type SystemMessage,\n  type ToolCall,\n  type ToolMessage,\n  type UserMessage,\n} from '@mistralai/mistralai-gcp/models/components';\nimport {\n  GenerationCommonConfigSchema,\n  z,\n  type GenerateRequest,\n  type Genkit,\n  type MessageData,\n  type ModelReference,\n  type ModelResponseData,\n  type Part,\n  type Role,\n  type ToolRequestPart,\n} from 'genkit';\nimport {\n  GenerationCommonConfigDescriptions,\n  modelRef,\n  type ModelAction,\n} from 'genkit/model';\nimport { getGenkitClientHeader } from '../../common/index.js';\n\n/**\n * See https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post\n * @deprecated\n */\nexport const MistralConfigSchema = GenerationCommonConfigSchema.extend({\n  // TODO: Update this with all the parameters in\n  // https://docs.mistral.ai/api/#tag/chat/operation/chat_completion_v1_chat_completions_post.\n  location: z.string().optional(),\n  topP: z\n    .number()\n    .describe(\n      GenerationCommonConfigDescriptions.topP + ' The default value is 1.'\n    )\n    .optional(),\n});\n\n/**\n * @deprecated\n */\nexport const mistralLarge = modelRef({\n  name: 'vertexai/mistral-large',\n  info: {\n    label: 'Vertex AI Model Garden - Mistral Large',\n    versions: ['mistral-large-2411', 'mistral-large-2407'],\n    supports: {\n      multiturn: true,\n      media: false,\n      tools: true,\n      systemRole: true,\n      output: ['text'],\n    },\n  },\n  configSchema: MistralConfigSchema,\n});\n\n/**\n * @deprecated\n */\nexport const mistralNemo = modelRef({\n  name: 'vertexai/mistral-nemo',\n  info: {\n    label: 'Vertex AI Model Garden - Mistral Nemo',\n    versions: ['mistral-nemo-2407'],\n    supports: {\n      multiturn: true,\n      media: false,\n      tools: false,\n      systemRole: true,\n      output: ['text'],\n    },\n  },\n  configSchema: MistralConfigSchema,\n});\n\n/**\n * @deprecated\n */\nexport const codestral = modelRef({\n  name: 'vertexai/codestral',\n  info: {\n    label: 'Vertex AI Model Garden - Codestral',\n    versions: ['codestral-2405'],\n    supports: {\n      multiturn: true,\n      media: false,\n      tools: false,\n      systemRole: true,\n      output: ['text'],\n    },\n  },\n  configSchema: MistralConfigSchema,\n});\n\n/**\n * @deprecated\n */\nexport const SUPPORTED_MISTRAL_MODELS: Record<\n  string,\n  ModelReference<typeof MistralConfigSchema>\n> = {\n  'mistral-large': mistralLarge,\n  'mistral-nemo': mistralNemo,\n  codestral: codestral,\n};\n\n// TODO: Do they export a type for this?\ntype MistralRole = 'assistant' | 'user' | 'tool' | 'system';\n\nfunction toMistralRole(role: Role): MistralRole {\n  switch (role) {\n    case 'model':\n      return 'assistant';\n    case 'user':\n      return 'user';\n    case 'tool':\n      return 'tool';\n    case 'system':\n      return 'system';\n    default:\n      throw new Error(`Unknwon role ${role}`);\n  }\n}\nfunction toMistralToolRequest(toolRequest: Record<string, any>): FunctionCall {\n  if (!toolRequest.name) {\n    throw new Error('Tool name is required');\n  }\n\n  return {\n    name: toolRequest.name,\n    // Mistral expects arguments as either a string or object\n    arguments:\n      typeof toolRequest.input === 'string'\n        ? toolRequest.input\n        : JSON.stringify(toolRequest.input),\n  };\n}\n\n/**\n * @deprecated\n */\nexport function toMistralRequest(\n  model: string,\n  input: GenerateRequest<typeof MistralConfigSchema>\n): ChatCompletionRequest {\n  const messages = input.messages.map((msg) => {\n    // Handle regular text messages\n    if (msg.content.every((part) => part.text)) {\n      const content = msg.content.map((part) => part.text || '').join('');\n      return {\n        role: toMistralRole(msg.role),\n        content,\n      };\n    }\n\n    // Handle assistant's tool/function calls\n    const toolRequest = msg.content.find((part) => part.toolRequest);\n    if (toolRequest?.toolRequest) {\n      const functionCall = toMistralToolRequest(toolRequest.toolRequest);\n      return {\n        role: 'assistant' as const,\n        content: null,\n        toolCalls: [\n          {\n            id: toolRequest.toolRequest.ref,\n            type: ToolTypes.Function,\n            function: {\n              name: functionCall.name,\n              arguments: functionCall.arguments,\n            },\n          },\n        ],\n      };\n    }\n\n    // Handle tool responses\n    const toolResponse = msg.content.find((part) => part.toolResponse);\n    if (toolResponse?.toolResponse) {\n      return {\n        role: 'tool' as const,\n        name: toolResponse.toolResponse.name,\n        content: JSON.stringify(toolResponse.toolResponse.output),\n        toolCallId: toolResponse.toolResponse.ref, // This must match the id from tool_calls\n      };\n    }\n\n    return {\n      role: toMistralRole(msg.role),\n      content: msg.content.map((part) => part.text || '').join(''),\n    };\n  });\n\n  validateToolSequence(messages); // This line exists but might not be running?\n\n  const request: ChatCompletionRequest = {\n    model,\n    messages,\n    maxTokens: input.config?.maxOutputTokens ?? 1024,\n    temperature: input.config?.temperature ?? 0.7,\n    ...(input.config?.topP && { topP: input.config.topP }),\n    ...(input.config?.stopSequences && { stop: input.config.stopSequences }),\n    ...(input.tools && {\n      tools: input.tools.map((tool) => ({\n        type: 'function',\n        function: {\n          name: tool.name,\n          description: tool.description,\n          parameters: tool.inputSchema || {},\n        },\n      })) as MistralTool[],\n    }),\n  };\n\n  return request;\n}\n// Helper to convert Mistral AssistantMessage content into Genkit parts\nfunction fromMistralTextPart(content: string): Part {\n  return {\n    text: content,\n  };\n}\n\n// Helper to convert Mistral ToolCall into Genkit parts\nfunction fromMistralToolCall(toolCall: ToolCall): ToolRequestPart {\n  if (!toolCall.function) {\n    throw new Error('Tool call must include a function definition');\n  }\n\n  return {\n    toolRequest: {\n      ref: toolCall.id,\n      name: toolCall.function.name,\n      input:\n        typeof toolCall.function.arguments === 'string'\n          ? JSON.parse(toolCall.function.arguments)\n          : toolCall.function.arguments,\n    },\n  };\n}\n\n// Converts Mistral AssistantMessage content into Genkit parts\nfunction fromMistralMessage(message: AssistantMessage): Part[] {\n  const parts: Part[] = [];\n\n  // Handle textual content\n  if (typeof message.content === 'string') {\n    parts.push(fromMistralTextPart(message.content));\n  } else if (Array.isArray(message.content)) {\n    // If content is an array of ContentChunk, handle each chunk\n    message.content.forEach((chunk) => {\n      if (chunk.type === 'text') {\n        parts.push(fromMistralTextPart(chunk.text));\n      }\n      // Add support for other ContentChunk types here if needed\n    });\n  }\n\n  // Handle tool calls if present\n  if (message.toolCalls) {\n    message.toolCalls.forEach((toolCall) => {\n      parts.push(fromMistralToolCall(toolCall));\n    });\n  }\n\n  return parts;\n}\n\n/**\n * Maps Mistral finish reasons to Genkit finish reasons\n * @deprecated\n */\nexport function fromMistralFinishReason(\n  reason: ChatCompletionChoiceFinishReason | undefined\n): 'length' | 'unknown' | 'stop' | 'blocked' | 'other' {\n  switch (reason) {\n    case ChatCompletionChoiceFinishReason.Stop:\n      return 'stop';\n    case ChatCompletionChoiceFinishReason.Length:\n    case ChatCompletionChoiceFinishReason.ModelLength:\n      return 'length';\n    case ChatCompletionChoiceFinishReason.Error:\n      return 'other'; // Map generic errors to \"other\"\n    case ChatCompletionChoiceFinishReason.ToolCalls:\n      return 'stop'; // Assuming tool calls signify a \"stop\" in processing\n    default:\n      return 'other'; // For undefined or unmapped reasons\n  }\n}\n\n/**\n * Converts a Mistral response to a Genkit response\n * @deprecated\n */\nexport function fromMistralResponse(\n  _input: GenerateRequest<typeof MistralConfigSchema>,\n  response: ChatCompletionResponse\n): ModelResponseData {\n  const firstChoice = response.choices?.[0];\n  // Convert content from Mistral response to Genkit parts\n  const contentParts: Part[] = firstChoice?.message\n    ? fromMistralMessage(firstChoice.message)\n    : [];\n\n  const message: MessageData = {\n    role: 'model',\n    content: contentParts,\n  };\n\n  return {\n    message,\n    finishReason: fromMistralFinishReason(firstChoice?.finishReason),\n    usage: {\n      inputTokens: response.usage.promptTokens,\n      outputTokens: response.usage.completionTokens,\n    },\n    custom: {\n      id: response.id,\n      model: response.model,\n      created: response.created,\n    },\n    raw: response, // Include the raw response for debugging or additional context\n  };\n}\n\n/** @deprecated */\nexport function mistralModel(\n  ai: Genkit,\n  modelName: string,\n  projectId: string,\n  region: string\n): ModelAction {\n  const getClient = createClientFactory(projectId);\n\n  const model = SUPPORTED_MISTRAL_MODELS[modelName];\n  if (!model) {\n    throw new Error(`Unsupported Mistral model name ${modelName}`);\n  }\n\n  return ai.defineModel(\n    {\n      name: model.name,\n      label: model.info?.label,\n      configSchema: MistralConfigSchema,\n      supports: model.info?.supports,\n      versions: model.info?.versions,\n    },\n    async (input, sendChunk) => {\n      const client = getClient(input.config?.location || region);\n\n      const versionedModel =\n        input.config?.version ?? model.info?.versions?.[0] ?? model.name;\n\n      if (!sendChunk) {\n        const mistralRequest = toMistralRequest(versionedModel, input);\n\n        const response = await client.chat.complete(mistralRequest, {\n          fetchOptions: {\n            headers: {\n              'X-Goog-Api-Client': getGenkitClientHeader(),\n            },\n          },\n        });\n\n        return fromMistralResponse(input, response);\n      } else {\n        const mistralRequest = toMistralRequest(versionedModel, input);\n        const stream = await client.chat.stream(mistralRequest, {\n          fetchOptions: {\n            headers: {\n              'X-Goog-Api-Client': getGenkitClientHeader(),\n            },\n          },\n        });\n\n        for await (const event of stream) {\n          const parts = fromMistralCompletionChunk(event.data);\n          if (parts.length > 0) {\n            sendChunk({\n              content: parts,\n            });\n          }\n        }\n\n        // Get the complete response after streaming\n        const completeResponse = await client.chat.complete(mistralRequest, {\n          fetchOptions: {\n            headers: {\n              'X-Goog-Api-Client': getGenkitClientHeader(),\n            },\n          },\n        });\n\n        return fromMistralResponse(input, completeResponse);\n      }\n    }\n  );\n}\n\nfunction createClientFactory(projectId: string) {\n  const clients: Record<string, MistralGoogleCloud> = {};\n\n  return (region: string): MistralGoogleCloud => {\n    if (!region) {\n      throw new Error('Region is required to create Mistral client');\n    }\n\n    try {\n      if (!clients[region]) {\n        clients[region] = new MistralGoogleCloud({\n          region,\n          projectId,\n        });\n      }\n      return clients[region];\n    } catch (error) {\n      throw new Error(\n        `Failed to create/retrieve Mistral client for region ${region}: ${error}`\n      );\n    }\n  };\n}\n\ntype MistralMessage =\n  | AssistantMessage\n  | ToolMessage\n  | SystemMessage\n  | UserMessage;\n\n// Helper function to validate tool calls and responses match\nfunction validateToolSequence(messages: MistralMessage[]) {\n  const toolCalls = (\n    messages.filter((m) => {\n      return m.role === 'assistant' && m.toolCalls;\n    }) as AssistantMessage[]\n  ).reduce((acc: ToolCall[], m) => {\n    if (m.toolCalls) {\n      return [...acc, ...m.toolCalls];\n    }\n    return acc;\n  }, []);\n\n  const toolResponses = messages.filter(\n    (m) => m.role === 'tool'\n  ) as ToolMessage[];\n\n  if (toolCalls.length !== toolResponses.length) {\n    throw new Error(\n      `Mismatch between tool calls (${toolCalls.length}) and responses (${toolResponses.length})`\n    );\n  }\n\n  toolResponses.forEach((response) => {\n    const matchingCall = toolCalls.find(\n      (call) => call.id === response.toolCallId\n    );\n    if (!matchingCall) {\n      throw new Error(\n        `Tool response with ID ${response.toolCallId} has no matching call`\n      );\n    }\n  });\n}\n\n/** @deprecated */\nexport function fromMistralCompletionChunk(chunk: CompletionChunk): Part[] {\n  if (!chunk.choices?.[0]?.delta) return [];\n\n  const delta = chunk.choices[0].delta;\n  const parts: Part[] = [];\n\n  if (typeof delta.content === 'string') {\n    parts.push({ text: delta.content });\n  }\n\n  if (delta.toolCalls) {\n    delta.toolCalls.forEach((toolCall) => {\n      if (!toolCall.function) return;\n\n      parts.push({\n        toolRequest: {\n          ref: toolCall.id,\n          name: toolCall.function.name,\n          input:\n            typeof toolCall.function.arguments === 'string'\n              ? JSON.parse(toolCall.function.arguments)\n              : toolCall.function.arguments,\n        },\n      });\n    });\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