cat-llm 0.0.28__tar.gz → 0.0.30__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cat-llm
3
- Version: 0.0.28
3
+ Version: 0.0.30
4
4
  Summary: A tool for categorizing text data and images using LLMs and vision models
5
5
  Project-URL: Documentation, https://github.com/chrissoria/cat-llm#readme
6
6
  Project-URL: Issues, https://github.com/chrissoria/cat-llm/issues
@@ -130,28 +130,79 @@ def cerad_drawn_score(
130
130
  reference_text = f"This image contains a perfect reference image of a {shape}. Next to is a drawing that is meant to be similar to the reference {shape}.\n\n"
131
131
  else:
132
132
  reference_text = f"Image is expected to show within it a drawing of a {shape}.\n\n"
133
-
134
- prompt = [
135
- {
136
- "type": "text",
137
- "text": (
138
- f"You are an image-tagging assistant trained in the CERAD Constructional Praxis test.\n"
139
- f"Task Examine the attached image and decide, **for each category below**, "
140
- f"whether it is PRESENT (1) or NOT PRESENT (0).\n\n"
141
- f"{reference_text}"
142
- f"Categories:\n{categories_str}\n\n"
143
- f"Output format ► Respond with **only** a JSON object whose keys are the "
144
- f"quoted category numbers ('1', '2', …) and whose values are 1 or 0. "
145
- f"No additional keys, comments, or text.\n\n"
146
- f"Example:\n"
147
- f"{example_JSON}"
148
- ),
149
- },
150
- {
151
- "type": "image_url",
152
- "image_url": {"url": encoded_image, "detail": "high"},
153
- },
154
- ]
133
+
134
+ if model_source == "OpenAI":
135
+ prompt = [
136
+ {
137
+ "type": "text",
138
+ "text": (
139
+ f"You are an image-tagging assistant trained in the CERAD Constructional Praxis test.\n"
140
+ f"Task Examine the attached image and decide, **for each category below**, "
141
+ f"whether it is PRESENT (1) or NOT PRESENT (0).\n\n"
142
+ f"{reference_text}"
143
+ f"Categories:\n{categories_str}\n\n"
144
+ f"Output format Respond with **only** a JSON object whose keys are the "
145
+ f"quoted category numbers ('1', '2', …) and whose values are 1 or 0. "
146
+ f"No additional keys, comments, or text.\n\n"
147
+ f"Example:\n"
148
+ f"{example_JSON}"
149
+ ),
150
+ },
151
+ {
152
+ "type": "image_url",
153
+ "image_url": {"url": encoded_image, "detail": "high"},
154
+ },
155
+ ]
156
+ elif model_source == "Anthropic":
157
+ prompt = [
158
+ {
159
+ "type": "text",
160
+ "text": (
161
+ f"You are an image-tagging assistant trained in the CERAD Constructional Praxis test.\n"
162
+ f"Task ► Examine the attached image and decide, **for each category below**, "
163
+ f"whether it is PRESENT (1) or NOT PRESENT (0).\n\n"
164
+ f"{reference_text}"
165
+ f"Categories:\n{categories_str}\n\n"
166
+ f"Output format ► Respond with **only** a JSON object whose keys are the "
167
+ f"quoted category numbers ('1', '2', …) and whose values are 1 or 0. "
168
+ f"No additional keys, comments, or text.\n\n"
169
+ f"Example:\n"
170
+ f"{example_JSON}"
171
+ ),
172
+ },
173
+ {
174
+ "type": "image",
175
+ "source": {
176
+ "type": "base64",
177
+ "media_type": "image/jpeg",
178
+ "data": encoded
179
+ }
180
+ },
181
+ ]
182
+
183
+ elif model_source == "Mistral":
184
+ prompt = [
185
+ {
186
+ "role": "system",
187
+ "content": (
188
+ f"You are an image-tagging assistant trained in the CERAD Constructional Praxis test.\n"
189
+ f"Task ► Examine the attached image and decide, **for each category below**, "
190
+ f"whether it is PRESENT (1) or NOT PRESENT (0).\n\n"
191
+ f"{reference_text}"
192
+ f"Categories:\n{categories_str}\n\n"
193
+ f"Output format ► Respond with **only** a JSON object whose keys are the "
194
+ f"quoted category numbers ('1', '2', …) and whose values are 1 or 0. "
195
+ f"No additional keys, comments, or text.\n\n"
196
+ f"Example:\n"
197
+ f"{example_JSON}"
198
+ ),
199
+ },
200
+ {
201
+ "type": "image_url",
202
+ "image_url": f"data:image/jpeg;base64,{base64_image}"
203
+ }
204
+ ]
205
+
155
206
  if model_source == "OpenAI":
156
207
  from openai import OpenAI
157
208
  client = OpenAI(api_key=api_key)
@@ -167,20 +218,6 @@ def cerad_drawn_score(
167
218
  print(f"An error occurred: {e}")
168
219
  link1.append(f"Error processing input: {e}")
169
220
 
170
- elif model_source == "Perplexity":
171
- from openai import OpenAI
172
- client = OpenAI(api_key=api_key, base_url="https://api.perplexity.ai")
173
- try:
174
- response_obj = client.chat.completions.create(
175
- model=user_model,
176
- messages=[{'role': 'user', 'content': prompt}],
177
- temperature=creativity
178
- )
179
- reply = response_obj.choices[0].message.content
180
- link1.append(reply)
181
- except Exception as e:
182
- print(f"An error occurred: {e}")
183
- link1.append(f"Error processing input: {e}")
184
221
  elif model_source == "Anthropic":
185
222
  import anthropic
186
223
  client = anthropic.Anthropic(api_key=api_key)
@@ -196,6 +233,7 @@ def cerad_drawn_score(
196
233
  except Exception as e:
197
234
  print(f"An error occurred: {e}")
198
235
  link1.append(f"Error processing input: {e}")
236
+
199
237
  elif model_source == "Mistral":
200
238
  from mistralai import Mistral
201
239
  client = Mistral(api_key=api_key)
@@ -213,7 +251,7 @@ def cerad_drawn_score(
213
251
  print(f"An error occurred: {e}")
214
252
  link1.append(f"Error processing input: {e}")
215
253
  else:
216
- raise ValueError("Unknown source! Choose from OpenAI, Anthropic, Perplexity, or Mistral")
254
+ raise ValueError("Unknown source! Choose from OpenAI, Perplexity, or Mistral")
217
255
  # in situation that no JSON is found
218
256
  if reply is not None:
219
257
  extracted_json = regex.findall(r'\{(?:[^{}]|(?R))*\}', reply, regex.DOTALL)
@@ -1,7 +1,7 @@
1
1
  # SPDX-FileCopyrightText: 2025-present Christopher Soria <chrissoria@berkeley.edu>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.0.28"
4
+ __version__ = "0.0.30"
5
5
  __author__ = "Chris Soria"
6
6
  __email__ = "chrissoria@berkeley.edu"
7
7
  __title__ = "cat-llm"
@@ -219,7 +219,7 @@ Return the top {top_n} categories as a numbered list sorted from the most to lea
219
219
  return top_categories_final
220
220
 
221
221
  #multi-class text classification
222
- def extract_multi_class(
222
+ def multi_class(
223
223
  survey_question,
224
224
  survey_input,
225
225
  categories,
@@ -391,5 +391,4 @@ Provide your work in JSON format where the number belonging to each category is
391
391
  save_directory = os.getcwd()
392
392
  categorized_data.to_csv(os.path.join(save_directory, filename), index=False)
393
393
 
394
- return categorized_data
395
-
394
+ return categorized_data
File without changes
File without changes
File without changes