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

Tentative Fix for Mistral Fix #985

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions instructor/client_mistral.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
# Future imports to ensure compatibility with Python 3.9
from __future__ import annotations

import mistralai.client
import mistralai.async_client as mistralaiasynccli

from mistralai import Mistral

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

"Mistral" is unknown import symbol (reportAttributeAccessIssue)

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "Mistral" is unknown (reportUnknownVariableType)

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

"Mistral" is unknown import symbol (reportAttributeAccessIssue)

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of "Mistral" is unknown (reportUnknownVariableType)

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

"Mistral" is unknown import symbol (reportAttributeAccessIssue)

Check failure on line 5 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of "Mistral" is unknown (reportUnknownVariableType)
import instructor
from typing import overload, Any
from typing import overload, Any, Literal


@overload
def from_mistral(
client: mistralai.client.MistralClient,
client: Mistral,

Check failure on line 12 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 12 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 12 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of parameter "client" is unknown (reportUnknownParameterType)
mode: instructor.Mode = instructor.Mode.MISTRAL_TOOLS,
use_async: Literal[False] = False,
**kwargs: Any,
) -> instructor.Instructor: ...


@overload
def from_mistral(
client: mistralaiasynccli.MistralAsyncClient,
client: Mistral,

Check failure on line 21 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 21 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 21 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of parameter "client" is unknown (reportUnknownParameterType)
mode: instructor.Mode = instructor.Mode.MISTRAL_TOOLS,
use_async: Literal[True] = True,
**kwargs: Any,
) -> instructor.AsyncInstructor: ...


def from_mistral(
client: mistralai.client.MistralClient | mistralaiasynccli.MistralAsyncClient,
client: Mistral,

Check failure on line 29 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 29 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of parameter "client" is unknown (reportUnknownParameterType)

Check failure on line 29 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of parameter "client" is unknown (reportUnknownParameterType)
mode: instructor.Mode = instructor.Mode.MISTRAL_TOOLS,
use_async: bool = False,
**kwargs: Any,
) -> instructor.Instructor | instructor.AsyncInstructor:
assert mode in {
instructor.Mode.MISTRAL_TOOLS,
}, "Mode be one of {instructor.Mode.MISTRAL_TOOLS}"

assert isinstance(
client, (mistralai.client.MistralClient, mistralaiasynccli.MistralAsyncClient)
), "Client must be an instance of mistralai.client.MistralClient or mistralai.async_cli.MistralAsyncClient"
client, (Mistral)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isinstance check should use a tuple for the second argument. Use (Mistral,) instead of (Mistral). This ensures it's treated as a tuple.

Suggested change
client, (Mistral)
client, (Mistral,)

), "Client must be an instance of mistralai.Mistral"

if isinstance(client, mistralai.client.MistralClient):
if not use_async:
return instructor.Instructor(
client=client,

Check failure on line 44 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument type is unknown   Argument corresponds to parameter "client" in function "__init__" (reportUnknownArgumentType)

Check failure on line 44 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Argument type is unknown   Argument corresponds to parameter "client" in function "__init__" (reportUnknownArgumentType)

Check failure on line 44 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Argument type is unknown   Argument corresponds to parameter "client" in function "__init__" (reportUnknownArgumentType)
create=instructor.patch(create=client.chat, mode=mode),
create=instructor.patch(create=client.chat.complete, mode=mode),

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "chat" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "complete" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Argument type is unknown   Argument corresponds to parameter "create" in function "patch" (reportUnknownArgumentType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of "chat" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Type of "complete" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.10)

Argument type is unknown   Argument corresponds to parameter "create" in function "patch" (reportUnknownArgumentType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of "chat" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Type of "complete" is unknown (reportUnknownMemberType)

Check failure on line 45 in instructor/client_mistral.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.9)

Argument type is unknown   Argument corresponds to parameter "create" in function "patch" (reportUnknownArgumentType)
provider=instructor.Provider.MISTRAL,
mode=mode,
**kwargs,
Expand All @@ -48,7 +51,7 @@
else:
return instructor.AsyncInstructor(
client=client,
create=instructor.patch(create=client.chat, mode=mode),
create=instructor.patch(create=client.chat.complete_async, mode=mode),
provider=instructor.Provider.MISTRAL,
mode=mode,
**kwargs,
Expand Down
Loading