Spaces:
Running
Running
phyloforfun
commited on
Commit
•
64ffaff
1
Parent(s):
39c6a41
Major update. Support for 15 LLMs, World Flora Online taxonomy validation, geolocation, 2 OCR methods, significant UI changes, stability improvements, consistent JSON parsing
Browse files- vouchervision/API_validation.py +21 -20
vouchervision/API_validation.py
CHANGED
@@ -120,28 +120,29 @@ class APIvalidation:
|
|
120 |
return False
|
121 |
|
122 |
def check_mistral_api_key(self):
|
123 |
-
if self.cfg_private:
|
124 |
-
client = MistralClient(api_key=self.cfg_private['mistral']['mistral_key'])
|
125 |
-
else:
|
126 |
-
client = MistralClient(api_key=os.getenv('MISTRAL_API_KEY'))
|
127 |
-
|
128 |
try:
|
129 |
-
|
|
|
|
|
|
|
130 |
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
model="mistral-tiny",
|
137 |
-
messages=messages,
|
138 |
-
)
|
139 |
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
except Exception as e: # Replace with a more specific exception if possible
|
146 |
return False
|
147 |
|
@@ -182,7 +183,7 @@ class APIvalidation:
|
|
182 |
else:
|
183 |
try:
|
184 |
# Assuming genai and vertexai are clients for Google services
|
185 |
-
os.environ["GOOGLE_API_KEY"] = os.getenv('PALM_API_KEY')
|
186 |
# genai.configure(api_key=self.cfg_private['google_palm']['google_palm_api'])
|
187 |
vertexai.init(project= os.getenv('GOOGLE_PROJECT_ID'), location=os.getenv('GOOGLE_LOCATION'))
|
188 |
|
@@ -307,5 +308,5 @@ class APIvalidation:
|
|
307 |
report += "Present Keys: " + ", ".join(present_keys) + "\n"
|
308 |
report += "Missing Keys: " + ", ".join(missing_keys) + "\n"
|
309 |
|
310 |
-
|
311 |
return present_keys, missing_keys, self.formatted_date
|
|
|
120 |
return False
|
121 |
|
122 |
def check_mistral_api_key(self):
|
|
|
|
|
|
|
|
|
|
|
123 |
try:
|
124 |
+
if self.cfg_private:
|
125 |
+
client = MistralClient(api_key=self.cfg_private['mistral']['mistral_key'])
|
126 |
+
else:
|
127 |
+
client = MistralClient(api_key=os.getenv('MISTRAL_API_KEY'))
|
128 |
|
129 |
+
|
130 |
+
# Initialize the Mistral Client with the API key
|
131 |
|
132 |
+
# Create a simple message
|
133 |
+
messages = [ChatMessage(role="user", content="hello")]
|
|
|
|
|
|
|
134 |
|
135 |
+
# Send the message and get the response
|
136 |
+
chat_response = client.chat(
|
137 |
+
model="mistral-tiny",
|
138 |
+
messages=messages,
|
139 |
+
)
|
140 |
+
|
141 |
+
# Check if the response is valid (adjust this according to the actual response structure)
|
142 |
+
if chat_response and chat_response.choices:
|
143 |
+
return True
|
144 |
+
else:
|
145 |
+
return False
|
146 |
except Exception as e: # Replace with a more specific exception if possible
|
147 |
return False
|
148 |
|
|
|
183 |
else:
|
184 |
try:
|
185 |
# Assuming genai and vertexai are clients for Google services
|
186 |
+
# os.environ["GOOGLE_API_KEY"] = os.getenv('PALM_API_KEY')
|
187 |
# genai.configure(api_key=self.cfg_private['google_palm']['google_palm_api'])
|
188 |
vertexai.init(project= os.getenv('GOOGLE_PROJECT_ID'), location=os.getenv('GOOGLE_LOCATION'))
|
189 |
|
|
|
308 |
report += "Present Keys: " + ", ".join(present_keys) + "\n"
|
309 |
report += "Missing Keys: " + ", ".join(missing_keys) + "\n"
|
310 |
|
311 |
+
print(report)
|
312 |
return present_keys, missing_keys, self.formatted_date
|