cat-llm 0.0.67__py3-none-any.whl → 0.0.69__py3-none-any.whl

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.
@@ -0,0 +1,433 @@
1
+ # openai stepback prompt
2
+
3
+ def get_stepback_insight_openai(
4
+ stepback,
5
+ api_key,
6
+ user_model,
7
+ model_source="openai",
8
+ creativity=None
9
+ ):
10
+ from openai import OpenAI
11
+ # Conditional base_url setting based on model source
12
+ base_url = (
13
+ "https://api.perplexity.ai" if model_source == "perplexity"
14
+ else "https://router.huggingface.co/v1" if model_source == "huggingface"
15
+ else None
16
+ )
17
+
18
+ client = OpenAI(api_key=api_key, base_url=base_url)
19
+
20
+ try:
21
+ stepback_response = client.chat.completions.create(
22
+ model=user_model,
23
+ messages=[{'role': 'user', 'content': stepback}],
24
+ **({"temperature": creativity} if creativity is not None else {})
25
+ )
26
+ stepback_insight = stepback_response.choices[0].message.content
27
+
28
+ return stepback_insight, True
29
+
30
+ except Exception as e:
31
+ print(f"An error occurred during step-back prompting: {e}")
32
+ return None, False
33
+
34
+
35
+ # claude stepback prompt
36
+
37
+ def get_stepback_insight_anthropic(
38
+ stepback,
39
+ api_key,
40
+ user_model,
41
+ model_source="anthropic",
42
+ creativity=None
43
+ ):
44
+ import anthropic
45
+
46
+ client = anthropic.Anthropic(api_key=api_key)
47
+
48
+ try:
49
+ stepback_response = client.messages.create(
50
+ model=user_model,
51
+ max_tokens=4096,
52
+ messages=[{'role': 'user', 'content': stepback}],
53
+ **({"temperature": creativity} if creativity is not None else {})
54
+ )
55
+ stepback_insight = stepback_response.content[0].text
56
+
57
+ return stepback_insight, True
58
+
59
+ except Exception as e:
60
+ print(f"An error occurred during step-back prompting: {e}")
61
+ return None, False
62
+
63
+ # google stepback prompt
64
+
65
+ def get_stepback_insight_google(
66
+ stepback,
67
+ api_key,
68
+ user_model,
69
+ model_source="google",
70
+ creativity=None
71
+ ):
72
+
73
+ import requests
74
+
75
+ url = f"https://generativelanguage.googleapis.com/v1beta/models/{user_model}:generateContent?key={api_key}"
76
+
77
+ headers = {
78
+ "Content-Type": "application/json"
79
+ }
80
+
81
+ payload = {
82
+ "contents": [{
83
+ "parts": [{"text": stepback}],
84
+
85
+ **({"generationConfig": {"temperature": creativity}} if creativity is not None else {})
86
+ }]
87
+ }
88
+
89
+ try:
90
+ response = requests.post(url, headers=headers, json=payload)
91
+ response.raise_for_status() # Raise error for bad status codes
92
+
93
+ result = response.json()
94
+ stepback_insight = result['candidates'][0]['content']['parts'][0]['text']
95
+
96
+ return stepback_insight, True
97
+
98
+ except Exception as e:
99
+ print(f"An error occurred during step-back prompting: {e}")
100
+ return None, False
101
+
102
+ # mistral stepback prompt
103
+
104
+ def get_stepback_insight_mistral(
105
+ stepback,
106
+ api_key,
107
+ user_model,
108
+ model_source="mistral",
109
+ creativity=None
110
+ ):
111
+
112
+ from mistralai import Mistral
113
+
114
+ client = Mistral(api_key=api_key)
115
+
116
+ try:
117
+ stepback_response = client.chat.complete(
118
+ model=user_model,
119
+ messages=[{'role': 'user', 'content': stepback}],
120
+ **({"temperature": creativity} if creativity is not None else {})
121
+ )
122
+ stepback_insight = stepback_response.choices[0].message.content
123
+
124
+ return stepback_insight, True
125
+
126
+ except Exception as e:
127
+ print(f"An error occurred during step-back prompting: {e}")
128
+ return None, False
129
+
130
+ # openai chain of verification calls
131
+
132
+ def chain_of_verification_openai(
133
+ initial_reply,
134
+ step2_prompt,
135
+ step3_prompt,
136
+ step4_prompt,
137
+ client,
138
+ user_model,
139
+ creativity,
140
+ remove_numbering
141
+ ):
142
+ """
143
+ Execute Chain of Verification (CoVe) process.
144
+ Returns the verified reply or initial reply if error occurs.
145
+ """
146
+ try:
147
+ # STEP 2: Generate verification questions
148
+ step2_filled = step2_prompt.replace('<<INITIAL_REPLY>>', initial_reply)
149
+
150
+ verification_response = client.chat.completions.create(
151
+ model=user_model,
152
+ messages=[{'role': 'user', 'content': step2_filled}],
153
+ **({"temperature": creativity} if creativity is not None else {})
154
+ )
155
+
156
+ verification_questions = verification_response.choices[0].message.content
157
+
158
+ # STEP 3: Answer verification questions
159
+ questions_list = [
160
+ remove_numbering(q)
161
+ for q in verification_questions.split('\n')
162
+ if q.strip()
163
+ ]
164
+ verification_qa = []
165
+
166
+ # Prompting each question individually
167
+ for question in questions_list:
168
+ step3_filled = step3_prompt.replace('<<QUESTION>>', question)
169
+
170
+ answer_response = client.chat.completions.create(
171
+ model=user_model,
172
+ messages=[{'role': 'user', 'content': step3_filled}],
173
+ **({"temperature": creativity} if creativity is not None else {})
174
+ )
175
+
176
+ answer = answer_response.choices[0].message.content
177
+ verification_qa.append(f"Q: {question}\nA: {answer}")
178
+
179
+ # STEP 4: Final corrected categorization
180
+ verification_qa_text = "\n\n".join(verification_qa)
181
+
182
+ step4_filled = (step4_prompt
183
+ .replace('<<INITIAL_REPLY>>', initial_reply)
184
+ .replace('<<VERIFICATION_QA>>', verification_qa_text))
185
+
186
+ print(f"Final prompt:\n{step4_filled}\n")
187
+
188
+ final_response = client.chat.completions.create(
189
+ model=user_model,
190
+ messages=[{'role': 'user', 'content': step4_filled}],
191
+ **({"temperature": creativity} if creativity is not None else {})
192
+ )
193
+
194
+ verified_reply = final_response.choices[0].message.content
195
+ print("Chain of verification completed. Final response generated.\n")
196
+
197
+ return verified_reply
198
+
199
+ except Exception as e:
200
+ print(f"ERROR in Chain of Verification: {str(e)}")
201
+ print("Falling back to initial response.\n")
202
+ return initial_reply
203
+
204
+ # anthropic chain of verification calls
205
+
206
+ def chain_of_verification_anthropic(
207
+ initial_reply,
208
+ step2_prompt,
209
+ step3_prompt,
210
+ step4_prompt,
211
+ client,
212
+ user_model,
213
+ creativity,
214
+ remove_numbering
215
+ ):
216
+ """
217
+ Execute Chain of Verification (CoVe) process for Anthropic Claude.
218
+ Returns the verified reply or initial reply if error occurs.
219
+ """
220
+ try:
221
+ # STEP 2: Generate verification questions
222
+ step2_filled = step2_prompt.replace('<<INITIAL_REPLY>>', initial_reply)
223
+
224
+ verification_response = client.messages.create(
225
+ model=user_model,
226
+ messages=[{'role': 'user', 'content': step2_filled}],
227
+ max_tokens=4096,
228
+ **({"temperature": creativity} if creativity is not None else {})
229
+ )
230
+
231
+ verification_questions = verification_response.content[0].text
232
+
233
+ # STEP 3: Answer verification questions
234
+ questions_list = [
235
+ remove_numbering(q)
236
+ for q in verification_questions.split('\n')
237
+ if q.strip()
238
+ ]
239
+ print(f"Verification questions:\n{questions_list}\n")
240
+ verification_qa = []
241
+
242
+ # Prompting each question individually
243
+ for question in questions_list:
244
+ step3_filled = step3_prompt.replace('<<QUESTION>>', question)
245
+
246
+ answer_response = client.messages.create(
247
+ model=user_model,
248
+ messages=[{'role': 'user', 'content': step3_filled}],
249
+ max_tokens=4096,
250
+ **({"temperature": creativity} if creativity is not None else {})
251
+ )
252
+
253
+ answer = answer_response.content[0].text
254
+ verification_qa.append(f"Q: {question}\nA: {answer}")
255
+
256
+ # STEP 4: Final corrected categorization
257
+ verification_qa_text = "\n\n".join(verification_qa)
258
+
259
+ step4_filled = (step4_prompt
260
+ .replace('<<INITIAL_REPLY>>', initial_reply)
261
+ .replace('<<VERIFICATION_QA>>', verification_qa_text))
262
+
263
+ print(f"Final prompt:\n{step4_filled}\n")
264
+
265
+ final_response = client.messages.create(
266
+ model=user_model,
267
+ messages=[{'role': 'user', 'content': step4_filled}],
268
+ max_tokens=4096,
269
+ **({"temperature": creativity} if creativity is not None else {})
270
+ )
271
+
272
+ verified_reply = final_response.content[0].text
273
+ print("Chain of verification completed. Final response generated.\n")
274
+
275
+ return verified_reply
276
+
277
+ except Exception as e:
278
+ print(f"ERROR in Chain of Verification: {str(e)}")
279
+ print("Falling back to initial response.\n")
280
+ return initial_reply
281
+
282
+ # google chain of verification calls
283
+ def chain_of_verification_google(
284
+ initial_reply,
285
+ prompt,
286
+ step2_prompt,
287
+ step3_prompt,
288
+ step4_prompt,
289
+ url,
290
+ headers,
291
+ creativity,
292
+ remove_numbering,
293
+ make_google_request
294
+ ):
295
+ import time
296
+ """
297
+ Execute Chain of Verification (CoVe) process for Google Gemini.
298
+ Returns the verified reply or initial reply if error occurs.
299
+ """
300
+ try:
301
+ # STEP 2: Generate verification questions
302
+ step2_filled = step2_prompt.replace('<<INITIAL_REPLY>>', initial_reply)
303
+
304
+ payload_step2 = {
305
+ "contents": [{
306
+ "parts": [{"text": step2_filled}]
307
+ }],
308
+ **({"generationConfig": {"temperature": creativity}} if creativity is not None else {})
309
+ }
310
+
311
+ result_step2 = make_google_request(url, headers, payload_step2)
312
+ verification_questions = result_step2["candidates"][0]["content"]["parts"][0]["text"]
313
+
314
+ # STEP 3: Answer verification questions
315
+ questions_list = [
316
+ remove_numbering(q)
317
+ for q in verification_questions.split('\n')
318
+ if q.strip()
319
+ ]
320
+ verification_qa = []
321
+
322
+ for question in questions_list:
323
+ time.sleep(2) # temporary rate limit handling
324
+ step3_filled = step3_prompt.replace('<<QUESTION>>', question)
325
+
326
+ payload_step3 = {
327
+ "contents": [{
328
+ "parts": [{"text": step3_filled}]
329
+ }],
330
+ **({"generationConfig": {"temperature": creativity}} if creativity is not None else {})
331
+ }
332
+
333
+ result_step3 = make_google_request(url, headers, payload_step3)
334
+ answer = result_step3["candidates"][0]["content"]["parts"][0]["text"]
335
+ verification_qa.append(f"Q: {question}\nA: {answer}")
336
+
337
+ # STEP 4: Final corrected categorization
338
+ verification_qa_text = "\n\n".join(verification_qa)
339
+
340
+ step4_filled = (step4_prompt
341
+ .replace('<<PROMPT>>', prompt)
342
+ .replace('<<INITIAL_REPLY>>', initial_reply)
343
+ .replace('<<VERIFICATION_QA>>', verification_qa_text))
344
+
345
+ payload_step4 = {
346
+ "contents": [{
347
+ "parts": [{"text": step4_filled}]
348
+ }],
349
+ **({"generationConfig": {"temperature": creativity}} if creativity is not None else {})
350
+ }
351
+
352
+ result_step4 = make_google_request(url, headers, payload_step4)
353
+ verified_reply = result_step4["candidates"][0]["content"]["parts"][0]["text"]
354
+
355
+ print("Chain of verification completed. Final response generated.\n")
356
+ return verified_reply
357
+
358
+ except Exception as e:
359
+ print(f"ERROR in Chain of Verification: {str(e)}")
360
+ print("Falling back to initial response.\n")
361
+ return initial_reply
362
+
363
+ # mistral chain of verification calls
364
+
365
+ def chain_of_verification_mistral(
366
+ initial_reply,
367
+ step2_prompt,
368
+ step3_prompt,
369
+ step4_prompt,
370
+ client,
371
+ user_model,
372
+ creativity,
373
+ remove_numbering
374
+ ):
375
+ """
376
+ Execute Chain of Verification (CoVe) process for Mistral AI.
377
+ Returns the verified reply or initial reply if error occurs.
378
+ """
379
+ try:
380
+ # STEP 2: Generate verification questions
381
+ step2_filled = step2_prompt.replace('<<INITIAL_REPLY>>', initial_reply)
382
+
383
+ verification_response = client.chat.complete(
384
+ model=user_model,
385
+ messages=[{'role': 'user', 'content': step2_filled}],
386
+ **({"temperature": creativity} if creativity is not None else {})
387
+ )
388
+
389
+ verification_questions = verification_response.choices[0].message.content
390
+
391
+ # STEP 3: Answer verification questions
392
+ questions_list = [
393
+ remove_numbering(q)
394
+ for q in verification_questions.split('\n')
395
+ if q.strip()
396
+ ]
397
+ verification_qa = []
398
+
399
+ # Prompting each question individually
400
+ for question in questions_list:
401
+ step3_filled = step3_prompt.replace('<<QUESTION>>', question)
402
+
403
+ answer_response = client.chat.complete(
404
+ model=user_model,
405
+ messages=[{'role': 'user', 'content': step3_filled}],
406
+ **({"temperature": creativity} if creativity is not None else {})
407
+ )
408
+
409
+ answer = answer_response.choices[0].message.content
410
+ verification_qa.append(f"Q: {question}\nA: {answer}")
411
+
412
+ # STEP 4: Final corrected categorization
413
+ verification_qa_text = "\n\n".join(verification_qa)
414
+
415
+ step4_filled = (step4_prompt
416
+ .replace('<<INITIAL_REPLY>>', initial_reply)
417
+ .replace('<<VERIFICATION_QA>>', verification_qa_text))
418
+
419
+ final_response = client.chat.complete(
420
+ model=user_model,
421
+ messages=[{'role': 'user', 'content': step4_filled}],
422
+ **({"temperature": creativity} if creativity is not None else {})
423
+ )
424
+
425
+ verified_reply = final_response.choices[0].message.content
426
+ print("Chain of verification completed. Final response generated.\n")
427
+
428
+ return verified_reply
429
+
430
+ except Exception as e:
431
+ print(f"ERROR in Chain of Verification: {str(e)}")
432
+ print("Falling back to initial response.\n")
433
+ return initial_reply
@@ -0,0 +1,94 @@
1
+ # openai list of models
2
+ openai_models = [
3
+ "gpt-5",
4
+ "gpt-5-mini",
5
+ "gpt-5-nano",
6
+ "gpt-4o",
7
+ "gpt-4o-mini",
8
+ "gpt-4.1",
9
+ "gpt-4.1-mini",
10
+ "gpt-4.1-nano",
11
+ "gpt-3.5-turbo",
12
+ "text-davinci-003",
13
+ "text-davinci-002"
14
+ ]
15
+
16
+ # anthropic list of models
17
+ anthropic_models = [
18
+ "claude-opus-4-20250514-v1:0",
19
+ "claude-opus-4-1-20250805-v1:0",
20
+ "claude-sonnet-4-5-20250929-v1:0",
21
+ "claude-sonnet-4-20250514-v1:0",
22
+ "claude-3-7-sonnet-20250219-v1:0",
23
+ "claude-3-5-sonnet-20240620-v1:0",
24
+ "claude-3-5-haiku-20241022-v1:0",
25
+ "claude-3-opus-20240229-v1:0",
26
+ "claude-3-sonnet-20240229-v1:0",
27
+ "claude-haiku-4-5-20251001-v1:0",
28
+ "claude-sonnet-4-5-20250929",
29
+ "claude-haiku-4-5-20251001",
30
+ "claude-opus-4-1-20250805"
31
+ ]
32
+
33
+ # google list of models
34
+
35
+ google_models = [
36
+ "gemini-2.5-flash",
37
+ "gemini-2.5-flash-lite",
38
+ "gemini-2.5-pro",
39
+ "gemini-2.0-flash",
40
+ "gemini-2.0-flash-lite",
41
+ "gemini-2.0-pro",
42
+ "gemini-2.5",
43
+ "gemini-2.0",
44
+ "gemini-2.5-flash-preview",
45
+ "gemini-2.5-pro-preview"
46
+ ]
47
+
48
+ # perplexity list of models
49
+
50
+ perplexity_models = [
51
+ "sonar",
52
+ "sonar-pro",
53
+ "sonar-reasoning",
54
+ "sonar-reasoning-pro",
55
+ "sonar-deep-research",
56
+ "r1-1776"
57
+ ]
58
+
59
+ # mistral list of models
60
+
61
+ mistral_models = [
62
+ "mistral-large-latest",
63
+ "mistral-medium-2505",
64
+ "mistral-large-2411",
65
+ "codestral-2501",
66
+ "pixtral-large-2411",
67
+ "mistral-small-2407",
68
+ "mistral-embed",
69
+ "codestral-embed",
70
+ "mistral-moderation-2411",
71
+ "ministral-3b-2410",
72
+ "ministral-8b-2410"
73
+ ]
74
+
75
+ # meta list of models
76
+ # list can be found here: https://huggingface.co/collections/meta-llama/llama-4-67f0c30d9fe03840bc9d0164
77
+ meta_llama_models = [
78
+ "meta/llama-3.1-8b-instruct",
79
+ "meta/llama-3.1-70b-instruct",
80
+ "meta/llama-3.1-405b-instruct",
81
+ "meta/llama-3.2-11b-vision-instruct",
82
+ "meta/llama-3.2-90b-vision-instruct",
83
+ "meta/llama-3.3-70b-instruct",
84
+ "meta/llama-4-scout-17b-16e-instruct",
85
+ "meta/llama-4-maverick-17b-128e-instruct",
86
+ "llama-4-maverick-17b-128e-instruct-maas",
87
+ "llama-4-scout-17b-16e-instruct-maas",
88
+ "llama-3.3-70b-instruct-maas",
89
+ "llama-3.2-90b-vision-instruct-maas",
90
+ "llama-3.1-405b-instruct-maas",
91
+ "llama-3.1-70b-instruct-maas",
92
+ "llama-3.1-8b-instruct-maas",
93
+
94
+ ]