File size: 3,779 Bytes
839ab56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import re
def compare_with_chatgpt_job_title(text1, text2, openai_api_key):
    openai.api_key = openai_api_key
    prompt = f"Compare the following two texts and determine if they match in job title . Return 1 for match and 0 for no match.\n\nText 1: {text1}\n\nText 2: {text2}"

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are an assistant that helps compare texts for matching job titles "},
            {"role": "user", "content": prompt}
        ],
        max_tokens=100
    )

    # Extract the response content
    result = response.choices[0].message['content'].strip()

    # Check if the response contains '1' or '0' and return the corresponding integer
    if '1' in result:
        return 1
    elif '0' in result:
        return 0
    else:
        raise ValueError(f"Unexpected response: {result}")




def compare_with_chatgpt_education(text1, text2, openai_api_key):
    openai.api_key = openai_api_key
    prompt = f"Compare the following two texts and determine if they match in education . Return 1 for match and 0 for no match.\n\nText 1: {text1}\n\nText 2: {text2}"

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are an assistant that helps compare texts for matching education "},
            {"role": "user", "content": prompt}
        ],
        max_tokens=100
    )

    # Extract the response content
    result = response.choices[0].message['content'].strip()

    # Check if the response contains '1' or '0' and return the corresponding integer
    if '1' in result:
        return 1
    elif '0' in result:
        return 0
    else:
        raise ValueError(f"Unexpected response: {result}")


def compare_with_chatgpt_location(text1, text2, openai_api_key):
    openai.api_key = openai_api_key
    prompt = f"Compare the following two texts and determine if they match in location . Return 1 for match and 0 for no match.\n\nText 1: {text1}\n\nText 2: {text2}"

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are an assistant that helps compare texts for matching location "},
            {"role": "user", "content": prompt}
        ],
        max_tokens=100
    )

    # Extract the response content
    result = response.choices[0].message['content'].strip()

    # Check if the response contains '1' or '0' and return the corresponding integer
    if '1' in result:
        return 1
    elif '0' in result:
        return 0
    else:
        raise ValueError(f"Unexpected response: {result}")


def compare_age_range_with_description(age, age_DS, openai_api_key):
    openai.api_key = openai_api_key
    
    prompt = (f"Check if the age {age} falls within the age range '{age_DS}' "
              f"Return '1' if it falls within the range, otherwise return '0'.\n\n"
              f"Age: {age}\n\n"
              f"Age Range: {age_DS}")

    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are an assistant that helps compare age ranges with a given age."},
            {"role": "user", "content": prompt}
        ],
        max_tokens=100
    )

    result = response.choices[0].message['content'].strip()

    # استفاده از regex برای پیدا کردن '1' یا '0'
    match = re.search(r"\b[01]\b", result)
    if match:
        return int(match.group())
    else:
        raise ValueError(f"Unexpected response: {result}")