deepset-ai / haystack-integrations

🚀 A list of Haystack Integrations, maintained by the community or deepset.
48 stars 62 forks source link

Add Mistral Integration page #121

Closed TuanaCelik closed 6 months ago

TuanaCelik commented 7 months ago

Currently, Mistral AI is supported via the OpenAIGenerator simply by providing the right model and API key. Let's add an integration page for Mistral which is slightly different to the rest:

We can explore adding full functionality as a separate integration next, and change the content of the integration tile accordingly.

### Tasks
- [ ] https://github.com/deepset-ai/haystack-integrations/issues/142
anakin87 commented 7 months ago

This works:

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage

api_key = "MISTRAL-API-KEY"
model = "mistral-medium"

client = OpenAIChatGenerator(
    api_key=api_key, model_name=model, api_base_url="https://api.mistral.ai/v1"
)

response = client.run(
    messages=[ChatMessage.from_user("What is the best French cheese?")]
)
print(response)
anakin87 commented 7 months ago

Embedders

from haystack.components.embedders import OpenAITextEmbedder

api_key = "MISTRAL-API-KEY"
model = "mistral-embed"

embedder = OpenAITextEmbedder(api_key=api_key, model_name=model, api_base_url="https://api.mistral.ai/v1")

response = embedder.run(text="What is the best French cheese?")
print(response)
# {'embedding': [-0.0186004638671875, ...],
# 'meta': {'model': 'mistral-embed', 
#'usage': {'prompt_tokens': 9, 'total_tokens': 9, 'completion_tokens': 0}}}
annthurium commented 7 months ago

https://github.com/deepset-ai/haystack-integrations/pull/125