-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths01e05.py
61 lines (52 loc) · 1.87 KB
/
s01e05.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import json
from utilities.common import AIDevsClient, OpenAIClient
from utilities.config import AI_DEVS_API_KEY, S01E05_TASK_URL, S01E05_REPORT_URL
def main():
# Initialize clients
client_aidevs = AIDevsClient()
client_openai = OpenAIClient()
# Configuration
TASK_NAME = "CENZURA"
API_KEY = AI_DEVS_API_KEY
DATA_URL = S01E05_TASK_URL
SUBMIT_URL = S01E05_REPORT_URL
# Step 1: Retrieve data using the client method
data = ''.join(client_aidevs.fetch_data(DATA_URL))
print("Original Text: " + data)
if data:
# Step 2: Censor personal information
messages = [
{"role": "system", "content": (
"You are a helpful assistant that censors personal information in a text. "
"Replace all names, ages, cities, and street addresses with the word 'CENZURA'. "
"YOU MUST KEEP the rest of the text unchanged, including all spaces, punctuation, and words."
)},
{"role": "user", "content": data}
]
censored_text = client_openai.get_completion(
messages=messages,
model="gpt-4o-mini",
temperature=0.1
).strip()
print("Censored Text: " + censored_text)
# Step 3: Prepare the payload
answer = censored_text # The actual censored text
payload = {
"task": TASK_NAME,
"apikey": API_KEY,
"answer": answer
}
# Step 4: Submit using the client method
response = client_aidevs.submit_answer(
answer=payload,
submit_url=SUBMIT_URL
)
# Handle response
if response:
print(f"Request successful! Response: {response}")
else:
print("Failed to submit the censored data.")
else:
print("Failed to retrieve data.")
if __name__ == "__main__":
main()