Skip to content

Commit

Permalink
change metadata to meta (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 authored Jan 8, 2024
1 parent 10dcef0 commit 9411c99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def run(self, messages: List[ChatMessage], generation_kwargs: Optional[Dict[str,
stream_chunk = self._build_chunk(chunk)
self.streaming_callback(stream_chunk)
chat_message = ChatMessage.from_assistant(content=response.texts)
chat_message.metadata.update(
chat_message.meta.update(
{
"model": self.model_name,
"usage": response.token_count,
Expand All @@ -180,9 +180,7 @@ def _build_chunk(self, chunk) -> StreamingChunk:
:return: The StreamingChunk.
"""
# if chunk.event_type == "text-generation":
chat_message = StreamingChunk(
content=chunk.text, metadata={"index": chunk.index, "event_type": chunk.event_type}
)
chat_message = StreamingChunk(content=chunk.text, meta={"index": chunk.index, "event_type": chunk.event_type})
return chat_message

def _build_message(self, cohere_response):
Expand All @@ -193,7 +191,7 @@ def _build_message(self, cohere_response):
"""
content = cohere_response.text
message = ChatMessage.from_assistant(content=content)
message.metadata.update(
message.meta.update(
{
"model": self.model_name,
"usage": cohere_response.token_count,
Expand Down
16 changes: 8 additions & 8 deletions integrations/cohere/tests/test_cohere_chat_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def mock_iter(self): # noqa: ARG001
)
@pytest.mark.integration
def test_live_run(self):
chat_messages = [ChatMessage(content="What's the capital of France", role=ChatRole.USER, name="", metadata={})]
chat_messages = [ChatMessage(content="What's the capital of France", role=ChatRole.USER, name="", meta={})]
component = CohereChatGenerator(
api_key=os.environ.get("COHERE_API_KEY"), generation_kwargs={"temperature": 0.8}
)
Expand Down Expand Up @@ -291,7 +291,7 @@ def __call__(self, chunk: StreamingChunk) -> None:
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content[0]

assert message.metadata["finish_reason"] == "COMPLETE"
assert message.meta["finish_reason"] == "COMPLETE"

assert callback.counter > 1
assert "Paris" in callback.responses
Expand All @@ -302,16 +302,16 @@ def __call__(self, chunk: StreamingChunk) -> None:
)
@pytest.mark.integration
def test_live_run_with_connector(self):
chat_messages = [ChatMessage(content="What's the capital of France", role=ChatRole.USER, name="", metadata={})]
chat_messages = [ChatMessage(content="What's the capital of France", role=ChatRole.USER, name="", meta={})]
component = CohereChatGenerator(
api_key=os.environ.get("COHERE_API_KEY"), generation_kwargs={"temperature": 0.8}
)
results = component.run(chat_messages, generation_kwargs={"connectors": [{"id": "web-search"}]})
assert len(results["replies"]) == 1
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content
assert message.metadata["documents"] is not None
assert message.metadata["citations"] is not None
assert message.meta["documents"] is not None
assert message.meta["citations"] is not None

@pytest.mark.skipif(
not os.environ.get("COHERE_API_KEY", None),
Expand All @@ -337,10 +337,10 @@ def __call__(self, chunk: StreamingChunk) -> None:
message: ChatMessage = results["replies"][0]
assert "Paris" in message.content[0]

assert message.metadata["finish_reason"] == "COMPLETE"
assert message.meta["finish_reason"] == "COMPLETE"

assert callback.counter > 1
assert "Paris" in callback.responses

assert message.metadata["documents"] is not None
assert message.metadata["citations"] is not None
assert message.meta["documents"] is not None
assert message.meta["citations"] is not None

0 comments on commit 9411c99

Please sign in to comment.