File size: 790 Bytes
510a9b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from openai import OpenAI

# Initialize OpenAI client
def get_openai_client(api_key):
    """
    Returns an OpenAI client instance with the provided API key.
    """
    return OpenAI(api_key=api_key)

def classify_row_chat(prompt, client, model="gpt-3.5-turbo"):
    """
    Sends a classification prompt to the OpenAI Chat API and returns the predicted label.
    
    Args:
        prompt (str): The user prompt to classify data.
        client (OpenAI): The OpenAI client instance.
        model (str): The model to use for chat completion.
    
    Returns:
        str: The predicted label.
    """
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content.strip()