diff options
author | Commenter123321 <36051603+Commenter123321@users.noreply.github.com> | 2023-10-09 18:02:06 +0200 |
---|---|---|
committer | Commenter123321 <36051603+Commenter123321@users.noreply.github.com> | 2023-10-09 18:02:06 +0200 |
commit | 119817c96349807efaf87ee432ce46446542b66a (patch) | |
tree | 1dbdf4d4dbf4f6c8a8247274ef500a2f1de765d1 /g4f/Provider/needs_auth/Raycast.py | |
parent | aivvm's no life creator keeps patching it, but I'm just better 😉 (diff) | |
parent | Merge branch 'main' of https://github.com/xtekky/gpt4free (diff) | |
download | gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.gz gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.bz2 gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.lz gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.xz gpt4free-119817c96349807efaf87ee432ce46446542b66a.tar.zst gpt4free-119817c96349807efaf87ee432ce46446542b66a.zip |
Diffstat (limited to 'g4f/Provider/needs_auth/Raycast.py')
-rw-r--r-- | g4f/Provider/needs_auth/Raycast.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/g4f/Provider/needs_auth/Raycast.py b/g4f/Provider/needs_auth/Raycast.py new file mode 100644 index 00000000..619b217b --- /dev/null +++ b/g4f/Provider/needs_auth/Raycast.py @@ -0,0 +1,72 @@ +from __future__ import annotations + +import json + +import requests + +from ...typing import Any, CreateResult +from ..base_provider import BaseProvider + + +class Raycast(BaseProvider): + url = "https://raycast.com" + supports_gpt_35_turbo = True + supports_gpt_4 = True + supports_stream = True + needs_auth = True + working = True + + @staticmethod + def create_completion( + model: str, + messages: list[dict[str, str]], + stream: bool, + **kwargs: Any, + ) -> CreateResult: + auth = kwargs.get('auth') + headers = { + 'Accept': 'application/json', + 'Accept-Language': 'en-US,en;q=0.9', + 'Authorization': f'Bearer {auth}', + 'Content-Type': 'application/json', + 'User-Agent': 'Raycast/0 CFNetwork/1410.0.3 Darwin/22.6.0', + } + parsed_messages = [] + for message in messages: + parsed_messages.append({ + 'author': message['role'], + 'content': {'text': message['content']} + }) + data = { + "debug": False, + "locale": "en-CN", + "messages": parsed_messages, + "model": model, + "provider": "openai", + "source": "ai_chat", + "system_instruction": "markdown", + "temperature": 0.5 + } + response = requests.post("https://backend.raycast.com/api/v1/ai/chat_completions", headers=headers, json=data, stream=True) + for token in response.iter_lines(): + if b'data: ' not in token: + continue + completion_chunk = json.loads(token.decode().replace('data: ', '')) + token = completion_chunk['text'] + if token != None: + yield token + + @classmethod + @property + def params(cls): + params = [ + ("model", "str"), + ("messages", "list[dict[str, str]]"), + ("stream", "bool"), + ("temperature", "float"), + ("top_p", "int"), + ("model", "str"), + ("auth", "str"), + ] + param = ", ".join([": ".join(p) for p in params]) + return f"g4f.provider.{cls.__name__} supports: ({param})" |