meta-llama / llama-stack-client-python

Python SDK for Llama Stack
Apache License 2.0
77 stars 21 forks source link

How Can I Filter The ChatCompletionResponse Result #27

Closed dawenxi-007 closed 2 weeks ago

dawenxi-007 commented 2 weeks ago

I am following the instructions here to run a simple inferencing with Llama model.

The printed response from client.inference.chat_completion gave the a lot of other information besides the output content, as the following:

ChatCompletionResponse(completion_message=CompletionMessage(content='Here is a 2 sentence poem about the moon:\n\nThe moon glows bright in the midnight sky,\nA silver beacon, passing us by.', role='assistant', stop_reason='end_of_turn', tool_calls=[]), logprobs=None)

How can I just generate the content with the desired format? Basically, filtering out the content from all the response output.

ashwinb commented 2 weeks ago

Just do

response = client.inference.chat_completion(...)
print(response.completion_message.content)
dawenxi-007 commented 2 weeks ago

Thank you! It works as expected.