Repository: explodinggradients/ragas
Issue: How to use AzureOpenai instance model inside RAGAS - [ not langchain]
Root cause: Interface Contract Mismatch

I  am having these secrets and this is how I use `gpt-4o` model:

```
from ragas import SingleTurnSample 
from ragas.metrics import ResponseRelevancy
import os
from openai import AzureOpenAI
from ragas import evaluate
import requests
```

**To get the secret key/Tokens**
```
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {
            'client_id': client_id,
            'client_secret': client_secret,
            'grant_type': 'client_credentials',
            'scope': 'openid email profile'
        }
       
response = requests.post(token_url, headers=headers, data=data)
dict_of_response_text = response.json()
token = dict_of_response_text.get("access_token")
```

**To see if model is working**

```
client = AzureOpenAI(
  azure_endpoint = params["azure_endpoint"], 
  api_key=token,  
  api_version=params["api_version"]
)

response = client.chat.completions.create(
    model=params["model"], # model = "deployment_name".
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
        {"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
        {"role": "user", "content": "Do other Azure AI services support this too?"}
    ],
 temperature=params["temperature"],
 # top_p=params["top_p"],
 max_tokens=params["max_tokens"]
    
)

```

I'm not using any langchain based famework.

Then I use this example to run:

https://docs.ragas.io/en/stable/concepts/metrics/available_metrics/answer_relevance/#response-relevancy

```
from ragas import SingleTurnSample 
from ragas.metrics import ResponseRelevancy

sample = SingleTurnSample(
        user_input="When was the first super bowl?",
        response="The first superbowl was held on Jan 15, 1967",
        retrieved_contexts=[
            "The First AFL–NFL World Championship Game was an American football game played on January 15, 1967, at the Los Angeles Memorial Coliseum in Los Angeles."
        ]
    )

scorer = ResponseRelevancy(llm=client)
await scorer.single_turn_ascore(sample)
```

Throws error:
AttributeError: 'AzureOpenAI' object has no attribute 'generate'

**So, how can I pass the instance inside ragas using the information I have above.** 


**How to pass model inside** `scorer = ResponseRelevancy(llm=client)`

I tried something like this:

```
azure_model=AzureChatOpenAI(
                api_version=config.pf_api_version,
                azure_endpoint=config.pf_oa_endpoint,
                azure_ad_token=token,
                max_tokens=config.max_tokens,
                model=config.pf_llm_deployment
            )

# init the embeddings for answer_relevancy, answer_correctness and answer_similarity
azure_embeddings = AzureOpenAIEmbeddings(
    openai_api_version=config.pf_api_version,
    azure_endpoint=config.pf_oa_endpoint_embed,
    azure_ad_token=token,
    model=config.pf_embedding_engine,
)


```

```
scorer = ResponseRelevancy(llm=azure_model)
await scorer.single_turn_ascore(sample)
```

Error

**TypeError: object of type 'StringPromptValue' has no len()**

Hi @pratikchhapolika, I'm also encountering the same issue. Following the same exact documentation in https://docs.ragas.io/en/latest/concepts/metrics/available_metrics/faithfulness/. But get the same error with you 

**TypeError: object of type 'StringPromptValue' has no len()**

May I know how you solved it? Thank you so much