Formerly known as Azure AI Services or Azure Cognitive Services is a unified collection of prebuilt AI capabilities within the Microsoft Foundry platform
Hi Bagas
Agreed with above pointers.
Any slip in endpoint/model deployment name might trigger 500 internal server error even though correct key is passed.
Have skip v2/rerank in endpoint name
Attached reference code from my trials (Used new foundry UI)
Code that provided results with correct key
import cohere
co = cohere.ClientV2(
base_url="https://<foundryproject>.services.ai.azure.com/providers/cohere/",
api_key="2UYOigwIlCf7ddqPQS8gCuQlumdBW1V6IiNq5GMm3y7aT2FCFqCSJQQJ99CCACREanaXJ3w3AAAAACOGlNG",
)
import yaml
documents = [
{
"Title": "Incorrect Password",
"Content": "Hello, I have been trying to access my account for the past hour and it keeps saying my password is incorrect. Can you please help me?",
},
{
"Title": "Confirmation Email Missed",
"Content": "Hi, I recently purchased a product from your website but I never received a confirmation email. Can you please look into this for me?",
},
{
"Title": "Questions about Return Policy",
"Content": "Hello, I have a question about the return policy for this product. I purchased it a few weeks ago and it is defective.",
},
{
"Title": "Customer Support is Busy",
"Content": "Good morning, I have been trying to reach your customer support team for the past week but I keep getting a busy signal. Can you please help me?",
},
{
"Title": "Received Wrong Item",
"Content": "Hi, I have a question about my recent order. I received the wrong item and I need to return it.",
},
{
"Title": "Customer Service is Unavailable",
"Content": "Hello, I have been trying to reach your customer support team for the past hour but I keep getting a busy signal. Can you please help me?",
},
{
"Title": "Return Policy for Defective Product",
"Content": "Hi, I have a question about the return policy for this product. I purchased it a few weeks ago and it is defective.",
},
{
"Title": "Wrong Item Received",
"Content": "Good morning, I have a question about my recent order. I received the wrong item and I need to return it.",
},
{
"Title": "Return Defective Product",
"Content": "Hello, I have a question about the return policy for this product. I purchased it a few weeks ago and it is defective.",
},
]
response = co.rerank(
model="Cohere-rerank-v4.0-fast", # NOTE: For rerank v4, you must specify the model e.g. `Cohere-rerank-v4.0-fast` or `Cohere-rerank-v4.0-pro`
documents=[yaml.dump(doc, sort_keys=False) for doc in documents],
query="What emails have been about returning items?",
top_n=5,
)
print(response)
Output
id='7b32b918-e582-470c-9a12-450c1c2996a7' results=[V2RerankResponseResultsItem(index=7, relevance_score=0.70869666), V2RerankResponseResultsItem(index=4, relevance_score=0.6822351), V2RerankResponseResultsItem(index=8, relevance_score=0.52692705), V2RerankResponseResultsItem(index=2, relevance_score=0.5035156), V2RerankResponseResultsItem(index=6, relevance_score=0.44707403)] ...
Code that throws 500 internal server error with correct key
response = co.rerank(
model="Cohere-rerank-v4.0", # Model name was corrupted knowingly her
documents=[yaml.dump(doc, sort_keys=False) for doc in documents],
query="What emails have been about returning items?",
top_n=5,
)
print(response)
Reference used- https://github.com/Azure/azureml-examples/blob/main/sdk/python/foundation-models/cohere/rerank-cohere-client.ipynb
Please test above syntax and new foundry endpoint and share your observation if the issue still persits.
Thank you.