当我尝试使用 GPT-4o 时,为什么 DataBricks 会出现 API 连接错误?

问题描述 投票:0回答:1

当尝试通过 DataBricks 中的 API 访问 AzureChatOpenAI 时,我得到:APIConnectionError:连接错误。该代码在 Visual Studio Code 中运行良好。关于如何解决此问题的任何想法,或者我应该联系谁来帮助我?

我询问了团队中的其他数据科学家,并联系了数据工程师,但尚未找到解决方案

我正在使用 langchain 的 AzureChatOpenAI。数据块亮点

response = model.invoke(messages, temperature=0)

如以下代码中的错误:

def get_categories_and_tone(review):
    messages = [
        SystemMessage(content="You are a helpful assistant that classifies customer reviews into predefined categories and determines the tone. Return the categories and the tone. Return it without any explanation. If the string: 'Lack.' appears in a review without any other words you must return a NaN as the tone"),
        HumanMessage(content=f"Classify the following review into one or more of these categories: {', '.join(categories)}.\n\nReview: \"{review}\"\nCategories:\nTone:")
    ]
    
    response = model.invoke(messages, temperature=0)
    response_content = response.content.strip().split('\n')
    
    categories_list = []
    tone = ""
    
    for line in response_content:
        if line.startswith("Categories:"):
            categories_list = line.replace('Categories: ', '').strip().split(', ')
        elif line.startswith("Tone:"):
            tone = line.replace('Tone: ', '').strip()
    
    return categories_list, tone

# Function to get the details if applicable
def get_details(categories_list, review):
    details = []
    for category in categories_list:
        if category in subcategories and subcategories[category]:
            possible_details = ', '.join(subcategories[category])
            messages = [
                SystemMessage(content="You are a helpful assistant that classifies customer reviews into predefined subcategories. Return only the subcategory name. Return it without any explanation."),
                HumanMessage(content=f"Based on the category '{category}', classify the following review into one of these details: {possible_details}\n\nReview: \"{review}\"\nDetail:")
            ]
            
            response = model.invoke(messages)
            response_content = response.content.strip()
            detail = response_content.replace('Detail: ', '').strip()
            details.append(detail)
        else:
            details.append("N/A")
    
    return details

# Main function for classifying an opinion
def classify_review(review):
    # Names to exclude
    categories_list, tone = get_categories_and_tone(review)
    #return categories_list, details, tone details removed as it deals with sub-categories
    return categories_list, tone

# Application of the function to classify every opinion
results = df['General Feedback, translated'].apply(classify_review)
azure databricks azure-databricks
1个回答
0
投票

这是网络问题。您可以首先使用此线程中的代码检查 API URL 是否可访问。

© www.soinside.com 2019 - 2024. All rights reserved.