Fix Gemini and Mistral provider imports
Switch Gemini from deprecated google-generativeai to google-genai. Fix Mistral import path to mistralai.client.Mistral (v2.x layout). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+13
-12
@@ -51,23 +51,24 @@ class GeminiProvider(Provider):
|
||||
name = "Gemini"
|
||||
|
||||
def __init__(self):
|
||||
import google.generativeai as genai
|
||||
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
|
||||
self._genai = genai
|
||||
from google import genai
|
||||
from google.genai import types as genai_types
|
||||
self._client = genai.Client(api_key=os.environ["GOOGLE_API_KEY"])
|
||||
self._types = genai_types
|
||||
|
||||
def chat(self, messages: list[dict], system: str, max_tokens: int = 4096) -> str:
|
||||
model = self._genai.GenerativeModel(
|
||||
model_name="gemini-2.0-flash",
|
||||
system_instruction=system,
|
||||
)
|
||||
# Convert role "assistant" → "model" for Gemini
|
||||
contents = [
|
||||
{"role": "model" if m["role"] == "assistant" else "user", "parts": [m["content"]]}
|
||||
{"role": "model" if m["role"] == "assistant" else "user", "parts": [{"text": m["content"]}]}
|
||||
for m in messages
|
||||
]
|
||||
response = model.generate_content(
|
||||
contents,
|
||||
generation_config=self._genai.types.GenerationConfig(max_output_tokens=max_tokens),
|
||||
response = self._client.models.generate_content(
|
||||
model="gemini-2.0-flash",
|
||||
contents=contents,
|
||||
config=self._types.GenerateContentConfig(
|
||||
system_instruction=system,
|
||||
max_output_tokens=max_tokens,
|
||||
),
|
||||
)
|
||||
return response.text
|
||||
|
||||
@@ -76,7 +77,7 @@ class MistralProvider(Provider):
|
||||
name = "Mistral"
|
||||
|
||||
def __init__(self):
|
||||
from mistralai import Mistral
|
||||
from mistralai.client import Mistral
|
||||
self._client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
|
||||
|
||||
def chat(self, messages: list[dict], system: str, max_tokens: int = 4096) -> str:
|
||||
|
||||
Reference in New Issue
Block a user