-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_sharpapi_tests.py
399 lines (339 loc) · 14.5 KB
/
run_sharpapi_tests.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import logging
import random
import string
import os
from dotenv import load_dotenv
from sharpapi.sharp_api_service import SharpApiService
from sharpapi.dto.job_description_parameters import JobDescriptionParameters
import questionary # Use questionary instead of inquirer
def random_string(length=8):
"""Generate a random string of fixed length."""
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
def test_ping(sharp_api, logger):
logger.info("Testing ping() method...")
ping_response = sharp_api.ping()
logger.info(f"Ping Response: {ping_response}")
logger.info("-" * 50)
def test_quota(sharp_api, logger):
logger.info("Testing quota() method...")
quota_info = sharp_api.quota()
if quota_info:
logger.info("Quota Information:")
logger.info(f"Timestamp: {quota_info.timestamp}")
logger.info(f"On Trial: {quota_info.on_trial}")
logger.info(f"Trial Ends: {quota_info.trial_ends}")
logger.info(f"Subscribed: {quota_info.subscribed}")
logger.info(f"Current Subscription Start: {quota_info.current_subscription_start}")
logger.info(f"Current Subscription End: {quota_info.current_subscription_end}")
logger.info(f"Subscription Words Quota: {quota_info.subscription_words_quota}")
logger.info(f"Subscription Words Used: {quota_info.subscription_words_used}")
logger.info(f"Subscription Words Used Percentage: {quota_info.subscription_words_used_percentage}%")
else:
logger.info("Failed to retrieve quota information.")
logger.info("-" * 50)
def test_parse_resume(sharp_api, logger):
logger.info("Testing parse_resume() method...")
resume_file_path = 'sample_resume.pdf' # Replace with your actual file path
if os.path.exists(resume_file_path):
status_url = sharp_api.parse_resume(resume_file_path, language='English')
result_job = sharp_api.fetch_results(status_url)
logger.info("Parsed Resume Result:")
logger.info(result_job.get_result_json())
else:
logger.warning(f"Resume file '{resume_file_path}' not found. Skipping parse_resume test.")
logger.info("-" * 50)
def test_generate_job_description(sharp_api, logger):
logger.info("Testing generate_job_description() method...")
job_description_params = JobDescriptionParameters(
name=f"Software Engineer",
company_name=f"Company {random_string(8)}",
minimum_work_experience="3+ years",
minimum_education="Bachelor's Degree in Computer Science",
employment_type="Full-time",
required_skills=[
"Proficiency in Python",
"Experience with RESTful APIs",
f"Knowledge of {random_string(7)}"
],
optional_skills=[
"Familiarity with Docker",
"Experience with cloud services"
],
country="USA",
remote=True,
visa_sponsored=False,
language='English',
voice_tone='Professional',
context=None
)
status_url = sharp_api.generate_job_description(job_description_params)
result_job = sharp_api.fetch_results(status_url)
logger.info("Generated Job Description Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_related_skills(sharp_api, logger):
logger.info("Testing related_skills() method...")
skill_name = f"Coding"
status_url = sharp_api.related_skills(skill_name, language='English', max_quantity=5)
result_job = sharp_api.fetch_results(status_url)
logger.info("Related Skills Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_related_job_positions(sharp_api, logger):
logger.info("Testing related_job_positions() method...")
job_position_name = f"Flutter Developer"
status_url = sharp_api.related_job_positions(job_position_name, language='English', max_quantity=5)
result_job = sharp_api.fetch_results(status_url)
logger.info("Related Job Positions Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_product_review_sentiment(sharp_api, logger):
logger.info("Testing product_review_sentiment() method...")
review = f"This product is {random.choice(['great', 'terrible'])}! {random_string(10)}"
status_url = sharp_api.product_review_sentiment(review)
result_job = sharp_api.fetch_results(status_url)
logger.info("Product Review Sentiment Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_product_categories(sharp_api, logger):
logger.info("Testing product_categories() method...")
product_name = f"Apple Watch v.{random_string(2)}"
status_url = sharp_api.product_categories(
product_name,
language='English',
max_quantity=5,
voice_tone='Neutral'
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Product Categories Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_generate_product_intro(sharp_api, logger):
logger.info("Testing generate_product_intro() method...")
product_data = f"This is a new product called Apple Watch v.{random_string(2)}. It is designed to help with {random_string(15)}."
status_url = sharp_api.generate_product_intro(
product_data,
language='English',
max_length=100,
voice_tone='Friendly'
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Generated Product Intro Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_generate_thank_you_email(sharp_api, logger):
logger.info("Testing generate_thank_you_email() method...")
product_name = f"Apple Watch v.{random_string(2)}"
status_url = sharp_api.generate_thank_you_email(
product_name,
language='English',
max_length=200,
voice_tone='Professional',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Generated Thank You Email Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_detect_phones(sharp_api, logger):
logger.info("Testing detect_phones() method...")
text_with_phone = f"Contact me at {random.randint(100,999)}-555-{random.randint(1000,9999)} for more information."
status_url = sharp_api.detect_phones(text_with_phone)
result_job = sharp_api.fetch_results(status_url)
logger.info("Detected Phones Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_detect_emails(sharp_api, logger):
logger.info("Testing detect_emails() method...")
text_with_email = f"Please send an email to test_{random_string(5)}@example.com."
status_url = sharp_api.detect_emails(text_with_email)
result_job = sharp_api.fetch_results(status_url)
logger.info("Detected Emails Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_detect_spam(sharp_api, logger):
logger.info("Testing detect_spam() method...")
spam_text = f"Congratulations! You have won {random.randint(1000,5000)} dollars! Click here to claim your prize."
status_url = sharp_api.detect_spam(spam_text)
result_job = sharp_api.fetch_results(status_url)
logger.info("Spam Detection Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_summarize_text(sharp_api, logger):
logger.info("Testing summarize_text() method...")
long_text = (
f"This is a long text that needs to be summarized. {random_string(50)} "
"It contains multiple sentences and information."
)
status_url = sharp_api.summarize_text(
long_text,
language='English',
max_length=50,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Summarized Text Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_generate_keywords(sharp_api, logger):
logger.info("Testing generate_keywords() method...")
content = f"This is some content about Apple Watch v.{random_string(1)} that needs keywords."
status_url = sharp_api.generate_keywords(
content,
language='English',
max_quantity=5,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Generated Keywords Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_translate(sharp_api, logger):
logger.info("Testing translate() method...")
text_to_translate = f"This is a text to translate. Let's see what comes out {random_string(3)}"
target_language = 'Spanish'
status_url = sharp_api.translate(
text_to_translate,
language=target_language,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Translated Text Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_paraphrase(sharp_api, logger):
logger.info("Testing paraphrase() method...")
text_to_paraphrase = f"This is a text that needs to be paraphrased. Lorem ipsum. Go. Now. {random_string(10)}"
status_url = sharp_api.paraphrase(
text_to_paraphrase,
language='English',
max_length=100,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Paraphrased Text Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_proofread(sharp_api, logger):
logger.info("Testing proofread() method...")
text_to_proofread = f"This is a txt with erors that need to be corected. {random_string(10)}"
status_url = sharp_api.proofread(text_to_proofread)
result_job = sharp_api.fetch_results(status_url)
logger.info("Proofread Text Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_generate_seo_tags(sharp_api, logger):
logger.info("Testing generate_seo_tags() method...")
content_for_seo = f"This is content about Apple Watch v.{random_string(2)} that needs SEO tags."
status_url = sharp_api.generate_seo_tags(
content_for_seo,
language='English',
voice_tone='Neutral'
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Generated SEO Tags Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_travel_review_sentiment(sharp_api, logger):
logger.info("Testing travel_review_sentiment() method...")
travel_review = f"The trip was {random.choice(['amazing', 'disappointing'])}. {random_string(10)}"
status_url = sharp_api.travel_review_sentiment(travel_review)
result_job = sharp_api.fetch_results(status_url)
logger.info("Travel Review Sentiment Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_tours_and_activities_product_categories(sharp_api, logger):
logger.info("Testing tours_and_activities_product_categories() method...")
ta_product_name = f"Tour Universal Studios Singapore"
status_url = sharp_api.tours_and_activities_product_categories(
ta_product_name,
city='Paris',
country='France',
language='English',
max_quantity=5,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Tours and Activities Product Categories Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def test_hospitality_product_categories(sharp_api, logger):
logger.info("Testing hospitality_product_categories() method...")
hospitality_product_name = f"Hotel Hilton New York"
status_url = sharp_api.hospitality_product_categories(
hospitality_product_name,
city='New York',
country='USA',
language='English',
max_quantity=5,
voice_tone='Neutral',
context=None
)
result_job = sharp_api.fetch_results(status_url)
logger.info("Hospitality Product Categories Result:")
logger.info(result_job.get_result_json())
logger.info("-" * 50)
def main():
# Load environment variables from .env file
load_dotenv()
api_key = os.getenv('SHARP_API_KEY')
if not api_key:
raise ValueError("API key not found. Please set SHARP_API_KEY in your .env file.")
# Initialize logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Initialize the SharpApiService
sharp_api = SharpApiService(api_key)
# Define the list of tests
tests = [
("Ping", test_ping),
("Quota", test_quota),
("Parse Resume", test_parse_resume),
("Generate Job Description", test_generate_job_description),
("Related Skills", test_related_skills),
("Related Job Positions", test_related_job_positions),
("Product Review Sentiment", test_product_review_sentiment),
("Product Categories", test_product_categories),
("Generate Product Intro", test_generate_product_intro),
("Generate Thank You Email", test_generate_thank_you_email),
("Detect Phones", test_detect_phones),
("Detect Emails", test_detect_emails),
("Detect Spam", test_detect_spam),
("Summarize Text", test_summarize_text),
("Generate Keywords", test_generate_keywords),
("Translate", test_translate),
("Paraphrase", test_paraphrase),
("Proofread", test_proofread),
("Generate SEO Tags", test_generate_seo_tags),
("Travel Review Sentiment", test_travel_review_sentiment),
("Tours and Activities Product Categories", test_tours_and_activities_product_categories),
("Hospitality Product Categories", test_hospitality_product_categories),
]
# Prepare the choices for questionary
choices = [test_name for (test_name, _) in tests] + ["Exit"]
while True:
# Use questionary to ask which test to run
choice = questionary.select(
"Which test would you like to run?",
choices=choices,
use_arrow_keys=True
).ask()
if choice == "Exit":
print("Exiting the program.")
break
# Find the selected test function
for test_name, test_func in tests:
if choice == test_name:
try:
test_func(sharp_api, logger)
except Exception as e:
logger.error(f"An error occurred during {test_name}:")
logger.error(e)
break
if __name__ == '__main__':
main()