-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from andrewyng/add-mistral-provider
- Loading branch information
Showing
7 changed files
with
192 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ANTHROPIC_API_KEY="" | ||
GROQ_API_KEY="" | ||
MISTRAL_API_KEY="" | ||
OPENAI_API_KEY="" | ||
OLLAMA_API_URL="http://localhost:11434" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Provides the individual provider interfaces for each FM provider.""" | ||
|
||
from .openai_interface import OpenAIInterface | ||
from .groq_interface import GroqInterface | ||
from .anthropic_interface import AnthropicInterface | ||
from .groq_interface import GroqInterface | ||
from .mistral_interface import MistralInterface | ||
from .ollama_interface import OllamaInterface | ||
from .openai_interface import OpenAIInterface |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
|
||
from aimodels.framework import ProviderInterface | ||
|
||
|
||
class MistralInterface(ProviderInterface): | ||
"""Implements the provider interface for Mistral.""" | ||
|
||
def __init__(self): | ||
from mistralai.client import MistralClient | ||
|
||
self.mistral_client = MistralClient(api_key=os.getenv("MISTRAL_API_KEY")) | ||
|
||
def chat_completion_create(self, messages=None, model=None, temperature=0): | ||
"""Request chat completions from the Mistral API. | ||
Args: | ||
---- | ||
model (str): Identifies the specific provider/model to use. | ||
messages (list of dict): A list of message objects in chat history. | ||
temperature (float): The temperature to use in the completion. | ||
Returns: | ||
------- | ||
The API response with the completion result. | ||
""" | ||
from mistralai.models.chat_completion import ChatMessage | ||
|
||
messages = [ | ||
ChatMessage(role=message["role"], content=message["content"]) | ||
for message in messages | ||
] | ||
return self.mistral_client.chat( | ||
model=model, | ||
messages=messages, | ||
temperature=temperature, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters