XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

refactor(etc/tool/create_provider.py): enhance provider template and functionality

3dcacd84
kqlio67 <kqlio67@users.noreply.github.com>
提交于

代码差异

1 个文件 +36 -13
Modified etc/tool/create_provider.py +36 -13
@@ -33,14 +33,35 @@ from __future__ import annotations
33 33 from aiohttp import ClientSession
34 34
35 35 from ..typing import AsyncResult, Messages
36 from .base_provider import AsyncGeneratorProvider
36 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
37 37 from .helper import format_prompt
38 38
39 39
40 class ChatGpt(AsyncGeneratorProvider):
41 url = "https://chat-gpt.com"
40 class {name}(AsyncGeneratorProvider, ProviderModelMixin):
41 label = ""
42 url = "https://example.com"
43 api_endpoint = "https://example.com/api/completion"
42 44 working = True
43 supports_gpt_35_turbo = True
45 needs_auth = False
46 supports_stream = True
47 supports_system_message = True
48 supports_message_history = True
49
50 default_model = ''
51 models = ['', '']
52
53 model_aliases = {
54 "alias1": "model1",
55 }
56
57 @classmethod
58 def get_model(cls, model: str) -> str:
59 if model in cls.models:
60 return model
61 elif model in cls.model_aliases:
62 return cls.model_aliases[model]
63 else:
64 return cls.default_model
44 65
45 66 @classmethod
46 67 async def create_async_generator(
@@ -50,19 +71,21 @@ class ChatGpt(AsyncGeneratorProvider):
50 71 proxy: str = None,
51 72 **kwargs
52 73 ) -> AsyncResult:
53 headers = {
54 "authority": "chat-gpt.com",
74 model = cls.get_model(model)
75
76 headers = {{
77 "authority": "example.com",
55 78 "accept": "application/json",
56 79 "origin": cls.url,
57 "referer": f"{cls.url}/chat",
58 }
80 "referer": f"{{cls.url}}/chat",
81 }}
59 82 async with ClientSession(headers=headers) as session:
60 83 prompt = format_prompt(messages)
61 data = {
84 data = {{
62 85 "prompt": prompt,
63 "purpose": "",
64 }
65 async with session.post(f"{cls.url}/api/chat", json=data, proxy=proxy) as response:
86 "model": model,
87 }}
88 async with session.post(f"{{cls.url}}/api/chat", json=data, proxy=proxy) as response:
66 89 response.raise_for_status()
67 90 async for chunk in response.content:
68 91 if chunk:
@@ -78,7 +101,7 @@ Create a provider from a cURL command. The command is:
78 101 {command}
79 102 ```
80 103 A example for a provider:
81 ```py
104 ```python
82 105 {example}
83 106 ```
84 107 The name for the provider class: