Skip to content

Commit

Permalink
add meta to return message
Browse files Browse the repository at this point in the history
  • Loading branch information
AlistairLR112 committed Feb 4, 2024
1 parent 8137674 commit 19f9d9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _create_json_payload(self, text: str, generation_kwargs: Optional[Dict[str,
"""
return {"model": self.model, "prompt": text, "options": {**self.generation_kwargs, **(generation_kwargs or {})}}

@component.output_types(embedding=List[float])
@component.output_types(embedding=List[float], meta=Dict[str, Any])
def run(self, text: str, generation_kwargs: Optional[Dict[str, Any]] = None):
"""
Run an Ollama Model on a given chat history.
Expand All @@ -55,4 +55,7 @@ def run(self, text: str, generation_kwargs: Optional[Dict[str, Any]] = None):

response.raise_for_status()

return response.json()
result = response.json()
result["meta"] = {"model": self.model, "duration": response.elapsed}

return result
4 changes: 3 additions & 1 deletion integrations/ollama/tests/test_text_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_init(self):
assert embedder.url == "http://my-custom-endpoint:11434/api/embeddings"
assert embedder.model == "llama2"

@pytest.mark.integration
def test_model_not_found(self):
embedder = OllamaTextEmbedder(model="cheese")

Expand All @@ -33,9 +34,10 @@ def test_model_not_found(self):

@pytest.mark.integration
def test_run(self):
embedder = OllamaTextEmbedder()
embedder = OllamaTextEmbedder(model="orca-mini")

reply = embedder.run("hello")

assert isinstance(reply, dict)
assert all(isinstance(element, float) for element in reply["embedding"])
assert reply["meta"]["model"] == "orca-mini"

0 comments on commit 19f9d9f

Please sign in to comment.