diff options
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/Copilot.py | 17 | ||||
-rw-r--r-- | g4f/Provider/needs_auth/CopilotAccount.py | 3 | ||||
-rw-r--r-- | g4f/Provider/needs_auth/OpenaiChat.py | 2 |
3 files changed, 18 insertions, 4 deletions
diff --git a/g4f/Provider/Copilot.py b/g4f/Provider/Copilot.py index f10202bf..3bf6f193 100644 --- a/g4f/Provider/Copilot.py +++ b/g4f/Provider/Copilot.py @@ -23,9 +23,10 @@ except ImportError: from .base_provider import AbstractProvider, BaseConversation from .helper import format_prompt -from ..typing import CreateResult, Messages +from ..typing import CreateResult, Messages, ImageType from ..errors import MissingRequirementsError from ..requests.raise_for_status import raise_for_status +from ..image import to_bytes, is_accepted_format from .. import debug class Conversation(BaseConversation): @@ -43,6 +44,7 @@ class Copilot(AbstractProvider): url = "https://copilot.microsoft.com" working = True supports_stream = True + default_model = "Copilot" websocket_url = "wss://copilot.microsoft.com/c/api/chat?api-version=2" conversation_url = f"{url}/c/api/conversations" @@ -55,6 +57,7 @@ class Copilot(AbstractProvider): stream: bool = False, proxy: str = None, timeout: int = 900, + image: ImageType = None, conversation: Conversation = None, return_conversation: bool = False, **kwargs @@ -98,11 +101,21 @@ class Copilot(AbstractProvider): if debug.logging: print(f"Copilot: Use conversation: {conversation_id}") + images = [] + if image is not None: + data = to_bytes(image) + response = session.post( + "https://copilot.microsoft.com/c/api/attachments", + headers={"content-type": is_accepted_format(data)}, + data=data + ) + images.append({"type":"image", "url": response.json().get("url")}) + wss = session.ws_connect(cls.websocket_url) wss.send(json.dumps({ "event": "send", "conversationId": conversation_id, - "content": [{ + "content": [*images, { "type": "text", "text": prompt, }], diff --git a/g4f/Provider/needs_auth/CopilotAccount.py b/g4f/Provider/needs_auth/CopilotAccount.py index fa43867e..76e51278 100644 --- a/g4f/Provider/needs_auth/CopilotAccount.py +++ b/g4f/Provider/needs_auth/CopilotAccount.py @@ -5,4 +5,5 @@ from ..Copilot import Copilot class CopilotAccount(Copilot): needs_auth = True parent = "Copilot" - default_model = ""
\ No newline at end of file + default_model = "Copilot" + default_vision_model = default_model
\ No newline at end of file diff --git a/g4f/Provider/needs_auth/OpenaiChat.py b/g4f/Provider/needs_auth/OpenaiChat.py index 13e15f1d..22264dd9 100644 --- a/g4f/Provider/needs_auth/OpenaiChat.py +++ b/g4f/Provider/needs_auth/OpenaiChat.py @@ -396,7 +396,7 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin): f"{cls.url}/backend-anon/sentinel/chat-requirements" if cls._api_key is None else f"{cls.url}/backend-api/sentinel/chat-requirements", - json={"p": get_requirements_token(RequestConfig.proof_token)}, + json={"p": get_requirements_token(RequestConfig.proof_token) if RequestConfig.proof_token else None}, headers=cls._headers ) as response: cls._update_request_args(session) |