diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-08-20 05:49:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-20 05:49:53 +0200 |
commit | f55b24a9145d46ed207c120f27212af244223c13 (patch) | |
tree | 4ab04db3724741f1bb7688883fbb4dd9e1385f9a /g4f/Provider/Raycast.py | |
parent | ~ | Merge pull request #808 (diff) | |
parent | provider to Provider in testing (diff) | |
download | gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar.gz gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar.bz2 gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar.lz gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar.xz gpt4free-f55b24a9145d46ed207c120f27212af244223c13.tar.zst gpt4free-f55b24a9145d46ed207c120f27212af244223c13.zip |
Diffstat (limited to 'g4f/Provider/Raycast.py')
-rw-r--r-- | g4f/Provider/Raycast.py | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/g4f/Provider/Raycast.py b/g4f/Provider/Raycast.py index 49481202..1f13c9fa 100644 --- a/g4f/Provider/Raycast.py +++ b/g4f/Provider/Raycast.py @@ -1,18 +1,17 @@ import json - import requests - -from ..Provider.base_provider import BaseProvider from ..typing import Any, CreateResult +from .base_provider import BaseProvider class Raycast(BaseProvider): - url = "https://backend.raycast.com/api/v1/ai/chat_completions" - working = True - supports_stream = True + url = "https://raycast.com" + # model = ['gpt-3.5-turbo', 'gpt-4'] supports_gpt_35_turbo = True supports_gpt_4 = True + supports_stream = True needs_auth = True + working = True @staticmethod def create_completion( @@ -21,20 +20,20 @@ class Raycast(BaseProvider): stream: bool, **kwargs: Any, ) -> CreateResult: - auth = kwargs.get("auth") - + 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", + '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: list[dict[str, Any]] = [] + parsed_messages = [] for message in messages: - parsed_messages.append( - {"author": message["role"], "content": {"text": message["content"]}} - ) + parsed_messages.append({ + 'author': message['role'], + 'content': {'text': message['content']} + }) data = { "debug": False, "locale": "en-CN", @@ -43,14 +42,28 @@ class Raycast(BaseProvider): "provider": "openai", "source": "ai_chat", "system_instruction": "markdown", - "temperature": 0.5, + "temperature": 0.5 } - url = "https://backend.raycast.com/api/v1/ai/chat_completions" - response = requests.post(url, headers=headers, json=data, stream=True) + 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: + if b'data: ' not in token: continue - completion_chunk = json.loads(token.decode().replace("data: ", "")) - token = completion_chunk["text"] + 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})" |