cohere-ai / cohere-python

Python Library for Accessing the Cohere API
https://docs.cohere.ai
MIT License
286 stars 63 forks source link

Return json in response #475

Closed geweb7 closed 4 months ago

geweb7 commented 5 months ago

response = co.chat(message = "what day is it today?") print(response)

it seems to be plain text format:

text='Today is Friday, April 12, 2024.' generation_id='...' citations=None documents=None is_search_required=None search_queries=None search_results=None finish_reason='COMPLETE' tool_calls=None chat_history=[ChatMessage(role='USER', message='what day is it today?'), ChatMessage(role='CHATBOT', message='Today is Friday, April 12, 2024.')] meta=ApiMeta(api_version=ApiMetaApiVersion(version='1', is_deprecated=None, is_experimental=None), billed_units=ApiMetaBilledUnits(input_tokens=6, output_tokens=15, search_units=None, classifications=None), tokens=ApiMetaTokens(input_tokens=72, output_tokens=15), warnings=None) response_id='...'

how should we extract text from the response? Please return json in NONSTREAMEDCHATRESPONSE and update docs on getting response text.

BeatrixCohere commented 4 months ago

Are you able to get the text by: response = co.chat(message = "what day is it today?") print(response.text)

geweb7 commented 4 months ago

yes, now i use it like this, but feeling not sure it's the correct way.

the same with printing let's say output_tokens

BeatrixCohere commented 4 months ago

This is the correct way to access the text.