----------------------
To get the string of the response from the reformatted text using the
acomplete
method, you can access the
text
attribute of the
CompletionResponse
object returned by the method. Here's how you can do it:
from llama_index.llms import OpenAI
llm = OpenAI()
resp = await llm.acomplete("Reformat the following text: [Your text here]")
reformatted_text = resp.text
print(reformatted_text)
This approach is consistent across different LLM implementations in LlamaIndex. For example, the same pattern works for other LLMs like Cohere, Anthropic, or custom implementations:
- For Cohere:
```python
from llama_index.llms.cohere import Cohere
llm = Cohere(model="command", api_key=api_key)
resp = await llm.acomplete("Reformat the following text: [Your text here]")
reformatted_text = resp.text
print(reformatted_text)
[Source](<https://docs.llamaindex.ai/en/latest/examples/llm/cohere/#async>)
2. For Anthropic:
python
from llama_index.multi_modal_llms.anthropic import AnthropicMultiModal
llm = AnthropicMultiModal()
resp = await llm.acomplete("Reformat the following text: [Your text here]", image_documents=[])
reformatted_text = resp.text
print(reformatted_text)
``
[Source](<https://docs.llamaindex.ai/en/latest/api_reference/multi_modal_llms/anthropic/#llama_index.multi_modal_llms.anthropic.AnthropicMultiModal>)
The
CompletionResponse
object returned by
acomplete
contains the reformatted text in its
text
attribute. By accessing
resp.text`, you get the string representation of the LLM's response, which in this case would be the reformatted text.