When we only need the content of the first message.
(completion: ChatCompletion)
| 66 | log = logging.getLogger(__name__) |
| 67 | |
| 68 | def get_first_message_content(completion: ChatCompletion) -> str: |
| 69 | """When we only need the content of the first message.""" |
| 70 | log.info(f"🔍 get_first_message_content called with: {type(completion)}") |
| 71 | log.debug(f"raw completion: {completion}") |
| 72 | |
| 73 | try: |
| 74 | if hasattr(completion, 'choices') and len(completion.choices) > 0: |
| 75 | choice = completion.choices[0] |
| 76 | if hasattr(choice, 'message') and hasattr(choice.message, 'content'): |
| 77 | content = choice.message.content |
| 78 | log.info(f"✅ Successfully extracted content: {type(content)}, length: {len(content) if content else 0}") |
| 79 | return content |
| 80 | else: |
| 81 | log.error("❌ Choice doesn't have message.content") |
| 82 | return str(completion) |
| 83 | else: |
| 84 | log.error("❌ Completion doesn't have choices") |
| 85 | return str(completion) |
| 86 | except Exception as e: |
| 87 | log.error(f"❌ Error in get_first_message_content: {e}") |
| 88 | return str(completion) |
| 89 | |
| 90 | |
| 91 | def parse_stream_response(completion: ChatCompletionChunk) -> str: |
nothing calls this directly
no outgoing calls
no test coverage detected