Error when calling CosmosDB from PromptFlow in Azure Machine Learning: “Request failed with status code 400 – NotSupported ConnectionType 0”

  Kiến thức lập trình

Hello Stack Overflow community,

I’m working on a project that’s part of the Azure Contoso Chat repo, which involves using PromptFlow, a component of Azure Machine Learning, to call CosmosDB.

I’m at the end of the tutorial, testing the flow in AI studio, and I encounter this error:

Request failed with status code 400 - NotSupported ConnectionType 0 for connection contoso-cosmos.

Here’s a snippet of the code I’m using to connect to CosmosDB:
`from typing import Dict
from promptflow import tool
from azure.cosmos import CosmosClient
from promptflow.connections import CustomConnection

@tool
def customer_lookup(customerId: str, conn: CustomConnection) -> str:
client = CosmosClient(url=conn.configs[“endpoint”], credential=conn.secrets[“key”])
db = client.get_database_client(conn.configs[“databaseId”])
container = db.get_container_client(conn.configs[“containerId”])
response = container.read_item(item=customerId, partition_key=customerId)
response[“orders”] = response[“orders”][:2]
return response`

This flow works as expected when called from my local environment, but the error occurs when I run it within Azure Machine Learning’s PromptFlow.

Also,I’ve double-checked the connection details, and they appear to be correct. I suspect there might be a specific configuration or setting within Azure Machine Learning that needs to be adjusted.

Has anyone encountered a similar issue or have any insights on how to resolve this? Any help would be greatly appreciated!

New contributor

user24253039 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT