Merge pull request #752 from pipecat-ai/mb/google-context-message-conversion
Use Google Gemini message format when adding message to the LLM context
This commit is contained in:
@@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Updated STT and TTS services with language options that match the supported
|
- Updated STT and TTS services with language options that match the supported
|
||||||
languages for each service.
|
languages for each service.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed Google Gemini message handling to properly convert appended messages to Gemini's required format
|
||||||
|
|
||||||
## [0.0.49] - 2024-11-17
|
## [0.0.49] - 2024-11-17
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -332,6 +332,22 @@ class GoogleLLMContext(OpenAILLMContext):
|
|||||||
self._messages[:] = messages
|
self._messages[:] = messages
|
||||||
self._restructure_from_openai_messages()
|
self._restructure_from_openai_messages()
|
||||||
|
|
||||||
|
def add_messages(self, messages: List):
|
||||||
|
# Convert each message individually
|
||||||
|
converted_messages = []
|
||||||
|
for msg in messages:
|
||||||
|
if isinstance(msg, glm.Content):
|
||||||
|
# Already in Gemini format
|
||||||
|
converted_messages.append(msg)
|
||||||
|
else:
|
||||||
|
# Convert from standard format to Gemini format
|
||||||
|
converted = self.from_standard_message(msg)
|
||||||
|
if converted is not None:
|
||||||
|
converted_messages.append(converted)
|
||||||
|
|
||||||
|
# Add the converted messages to our existing messages
|
||||||
|
self._messages.extend(converted_messages)
|
||||||
|
|
||||||
def get_messages_for_logging(self):
|
def get_messages_for_logging(self):
|
||||||
msgs = []
|
msgs = []
|
||||||
for message in self.messages:
|
for message in self.messages:
|
||||||
|
|||||||
Reference in New Issue
Block a user