Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mistral model client integration #286

Open
fm1320 opened this issue Nov 27, 2024 · 5 comments
Open

Mistral model client integration #286

fm1320 opened this issue Nov 27, 2024 · 5 comments
Labels
[adalflow] suggest integration Add a new model_client, db retriever, etc in /adalflow help wanted Need helps with input, discussion, review, and PR submission.

Comments

@fm1320
Copy link
Contributor

fm1320 commented Nov 27, 2024

Description & Motivation

As part of extending Adalflow's capability we want to integrate Mistral as a provider

Pitch

No response

Provider POC

No response

Additional context

No response

@fm1320 fm1320 added the help wanted Need helps with input, discussion, review, and PR submission. label Nov 27, 2024
@adjahossoualexandre
Copy link

Proposal

I will wrap Mistral text generation and embedding endpoints into a concrete implementation of the 6 ModelClient main methods.

I will use Mistal SDK.

from adalflow.core.model_client import ModelClient

def MistralClient(ModelClient):

    def __init__(self, model_name: Optional[str] = None) -> None:
        super().__init__()
        self._model_name = model_name

    def init_sync_client(self):
        pass

    def convert_inputs_to_api_kwargs(
        self,
        input: Any,  # for retriever, it is a single query,
        model_kwargs: dict = {},
        model_type: ModelType = ModelType.UNDEFINED,
    ) -> dict:
        pass

    def parse_embedding_response(self, response: Any) -> EmbedderOutput:
        pass

    def parse_chat_completion(self, completion: Any) -> GeneratorOutput:
        pass

    def call(self, api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED):
        pass

Regarding the init_async_client() method, I'm not sure how to implement it since the SDK has no dedicated method for it. Any suggestions?

@liyin2015 liyin2015 added the [adalflow] suggest integration Add a new model_client, db retriever, etc in /adalflow label Dec 3, 2024
@fm1320
Copy link
Contributor Author

fm1320 commented Jan 14, 2025

@adjahossoualexandre So in adalflow/adalflow/components/model_client basically you would create a new model client .py file similar to the example of the openai or other clients you see there

@adjahossoualexandre
Copy link

@fm1320 Yes, exactly. The only thing I'm not sure about is the init_async_client() because the SDK has no dedicated method for it but instead uses async def. Do you have any suggestions?

@fm1320
Copy link
Contributor Author

fm1320 commented Jan 14, 2025

Maybe wrap the synchronous client that makes the API call for async usage ? This is my rough idea, feel free to start the PR and I will adapt this part if needed

async def acall(self, api_kwargs: Dict = {}):
        response = await asyncio.to_thread(self.call, api_kwargs)
        return response
        
        
# Using the client
async def example():
    client = MistralClient()
    

    response = await client.acall(
        {"prompt": "Hello!"},
        model_type=ModelType.LLM
    )
    return response

@adjahossoualexandre
Copy link

I'll try to do that thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[adalflow] suggest integration Add a new model_client, db retriever, etc in /adalflow help wanted Need helps with input, discussion, review, and PR submission.
Projects
None yet
Development

No branches or pull requests

3 participants