AWS SDK for C++

AWS SDK for C++ Version 1.11.440

Loading...
Searching...
No Matches
ConverseStreamHandler.h
1
6#pragma once
7#include <aws/core/utils/HashingUtils.h>
8#include <aws/core/utils/event/EventStreamHandler.h>
9#include <aws/core/client/AWSError.h>
10#include <aws/bedrock-runtime/BedrockRuntime_EXPORTS.h>
11#include <aws/bedrock-runtime/BedrockRuntimeErrors.h>
12
13#include <aws/bedrock-runtime/model/ConverseStreamInitialResponse.h>
14#include <aws/bedrock-runtime/model/MessageStartEvent.h>
15#include <aws/bedrock-runtime/model/ContentBlockStartEvent.h>
16#include <aws/bedrock-runtime/model/ContentBlockDeltaEvent.h>
17#include <aws/bedrock-runtime/model/ContentBlockStopEvent.h>
18#include <aws/bedrock-runtime/model/MessageStopEvent.h>
19#include <aws/bedrock-runtime/model/ConverseStreamMetadataEvent.h>
20
21namespace Aws
22{
23namespace BedrockRuntime
24{
25namespace Model
26{
28 {
37 };
38
40 {
41 typedef std::function<void(const ConverseStreamInitialResponse&)> ConverseStreamInitialResponseCallback;
42 typedef std::function<void(const ConverseStreamInitialResponse&, const Utils::Event::InitialResponseType)> ConverseStreamInitialResponseCallbackEx;
43 typedef std::function<void(const MessageStartEvent&)> MessageStartEventCallback;
44 typedef std::function<void(const ContentBlockStartEvent&)> ContentBlockStartEventCallback;
45 typedef std::function<void(const ContentBlockDeltaEvent&)> ContentBlockDeltaEventCallback;
46 typedef std::function<void(const ContentBlockStopEvent&)> ContentBlockStopEventCallback;
47 typedef std::function<void(const MessageStopEvent&)> MessageStopEventCallback;
48 typedef std::function<void(const ConverseStreamMetadataEvent&)> ConverseStreamMetadataEventCallback;
49 typedef std::function<void(const Aws::Client::AWSError<BedrockRuntimeErrors>& error)> ErrorCallback;
50
51 public:
52 AWS_BEDROCKRUNTIME_API ConverseStreamHandler();
53 AWS_BEDROCKRUNTIME_API ConverseStreamHandler& operator=(const ConverseStreamHandler&) = default;
54
55 AWS_BEDROCKRUNTIME_API virtual void OnEvent() override;
56
58
64 inline void SetInitialResponseCallbackEx(const ConverseStreamInitialResponseCallbackEx& callback) { m_onInitialResponse = callback; }
68 inline void SetInitialResponseCallback(const ConverseStreamInitialResponseCallback& noArgCallback)
69 {
70 m_onInitialResponse = [noArgCallback](const ConverseStreamInitialResponse& rs, const Utils::Event::InitialResponseType) { return noArgCallback(rs); };
71 }
73 inline void SetMessageStartEventCallback(const MessageStartEventCallback& callback) { m_onMessageStartEvent = callback; }
74 inline void SetContentBlockStartEventCallback(const ContentBlockStartEventCallback& callback) { m_onContentBlockStartEvent = callback; }
75 inline void SetContentBlockDeltaEventCallback(const ContentBlockDeltaEventCallback& callback) { m_onContentBlockDeltaEvent = callback; }
76 inline void SetContentBlockStopEventCallback(const ContentBlockStopEventCallback& callback) { m_onContentBlockStopEvent = callback; }
77 inline void SetMessageStopEventCallback(const MessageStopEventCallback& callback) { m_onMessageStopEvent = callback; }
78 inline void SetConverseStreamMetadataEventCallback(const ConverseStreamMetadataEventCallback& callback) { m_onConverseStreamMetadataEvent = callback; }
79 inline void SetOnErrorCallback(const ErrorCallback& callback) { m_onError = callback; }
80
81 inline ConverseStreamInitialResponseCallbackEx& GetInitialResponseCallbackEx() { return m_onInitialResponse; }
82
83 private:
84 AWS_BEDROCKRUNTIME_API void HandleEventInMessage();
85 AWS_BEDROCKRUNTIME_API void HandleErrorInMessage();
86 AWS_BEDROCKRUNTIME_API void MarshallError(const Aws::String& errorCode, const Aws::String& errorMessage);
87
88 ConverseStreamInitialResponseCallbackEx m_onInitialResponse;
89 MessageStartEventCallback m_onMessageStartEvent;
90 ContentBlockStartEventCallback m_onContentBlockStartEvent;
91 ContentBlockDeltaEventCallback m_onContentBlockDeltaEvent;
92 ContentBlockStopEventCallback m_onContentBlockStopEvent;
93 MessageStopEventCallback m_onMessageStopEvent;
94 ConverseStreamMetadataEventCallback m_onConverseStreamMetadataEvent;
95 ErrorCallback m_onError;
96 };
97
98namespace ConverseStreamEventMapper
99{
101
103} // namespace ConverseStreamEventMapper
104} // namespace Model
105} // namespace BedrockRuntime
106} // namespace Aws
AWS_BEDROCKRUNTIME_API ConverseStreamHandler & operator=(const ConverseStreamHandler &)=default
void SetInitialResponseCallbackEx(const ConverseStreamInitialResponseCallbackEx &callback)
void SetInitialResponseCallback(const ConverseStreamInitialResponseCallback &noArgCallback)
void SetOnErrorCallback(const ErrorCallback &callback)
void SetMessageStartEventCallback(const MessageStartEventCallback &callback)
virtual AWS_BEDROCKRUNTIME_API void OnEvent() override
void SetConverseStreamMetadataEventCallback(const ConverseStreamMetadataEventCallback &callback)
void SetContentBlockStartEventCallback(const ContentBlockStartEventCallback &callback)
void SetContentBlockStopEventCallback(const ContentBlockStopEventCallback &callback)
ConverseStreamInitialResponseCallbackEx & GetInitialResponseCallbackEx()
void SetContentBlockDeltaEventCallback(const ContentBlockDeltaEventCallback &callback)
void SetMessageStopEventCallback(const MessageStopEventCallback &callback)
AWS_BEDROCKRUNTIME_API ConverseStreamEventType GetConverseStreamEventTypeForName(const Aws::String &name)
AWS_BEDROCKRUNTIME_API Aws::String GetNameForConverseStreamEventType(ConverseStreamEventType value)
std::basic_string< char, std::char_traits< char >, Aws::Allocator< char > > String