camel-ai 0.2.13__py3-none-any.whl → 0.2.15__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.
Potentially problematic release.
This version of camel-ai might be problematic. Click here for more details.
- camel/__init__.py +1 -1
- camel/agents/chat_agent.py +362 -237
- camel/benchmarks/__init__.py +11 -1
- camel/benchmarks/apibank.py +560 -0
- camel/benchmarks/apibench.py +496 -0
- camel/benchmarks/gaia.py +2 -2
- camel/benchmarks/nexus.py +518 -0
- camel/datagen/__init__.py +21 -0
- camel/datagen/cotdatagen.py +448 -0
- camel/datagen/self_instruct/__init__.py +36 -0
- camel/datagen/self_instruct/filter/__init__.py +34 -0
- camel/datagen/self_instruct/filter/filter_function.py +208 -0
- camel/datagen/self_instruct/filter/filter_registry.py +56 -0
- camel/datagen/self_instruct/filter/instruction_filter.py +76 -0
- camel/datagen/self_instruct/self_instruct.py +393 -0
- camel/datagen/self_instruct/templates.py +384 -0
- camel/datahubs/huggingface.py +12 -2
- camel/datahubs/models.py +4 -2
- camel/embeddings/mistral_embedding.py +5 -1
- camel/embeddings/openai_compatible_embedding.py +6 -1
- camel/embeddings/openai_embedding.py +5 -1
- camel/interpreters/e2b_interpreter.py +5 -1
- camel/loaders/apify_reader.py +5 -1
- camel/loaders/chunkr_reader.py +5 -1
- camel/loaders/firecrawl_reader.py +0 -30
- camel/logger.py +11 -5
- camel/messages/conversion/sharegpt/hermes/hermes_function_formatter.py +4 -1
- camel/models/anthropic_model.py +5 -1
- camel/models/azure_openai_model.py +1 -2
- camel/models/cohere_model.py +5 -1
- camel/models/deepseek_model.py +5 -1
- camel/models/gemini_model.py +5 -1
- camel/models/groq_model.py +5 -1
- camel/models/mistral_model.py +5 -1
- camel/models/nemotron_model.py +5 -1
- camel/models/nvidia_model.py +5 -1
- camel/models/openai_model.py +28 -12
- camel/models/qwen_model.py +5 -1
- camel/models/reka_model.py +5 -1
- camel/models/reward/nemotron_model.py +5 -1
- camel/models/samba_model.py +5 -1
- camel/models/togetherai_model.py +5 -1
- camel/models/yi_model.py +5 -1
- camel/models/zhipuai_model.py +5 -1
- camel/retrievers/auto_retriever.py +8 -0
- camel/retrievers/vector_retriever.py +6 -3
- camel/schemas/__init__.py +2 -1
- camel/schemas/base.py +2 -4
- camel/schemas/openai_converter.py +5 -1
- camel/schemas/outlines_converter.py +249 -0
- camel/societies/role_playing.py +4 -4
- camel/societies/workforce/workforce.py +2 -2
- camel/storages/graph_storages/nebula_graph.py +119 -27
- camel/storages/graph_storages/neo4j_graph.py +138 -0
- camel/toolkits/__init__.py +2 -0
- camel/toolkits/arxiv_toolkit.py +20 -3
- camel/toolkits/function_tool.py +61 -61
- camel/toolkits/meshy_toolkit.py +5 -1
- camel/toolkits/notion_toolkit.py +1 -1
- camel/toolkits/openbb_toolkit.py +869 -0
- camel/toolkits/search_toolkit.py +91 -5
- camel/toolkits/stripe_toolkit.py +5 -1
- camel/toolkits/twitter_toolkit.py +24 -16
- camel/types/enums.py +10 -1
- camel/types/unified_model_type.py +5 -0
- camel/utils/__init__.py +4 -0
- camel/utils/commons.py +146 -42
- camel/utils/token_counting.py +1 -0
- {camel_ai-0.2.13.dist-info → camel_ai-0.2.15.dist-info}/METADATA +18 -7
- {camel_ai-0.2.13.dist-info → camel_ai-0.2.15.dist-info}/RECORD +72 -58
- {camel_ai-0.2.13.dist-info → camel_ai-0.2.15.dist-info}/LICENSE +0 -0
- {camel_ai-0.2.13.dist-info → camel_ai-0.2.15.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# flake8: noqa
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class SelfInstructTemplates:
|
|
20
|
+
r"""Contains templates prompts for self-instruct data generation"""
|
|
21
|
+
|
|
22
|
+
clf_template = """ '''Can the following task be regarded as a classification task with finite output labels?
|
|
23
|
+
|
|
24
|
+
Task: Given my personality and the job, tell me if I would be suitable.
|
|
25
|
+
Is it classification? Yes
|
|
26
|
+
|
|
27
|
+
Task: Give me an example of a time when you had to use your sense of humor.
|
|
28
|
+
Is it classification? No
|
|
29
|
+
|
|
30
|
+
Task: Replace the placeholders in the given text with appropriate named entities.
|
|
31
|
+
Is it classification? No
|
|
32
|
+
|
|
33
|
+
Task: Fact checking - tell me if the statement is true, false, or unknown, based on your knowledge and common sense.
|
|
34
|
+
Is it classification? Yes
|
|
35
|
+
|
|
36
|
+
Task: Return the SSN number for the person.
|
|
37
|
+
Is it classification? No
|
|
38
|
+
|
|
39
|
+
Task: Detect if the Reddit thread contains hate speech.
|
|
40
|
+
Is it classification? Yes
|
|
41
|
+
|
|
42
|
+
Task: Analyze the sentences below to identify biases.
|
|
43
|
+
Is it classification? No
|
|
44
|
+
|
|
45
|
+
Task: Select the longest sentence in terms of the number of words in the paragraph, output the sentence index.
|
|
46
|
+
Is it classification? Yes
|
|
47
|
+
|
|
48
|
+
Task: Find out the toxic word or phrase in the sentence.
|
|
49
|
+
Is it classification? No
|
|
50
|
+
|
|
51
|
+
Task: Rank these countries by their population.
|
|
52
|
+
Is it classification? No
|
|
53
|
+
|
|
54
|
+
Task: You are provided with a news article, and you need to identify all the categories that this article belongs to. Possible categories include: Music, Sports, Politics, Tech, Finance, Basketball, Soccer, Tennis, Entertainment, Digital Game, World News. Output its categories one by one, seperated by comma.
|
|
55
|
+
Is it classification? Yes
|
|
56
|
+
|
|
57
|
+
Task: Given the name of an exercise, explain how to do it.
|
|
58
|
+
Is it classification? No
|
|
59
|
+
|
|
60
|
+
Task: Select the oldest person from the list.
|
|
61
|
+
Is it classification? Yes
|
|
62
|
+
|
|
63
|
+
Task: Find the four smallest perfect numbers.
|
|
64
|
+
Is it classification? No
|
|
65
|
+
|
|
66
|
+
Task: Does the information in the document supports the claim? You can answer "Support" or "Unsupport".
|
|
67
|
+
Is it classification? Yes
|
|
68
|
+
|
|
69
|
+
Task: Create a detailed budget for the given hypothetical trip.
|
|
70
|
+
Is it classification? No
|
|
71
|
+
|
|
72
|
+
Task: Given a sentence, detect if there is any potential stereotype in it. If so, you should explain the stereotype. Else, output no.
|
|
73
|
+
Is it classification? No
|
|
74
|
+
|
|
75
|
+
Task: Explain the following idiom to me, and try to give me some examples.
|
|
76
|
+
Is it classification? No
|
|
77
|
+
|
|
78
|
+
Task: Is there anything I can eat for a breakfast that doesn't include eggs, yet includes protein, and has roughly 700-1000 calories?
|
|
79
|
+
Is it classification? No
|
|
80
|
+
|
|
81
|
+
Task: Answer the following multiple choice question. Select A, B, C, or D for the final answer.
|
|
82
|
+
Is it classification? Yes
|
|
83
|
+
|
|
84
|
+
Task: Decide whether the syllogism is logically sound.
|
|
85
|
+
Is it classification? Yes
|
|
86
|
+
|
|
87
|
+
Task: How can individuals and organizations reduce unconscious bias?
|
|
88
|
+
Is it classification? No
|
|
89
|
+
|
|
90
|
+
Task: What are some things you can do to de-stress?
|
|
91
|
+
Is it classification? No
|
|
92
|
+
|
|
93
|
+
Task: Find out the largest one from a set of numbers. Output the number directly.
|
|
94
|
+
Is it classification? Yes
|
|
95
|
+
|
|
96
|
+
Task: Replace the <mask> token in the text with proper words that are consistent with the context. You can use multiple words for each <mask> token.
|
|
97
|
+
Is it classification? No
|
|
98
|
+
|
|
99
|
+
Task: Write a cover letter based on the given facts.
|
|
100
|
+
Is it classification? No
|
|
101
|
+
|
|
102
|
+
Task: Identify the pos tag of the word in the given sentence.
|
|
103
|
+
Is it classification? Yes
|
|
104
|
+
|
|
105
|
+
Task: Write a program to compute the sum of integers from k to n.
|
|
106
|
+
Is it classification? No
|
|
107
|
+
|
|
108
|
+
Task: In this task, you need to compare the meaning of the two sentences and tell if they are the same. Output yes or no.
|
|
109
|
+
Is it classification? Yes
|
|
110
|
+
|
|
111
|
+
Task: To make the pairs have the same analogy, write the fourth word.
|
|
112
|
+
Is it classification? No
|
|
113
|
+
|
|
114
|
+
Task: Given a set of numbers, find all possible subsets that sum to a given number.
|
|
115
|
+
Is it classification? No
|
|
116
|
+
|
|
117
|
+
"""
|
|
118
|
+
output_first_template_for_clf = '''You are given a classification instruction.
|
|
119
|
+
|
|
120
|
+
Produce multiple labeled examples following the format below. For each example:
|
|
121
|
+
- Begin with a "Class label:" line identifying one possible category.
|
|
122
|
+
- Follow that with one line specifying the example input (e.g., "Sentence:", "Dialogue:", "Opinion:", or "Email:").
|
|
123
|
+
- The content after these lines should serve as an illustrative example of that label.
|
|
124
|
+
|
|
125
|
+
Do not restate or include the "Task:" line. Do not add additional commentary. Just produce the labeled examples.
|
|
126
|
+
|
|
127
|
+
Example format (no initial task line, task will be provided) when task is Task: Classify the sentiment of the sentence into positive, negative, or mixed.:
|
|
128
|
+
Class label: mixed
|
|
129
|
+
Sentence: I enjoy the flavor of the restaurant but their service is too slow.
|
|
130
|
+
Class label: Positive
|
|
131
|
+
Sentence: I had a great day today. The weather was beautiful and I spent time with friends and family.
|
|
132
|
+
Class label: Negative
|
|
133
|
+
Sentence: I was really disappointed by the latest superhero movie. I would not recommend it to anyone.
|
|
134
|
+
|
|
135
|
+
Below are more examples:
|
|
136
|
+
|
|
137
|
+
Task: Given a dialogue, classify whether the user is satisfied with the service. You should respond with "Satisfied" or "Unsatisfied".
|
|
138
|
+
Class label: Satisfied
|
|
139
|
+
Dialogue:
|
|
140
|
+
- Agent: Thank you for your feedback. We will work to improve our service in the future.
|
|
141
|
+
- Customer: I am happy with the service you provided. Thank you for your help.
|
|
142
|
+
Class label: Unsatisfied
|
|
143
|
+
Dialogue:
|
|
144
|
+
- Agent: I am sorry we will cancel that order for you, and you will get a refund within 7 business days.
|
|
145
|
+
- Customer: oh that takes too long. I want you to take quicker action on this.
|
|
146
|
+
|
|
147
|
+
Task: Given some political opinions, classify whether the person belongs to Democrats or Republicans.
|
|
148
|
+
Class label: Democrats
|
|
149
|
+
Opinion: I believe that everyone should have access to quality healthcare regardless of their income level.
|
|
150
|
+
Class label: Republicans
|
|
151
|
+
Opinion: I believe that people should be able to keep more of their hard-earned money and should not be taxed at high rates.
|
|
152
|
+
|
|
153
|
+
Task: Tell me if the following email is a promotion email or not.
|
|
154
|
+
Class label: Promotion
|
|
155
|
+
Email: Check out our amazing new sale! We've got discounts on all of your favorite products.
|
|
156
|
+
Class label: Not Promotion
|
|
157
|
+
Email: We hope you are doing well. Let us know if you need any help.
|
|
158
|
+
|
|
159
|
+
Task: Detect if the Reddit thread contains hate speech.
|
|
160
|
+
Class label: Hate Speech
|
|
161
|
+
Thread: All people of color are stupid and should not be allowed to vote.
|
|
162
|
+
Class label: Not Hate Speech
|
|
163
|
+
Thread: The best way to cook a steak on the grill.
|
|
164
|
+
|
|
165
|
+
Task: Does the information in the document supports the claim? You can answer "Support" or "Unsupport".
|
|
166
|
+
Class label: Unsupport
|
|
167
|
+
Document: After a record-breaking run that saw mortgage rates plunge to all-time lows and home prices soar to new highs, the U.S. housing market finally is slowing. While demand and price gains are cooling, any correction is likely to be a modest one, housing economists and analysts say. No one expects price drops on the scale of the declines experienced during the Great Recession.
|
|
168
|
+
Claim: The US housing market is going to crash soon.
|
|
169
|
+
Class label: Support
|
|
170
|
+
Document: The U.S. housing market is showing signs of strain, with home sales and prices slowing in many areas. Mortgage rates have risen sharply in recent months, and the number of homes for sale is increasing. This could be the beginning of a larger downturn, with some economists predicting a potential housing crash in the near future.
|
|
171
|
+
Claim: The US housing market is going to crash soon.
|
|
172
|
+
|
|
173
|
+
Task: Answer the following multiple-choice question. Select A, B, C, or D for the final answer.
|
|
174
|
+
Class label: C
|
|
175
|
+
Question: What is the capital of Germany?
|
|
176
|
+
A. London
|
|
177
|
+
B. Paris
|
|
178
|
+
C. Berlin
|
|
179
|
+
D. Rome
|
|
180
|
+
Class label: D
|
|
181
|
+
Question: What is the largest planet in our solar system?
|
|
182
|
+
A) Earth
|
|
183
|
+
B) Saturn
|
|
184
|
+
C) Mars
|
|
185
|
+
D) Jupiter
|
|
186
|
+
Class label: A
|
|
187
|
+
Question: What is the process by which plants make their own food through photosynthesis?
|
|
188
|
+
A) Respiration
|
|
189
|
+
B) Fermentation
|
|
190
|
+
C) Digestion
|
|
191
|
+
D) Metabolism
|
|
192
|
+
Class label: B
|
|
193
|
+
Question: Who wrote the novel "The Great Gatsby"?
|
|
194
|
+
A) Ernest Hemingway
|
|
195
|
+
B) F. Scott Fitzgerald
|
|
196
|
+
C) J.D. Salinger
|
|
197
|
+
D) Mark Twain
|
|
198
|
+
|
|
199
|
+
Task: You need to read a code and detect if there is a syntax error or not. Output true if there is an error, output false if there is not.
|
|
200
|
+
Class label: true
|
|
201
|
+
Code:
|
|
202
|
+
def quick_sort(arr):
|
|
203
|
+
if len(arr) < 2
|
|
204
|
+
return arr
|
|
205
|
+
Class label: False
|
|
206
|
+
Code:
|
|
207
|
+
def calculate_average(numbers):
|
|
208
|
+
total = 0
|
|
209
|
+
for number in numbers:
|
|
210
|
+
total += number
|
|
211
|
+
return total / len(numbers)
|
|
212
|
+
|
|
213
|
+
Task: You are provided with a news article, and you need to identify all the categories that this article belongs to. Possible categories include Sports and Politics. Output its categories one by one, separated by a comma.
|
|
214
|
+
Class label: Sports
|
|
215
|
+
Article: The Golden State Warriors have won the NBA championship for the second year in a row.
|
|
216
|
+
Class label: Politics
|
|
217
|
+
Article: The United States has withdrawn from the Paris Climate Agreement.
|
|
218
|
+
Class label: Politics, Sports
|
|
219
|
+
Article: The government has proposed cutting funding for youth sports programs.
|
|
220
|
+
|
|
221
|
+
Task: Given a credit card statement, the cardholder's spending habits, and the account balance, classify whether the cardholder is at risk of defaulting on their payments or not.
|
|
222
|
+
Class label: At risk
|
|
223
|
+
Credit card statement: Purchases at high-end clothing stores and luxury hotels.
|
|
224
|
+
Cardholder's spending habits: Frequent purchases at luxury brands and high-end establishments.
|
|
225
|
+
Account balance: Over the credit limit and multiple missed payments.
|
|
226
|
+
Class label: Not at risk
|
|
227
|
+
Credit card statement: Purchases at grocery stores and gas stations.
|
|
228
|
+
Cardholder's spending habits: Regular purchases for necessary expenses and occasional dining out.
|
|
229
|
+
Account balance: Slightly below the credit limit and no missed payments.
|
|
230
|
+
|
|
231
|
+
Task: Given a social media post, the hashtags used, and a topic. classify whether the post is relevant to the topic or not.
|
|
232
|
+
Class label: Relevant
|
|
233
|
+
Post: I can't believe the government is still not taking action on climate change. It's time for us to take matters into our own hands.
|
|
234
|
+
Hashtags: #climatechange #actnow
|
|
235
|
+
Topic: Climate change
|
|
236
|
+
Class label: Not relevant
|
|
237
|
+
Post: I just bought the new iPhone and it is amazing!
|
|
238
|
+
Hashtags: #apple #technology
|
|
239
|
+
Topic: Travel
|
|
240
|
+
|
|
241
|
+
Task: The answer will be 'yes' if the provided sentence contains an explicit mention that answers the given question. Otherwise, answer 'no'.
|
|
242
|
+
Class label: Yes
|
|
243
|
+
Sentence: Jack played basketball for an hour after school.
|
|
244
|
+
Question: How long did Jack play basketball?
|
|
245
|
+
Class label: No
|
|
246
|
+
Sentence: The leaders of the Department of Homeland Security now appear before 88 committees and subcommittees of Congress.
|
|
247
|
+
Question: How often are they required to appear?
|
|
248
|
+
|
|
249
|
+
Task: Tell me what's the second largest city by population in Canada.
|
|
250
|
+
Class label: Montreal
|
|
251
|
+
|
|
252
|
+
Task: Classifying different types of mathematical equations, such as linear, and quadratic equations, based on the coefficients and terms in the equation.
|
|
253
|
+
Class label: Linear equation
|
|
254
|
+
Equation: y = 2x + 5
|
|
255
|
+
Class label: Quadratic equation
|
|
256
|
+
Equation: y = x^2 - 4x + 3
|
|
257
|
+
|
|
258
|
+
Task: Tell me the first number of the given list.
|
|
259
|
+
Class label: 1
|
|
260
|
+
List: 1, 2, 3
|
|
261
|
+
Class label: 2
|
|
262
|
+
List: 2, 9, 10
|
|
263
|
+
|
|
264
|
+
Task: Which of the following is not an input type? (a) number (b) date (c) phone number (d) email address (e) all of these are valid inputs.
|
|
265
|
+
Class label: (e)
|
|
266
|
+
|
|
267
|
+
Now, using the given instruction, produce several formatted examples accordingly:
|
|
268
|
+
Task: {instruction}
|
|
269
|
+
'''
|
|
270
|
+
|
|
271
|
+
input_first_template_for_gen = '''You will be given a task,
|
|
272
|
+
Please generate at most two example instances illustrating how to
|
|
273
|
+
perform this task. For each instance:
|
|
274
|
+
- If the task requires input (as an actual instance of the task),
|
|
275
|
+
provide it. if the task itself can be answered without an instance,
|
|
276
|
+
skip the input.
|
|
277
|
+
- Then provide the correct output.
|
|
278
|
+
|
|
279
|
+
Do not provide any additional commentary, explanations, or more than two instances. Just show the instances in the following format:
|
|
280
|
+
|
|
281
|
+
Example 1
|
|
282
|
+
[Input if necessary]
|
|
283
|
+
Output: [oldest person]
|
|
284
|
+
|
|
285
|
+
Example 2
|
|
286
|
+
[Input if necessary]
|
|
287
|
+
Output: [oldest person]
|
|
288
|
+
|
|
289
|
+
Below are some examples:
|
|
290
|
+
|
|
291
|
+
Task: Which exercises are best for reducing belly fat at home?
|
|
292
|
+
Output:
|
|
293
|
+
- Lying Leg Raises
|
|
294
|
+
- Leg In And Out
|
|
295
|
+
- Plank
|
|
296
|
+
- Side Plank
|
|
297
|
+
- Sit-ups
|
|
298
|
+
|
|
299
|
+
Task: Extract all the country names in the paragraph, list them separated by commas.
|
|
300
|
+
Example 1
|
|
301
|
+
Paragraph: Dr. No is the sixth novel by the English author Ian Fleming to feature his British Secret Service agent James Bond. Written at Fleming's Goldeneye estate in Jamaica, it was first published in the United Kingdom by Jonathan Cape in 1958. In the novel Bond looks into the disappearance in Jamaica of two fellow MI6 operatives who had been investigating Doctor No. Bond travels to No's Caribbean island and meets Honeychile Rider, who is there to collect shells. They are captured and taken to a luxurious facility carved into a mountain. The character of Doctor No, the son of a German missionary and a Chinese woman, was influenced by Sax Rohmer's Fu Manchu stories. Dr. No was the first of Fleming's novels to face widespread negative reviews in Britain, but it was received more favourably in the United States.
|
|
302
|
+
Output: English, British, Jamaica, the United Kingdom, German, Chinese, Britain, the United States.
|
|
303
|
+
|
|
304
|
+
Task: Converting 85 F to Celsius.
|
|
305
|
+
Output: 85°F = 29.44°C
|
|
306
|
+
|
|
307
|
+
Task: Sort the given list ascendingly.
|
|
308
|
+
Example 1
|
|
309
|
+
List: [10, 92, 2, 5, -4, 92, 5, 101]
|
|
310
|
+
Output: [-4, 2, 5, 5, 10, 92, 92, 101]
|
|
311
|
+
Example 2
|
|
312
|
+
Input 2 - List: [9.99, 10, -5, -1000, 5e6, 999]
|
|
313
|
+
Output: [-1000, -5, 9.99, 10, 999, 5e6]
|
|
314
|
+
|
|
315
|
+
Task: Suggest a better and more professional rephrasing of the following sentence.
|
|
316
|
+
Example 1
|
|
317
|
+
Sentence: This house is surprisingly not constructed very well, and you probably need more money to fix it after you buy it. If you ask me, I would suggest you to consider other candidates.
|
|
318
|
+
Output: This house does not seem to be constructed well, so you may need to spend more money to fix it after you purchase it. I would suggest that you look at other properties.
|
|
319
|
+
Example 2
|
|
320
|
+
Sentence: Just so you know, we did an experiment last week and found really surprising results - language model can improve itself!
|
|
321
|
+
Output: Our experiments last week demonstrated surprising results, proving that the language model can improve itself.
|
|
322
|
+
|
|
323
|
+
Task: Read the following paragraph and answer a math question about the paragraph. You need to write out the calculation for getting the final answer.
|
|
324
|
+
Example 1
|
|
325
|
+
Paragraph: Gun violence in the United States results in tens of thousands of deaths and injuries annually, and was the leading cause of death for children 19 and younger in 2020. In 2018, the most recent year for which data are available as of 2021, the Centers for Disease Control and Prevention's (CDC) National Center for Health Statistics reports 38,390 deaths by firearm, of which 24,432 were by suicide. The rate of firearm deaths per 100,000 people rose from 10.3 per 100,000 in 1999 to 12 per 100,000 in 2017, with 109 people dying per day or about 14,542 homicides in total, being 11.9 per 100,000 in 2018. In 2010, there were 19,392 firearm-related suicides, and 11,078 firearm-related homicides in the U.S. In 2010, 358 murders were reported involving a rifle while 6,009 were reported involving a handgun; another 1,939 were reported with an unspecified type of firearm. In 2011, a total of 478,400 fatal and nonfatal violent crimes were committed with a firearm.
|
|
326
|
+
Question: How many more firearm-related deaths were there in 2018 compared to 2010?
|
|
327
|
+
Output:
|
|
328
|
+
38390 - (19392 + 11078) = 38390 - 30470 = 7920.
|
|
329
|
+
So, in 2018, there were 7920 more deaths by firearm than in 2010.
|
|
330
|
+
|
|
331
|
+
Task: Write Python code to solve this leetcode problem.
|
|
332
|
+
Example 1
|
|
333
|
+
Problem: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.
|
|
334
|
+
Output:
|
|
335
|
+
class Solution(object):
|
|
336
|
+
def addTwoNumbers(self, l1, l2):
|
|
337
|
+
carry = 0
|
|
338
|
+
root = n = ListNode(0)
|
|
339
|
+
while l1 or l2 or carry:
|
|
340
|
+
v1 = v2 = 0
|
|
341
|
+
if l1:
|
|
342
|
+
v1 = l1.val
|
|
343
|
+
l1 = l1.next
|
|
344
|
+
if l2:
|
|
345
|
+
v2 = l2.val
|
|
346
|
+
l2 = l2.next
|
|
347
|
+
carry, val = divmod(v1+v2+carry, 10)
|
|
348
|
+
n.next = ListNode(val)
|
|
349
|
+
n = n.next
|
|
350
|
+
return root.next
|
|
351
|
+
|
|
352
|
+
Task: Solve the equation and find the value of X. Show your steps.
|
|
353
|
+
Example 1
|
|
354
|
+
Equation: 10X + 5 = 10
|
|
355
|
+
Output: 10X = 5, X = 0.5
|
|
356
|
+
Example 2
|
|
357
|
+
Equation: X + Y + 120 = 100
|
|
358
|
+
Output: X + Y = -20, X = -20 - Y
|
|
359
|
+
|
|
360
|
+
Task: Write a program to compute the sum of integers from k to n.
|
|
361
|
+
Output:
|
|
362
|
+
def sum(k, n):
|
|
363
|
+
sum = 0
|
|
364
|
+
for i in range(k, n+1):
|
|
365
|
+
sum += i
|
|
366
|
+
return sum
|
|
367
|
+
|
|
368
|
+
Task: Select the oldest person from the given list.
|
|
369
|
+
Example 1
|
|
370
|
+
List: George Washington, Confucius, Michael Jordan, Michelangelo
|
|
371
|
+
Output: Confucious
|
|
372
|
+
Example 2
|
|
373
|
+
List: Alan Turing, Geoffrey Hinton, Yann LeCun, Yoshua Bengio
|
|
374
|
+
Output: Alan Turing
|
|
375
|
+
|
|
376
|
+
Task: Turn down a job offer by sending an email to a recruiter explaining the reason.
|
|
377
|
+
Output: Hi [Recruiter],
|
|
378
|
+
Thank you so much for the generous offer to join your team. As we discussed, I’ve admired the company for a number of years, and am a proud endorser of its products. However, after further consideration of where I currently am in my career, I’ve decided to accept an offer at another company.
|
|
379
|
+
I would love to stay in touch with you and have already started following you on [Social Media Platform]. Again, thank you so much for your time and consideration.
|
|
380
|
+
Thanks again,
|
|
381
|
+
[Your Name]
|
|
382
|
+
|
|
383
|
+
Task: {instruction}
|
|
384
|
+
'''
|
camel/datahubs/huggingface.py
CHANGED
|
@@ -35,7 +35,11 @@ class HuggingFaceDatasetManager(BaseDatasetManager):
|
|
|
35
35
|
will be read from the environment variable `HUGGING_FACE_TOKEN`.
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
|
-
@api_keys_required(
|
|
38
|
+
@api_keys_required(
|
|
39
|
+
[
|
|
40
|
+
("token", "HUGGING_FACE_TOKEN"),
|
|
41
|
+
]
|
|
42
|
+
)
|
|
39
43
|
@dependencies_required('huggingface_hub')
|
|
40
44
|
def __init__(self, token: Optional[str] = None):
|
|
41
45
|
from huggingface_hub import HfApi
|
|
@@ -362,7 +366,13 @@ class HuggingFaceDatasetManager(BaseDatasetManager):
|
|
|
362
366
|
with tempfile.NamedTemporaryFile(
|
|
363
367
|
delete=False, mode="w", newline="", encoding="utf-8"
|
|
364
368
|
) as f:
|
|
365
|
-
json.dump(
|
|
369
|
+
json.dump(
|
|
370
|
+
[
|
|
371
|
+
record.model_dump(exclude_defaults=True)
|
|
372
|
+
for record in records
|
|
373
|
+
],
|
|
374
|
+
f,
|
|
375
|
+
)
|
|
366
376
|
temp_file_path = f.name
|
|
367
377
|
|
|
368
378
|
try:
|
camel/datahubs/models.py
CHANGED
|
@@ -13,10 +13,12 @@
|
|
|
13
13
|
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
from typing import Any, Dict, Optional
|
|
15
15
|
|
|
16
|
-
from pydantic import BaseModel
|
|
16
|
+
from pydantic import BaseModel, ConfigDict
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class Record(BaseModel):
|
|
20
20
|
id: Optional[str] = None
|
|
21
21
|
metadata: Optional[Dict[str, Any]] = None
|
|
22
|
-
content: Dict[str, Any]
|
|
22
|
+
content: Optional[Dict[str, Any]] = None
|
|
23
|
+
|
|
24
|
+
model_config = ConfigDict(extra="allow")
|
|
@@ -37,6 +37,11 @@ class MistralEmbedding(BaseEmbedding[str]):
|
|
|
37
37
|
RuntimeError: If an unsupported model type is specified.
|
|
38
38
|
"""
|
|
39
39
|
|
|
40
|
+
@api_keys_required(
|
|
41
|
+
[
|
|
42
|
+
("api_key", 'MISTRAL_API_KEY'),
|
|
43
|
+
]
|
|
44
|
+
)
|
|
40
45
|
def __init__(
|
|
41
46
|
self,
|
|
42
47
|
model_type: EmbeddingModelType = (EmbeddingModelType.MISTRAL_EMBED),
|
|
@@ -56,7 +61,6 @@ class MistralEmbedding(BaseEmbedding[str]):
|
|
|
56
61
|
self._api_key = api_key or os.environ.get("MISTRAL_API_KEY")
|
|
57
62
|
self._client = Mistral(api_key=self._api_key)
|
|
58
63
|
|
|
59
|
-
@api_keys_required("MISTRAL_API_KEY")
|
|
60
64
|
def embed_list(
|
|
61
65
|
self,
|
|
62
66
|
objs: list[str],
|
|
@@ -32,6 +32,12 @@ class OpenAICompatibleEmbedding(BaseEmbedding[str]):
|
|
|
32
32
|
url (str): The url to the model service.
|
|
33
33
|
"""
|
|
34
34
|
|
|
35
|
+
@api_keys_required(
|
|
36
|
+
[
|
|
37
|
+
("api_key", 'OPENAI_COMPATIBILIY_API_KEY'),
|
|
38
|
+
("url", 'OPENAI_COMPATIBILIY_API_BASE_URL'),
|
|
39
|
+
]
|
|
40
|
+
)
|
|
35
41
|
def __init__(
|
|
36
42
|
self,
|
|
37
43
|
model_type: str,
|
|
@@ -52,7 +58,6 @@ class OpenAICompatibleEmbedding(BaseEmbedding[str]):
|
|
|
52
58
|
base_url=self._url,
|
|
53
59
|
)
|
|
54
60
|
|
|
55
|
-
@api_keys_required("OPENAI_COMPATIBILIY_API_KEY")
|
|
56
61
|
def embed_list(
|
|
57
62
|
self,
|
|
58
63
|
objs: list[str],
|
|
@@ -39,6 +39,11 @@ class OpenAIEmbedding(BaseEmbedding[str]):
|
|
|
39
39
|
RuntimeError: If an unsupported model type is specified.
|
|
40
40
|
"""
|
|
41
41
|
|
|
42
|
+
@api_keys_required(
|
|
43
|
+
[
|
|
44
|
+
("api_key", 'OPENAI_API_KEY'),
|
|
45
|
+
]
|
|
46
|
+
)
|
|
42
47
|
def __init__(
|
|
43
48
|
self,
|
|
44
49
|
model_type: EmbeddingModelType = (
|
|
@@ -58,7 +63,6 @@ class OpenAIEmbedding(BaseEmbedding[str]):
|
|
|
58
63
|
self._api_key = api_key or os.environ.get("OPENAI_API_KEY")
|
|
59
64
|
self.client = OpenAI(timeout=180, max_retries=3, api_key=self._api_key)
|
|
60
65
|
|
|
61
|
-
@api_keys_required("OPENAI_API_KEY")
|
|
62
66
|
def embed_list(
|
|
63
67
|
self,
|
|
64
68
|
objs: list[str],
|
camel/loaders/apify_reader.py
CHANGED
|
@@ -27,7 +27,11 @@ class Apify:
|
|
|
27
27
|
api_key (Optional[str]): API key for authenticating with the Apify API.
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
|
-
@api_keys_required(
|
|
30
|
+
@api_keys_required(
|
|
31
|
+
[
|
|
32
|
+
("api_key", "APIFY_API_KEY"),
|
|
33
|
+
]
|
|
34
|
+
)
|
|
31
35
|
def __init__(
|
|
32
36
|
self,
|
|
33
37
|
api_key: Optional[str] = None,
|
camel/loaders/chunkr_reader.py
CHANGED
|
@@ -40,7 +40,11 @@ class ChunkrReader:
|
|
|
40
40
|
**kwargs (Any): Additional keyword arguments for request headers.
|
|
41
41
|
"""
|
|
42
42
|
|
|
43
|
-
@api_keys_required(
|
|
43
|
+
@api_keys_required(
|
|
44
|
+
[
|
|
45
|
+
("api_key", "CHUNKR_API_KEY"),
|
|
46
|
+
]
|
|
47
|
+
)
|
|
44
48
|
def __init__(
|
|
45
49
|
self,
|
|
46
50
|
api_key: Optional[str] = None,
|
|
@@ -77,36 +77,6 @@ class Firecrawl:
|
|
|
77
77
|
except Exception as e:
|
|
78
78
|
raise RuntimeError(f"Failed to crawl the URL: {e}")
|
|
79
79
|
|
|
80
|
-
def markdown_crawl(self, url: str) -> str:
|
|
81
|
-
r"""Crawl a URL and all accessible subpages and return the content in
|
|
82
|
-
Markdown format.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
url (str): The URL to crawl.
|
|
86
|
-
|
|
87
|
-
Returns:
|
|
88
|
-
str: The content of the URL in Markdown format.
|
|
89
|
-
|
|
90
|
-
Raises:
|
|
91
|
-
RuntimeError: If the crawling process fails.
|
|
92
|
-
"""
|
|
93
|
-
|
|
94
|
-
try:
|
|
95
|
-
crawl_result = self.app.crawl_url(
|
|
96
|
-
url,
|
|
97
|
-
{'formats': ['markdown']},
|
|
98
|
-
)
|
|
99
|
-
if not isinstance(crawl_result, list):
|
|
100
|
-
raise ValueError("Unexpected response format")
|
|
101
|
-
markdown_contents = [
|
|
102
|
-
result.get('markdown', '') for result in crawl_result
|
|
103
|
-
]
|
|
104
|
-
return '\n'.join(markdown_contents)
|
|
105
|
-
except Exception as e:
|
|
106
|
-
raise RuntimeError(
|
|
107
|
-
f"Failed to crawl the URL and retrieve markdown: {e}"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
80
|
def check_crawl_job(self, job_id: str) -> Dict:
|
|
111
81
|
r"""Check the status of a crawl job.
|
|
112
82
|
|
camel/logger.py
CHANGED
|
@@ -26,18 +26,24 @@ def _configure_library_logging():
|
|
|
26
26
|
|
|
27
27
|
if not logging.root.handlers and not _logger.handlers:
|
|
28
28
|
logging.basicConfig(
|
|
29
|
-
level=os.environ.get('
|
|
29
|
+
level=os.environ.get('CAMEL_LOGGING_LEVEL', 'WARNING').upper(),
|
|
30
30
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
31
31
|
stream=sys.stdout,
|
|
32
32
|
)
|
|
33
33
|
logging.setLoggerClass(logging.Logger)
|
|
34
|
-
_logger.info(
|
|
34
|
+
_logger.info(
|
|
35
|
+
f"CAMEL library logging has been configured "
|
|
36
|
+
f"(level: {_logger.getEffectiveLevel()}). "
|
|
37
|
+
f"To change level, use set_log_level() or "
|
|
38
|
+
"set CAMEL_LOGGING_LEVEL env var. To disable logging, "
|
|
39
|
+
"set CAMEL_LOGGING_DISABLED=true or use disable_logging()"
|
|
40
|
+
)
|
|
35
41
|
else:
|
|
36
42
|
_logger.debug("Existing logger configuration found, using that.")
|
|
37
43
|
|
|
38
44
|
|
|
39
45
|
def disable_logging():
|
|
40
|
-
r"""Disable all logging for the
|
|
46
|
+
r"""Disable all logging for the CAMEL library.
|
|
41
47
|
|
|
42
48
|
This function sets the log level to a value higher than CRITICAL,
|
|
43
49
|
effectively disabling all log messages, and adds a NullHandler to
|
|
@@ -55,7 +61,7 @@ def disable_logging():
|
|
|
55
61
|
|
|
56
62
|
|
|
57
63
|
def enable_logging():
|
|
58
|
-
r"""Enable logging for the
|
|
64
|
+
r"""Enable logging for the CAMEL library.
|
|
59
65
|
|
|
60
66
|
This function re-enables logging if it was previously disabled,
|
|
61
67
|
and configures the library logging using the default settings.
|
|
@@ -67,7 +73,7 @@ def enable_logging():
|
|
|
67
73
|
|
|
68
74
|
|
|
69
75
|
def set_log_level(level):
|
|
70
|
-
r"""Set the logging level for the
|
|
76
|
+
r"""Set the logging level for the CAMEL library.
|
|
71
77
|
|
|
72
78
|
Args:
|
|
73
79
|
level (Union[str, int]): The logging level to set. This can be a string
|
|
@@ -109,7 +109,10 @@ class HermesFunctionFormatter(
|
|
|
109
109
|
format.
|
|
110
110
|
"""
|
|
111
111
|
tool_call_dict = {"name": func_name, "arguments": args}
|
|
112
|
-
|
|
112
|
+
|
|
113
|
+
if content:
|
|
114
|
+
return f"{content}\n<tool_call>\n{tool_call_dict}\n</tool_call>"
|
|
115
|
+
return f"<tool_call>\n{tool_call_dict}\n</tool_call>"
|
|
113
116
|
|
|
114
117
|
def format_tool_response(self, func_name: str, result: Any) -> str:
|
|
115
118
|
r"""Formats a tool response message with the given function name and
|
camel/models/anthropic_model.py
CHANGED
|
@@ -45,6 +45,11 @@ class AnthropicModel(BaseModelBackend):
|
|
|
45
45
|
will be used. (default: :obj:`None`)
|
|
46
46
|
"""
|
|
47
47
|
|
|
48
|
+
@api_keys_required(
|
|
49
|
+
[
|
|
50
|
+
("api_key", "ANTHROPIC_API_KEY"),
|
|
51
|
+
]
|
|
52
|
+
)
|
|
48
53
|
@dependencies_required('anthropic')
|
|
49
54
|
def __init__(
|
|
50
55
|
self,
|
|
@@ -118,7 +123,6 @@ class AnthropicModel(BaseModelBackend):
|
|
|
118
123
|
model=self.model_type,
|
|
119
124
|
).input_tokens
|
|
120
125
|
|
|
121
|
-
@api_keys_required("ANTHROPIC_API_KEY")
|
|
122
126
|
def run(
|
|
123
127
|
self,
|
|
124
128
|
messages: List[OpenAIMessage],
|
|
@@ -24,7 +24,7 @@ from camel.types import (
|
|
|
24
24
|
ChatCompletionChunk,
|
|
25
25
|
ModelType,
|
|
26
26
|
)
|
|
27
|
-
from camel.utils import BaseTokenCounter, OpenAITokenCounter
|
|
27
|
+
from camel.utils import BaseTokenCounter, OpenAITokenCounter
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
class AzureOpenAIModel(BaseModelBackend):
|
|
@@ -107,7 +107,6 @@ class AzureOpenAIModel(BaseModelBackend):
|
|
|
107
107
|
self._token_counter = OpenAITokenCounter(self.model_type)
|
|
108
108
|
return self._token_counter
|
|
109
109
|
|
|
110
|
-
@api_keys_required("AZURE_OPENAI_API_KEY", "AZURE_API_VERSION")
|
|
111
110
|
def run(
|
|
112
111
|
self,
|
|
113
112
|
messages: List[OpenAIMessage],
|