diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 10:23:24 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-11-19 10:23:24 +0100 |
commit | 7c10a036ed63b0a14f69b27552801dde4f220b4e (patch) | |
tree | bb63fe93fdad43581c64c23b92eb773b4ec0263e /g4f/Provider/Copilot.py | |
parent | Update unittests (diff) | |
download | gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar.gz gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar.bz2 gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar.lz gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar.xz gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.tar.zst gpt4free-7c10a036ed63b0a14f69b27552801dde4f220b4e.zip |
Diffstat (limited to 'g4f/Provider/Copilot.py')
-rw-r--r-- | g4f/Provider/Copilot.py | 17 |
1 files changed, 15 insertions, 2 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, }], |