summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Opchatgpts.py
diff options
context:
space:
mode:
authorRyan Jordan <ryjordan@gmail.com>2023-09-06 02:39:57 +0200
committerGitHub <noreply@github.com>2023-09-06 02:39:57 +0200
commitf81e618958318a092ca4c70a1b3ea15260bda97c (patch)
tree3ce022a8d719011268da7f1a0befc97bf32a60d8 /g4f/Provider/Opchatgpts.py
parentfeat(docker): add Docker and Docker Compose support (diff)
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
downloadgpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.gz
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.bz2
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.lz
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.xz
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.zst
gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.zip
Diffstat (limited to 'g4f/Provider/Opchatgpts.py')
-rw-r--r--g4f/Provider/Opchatgpts.py72
1 files changed, 35 insertions, 37 deletions
diff --git a/g4f/Provider/Opchatgpts.py b/g4f/Provider/Opchatgpts.py
index 9daa0ed9..241646f0 100644
--- a/g4f/Provider/Opchatgpts.py
+++ b/g4f/Provider/Opchatgpts.py
@@ -1,3 +1,5 @@
+from __future__ import annotations
+
import requests
from ..typing import Any, CreateResult
@@ -5,33 +7,30 @@ from .base_provider import BaseProvider
class Opchatgpts(BaseProvider):
- url = "https://opchatgpts.net"
- working = True
+ url = "https://opchatgpts.net"
+ working = True
supports_gpt_35_turbo = True
@staticmethod
def create_completion(
model: str,
messages: list[dict[str, str]],
- stream: bool,
- **kwargs: Any,
- ) -> CreateResult:
- temperature = kwargs.get("temperature", 0.8)
- max_tokens = kwargs.get("max_tokens", 1024)
+ stream: bool, **kwargs: Any) -> CreateResult:
+
+ temperature = kwargs.get("temperature", 0.8)
+ max_tokens = kwargs.get("max_tokens", 1024)
system_prompt = kwargs.get(
"system_prompt",
- "Converse as if you were an AI assistant. Be friendly, creative.",
- )
+ "Converse as if you were an AI assistant. Be friendly, creative.")
+
payload = _create_payload(
- messages=messages,
- temperature=temperature,
- max_tokens=max_tokens,
- system_prompt=system_prompt,
- )
-
- response = requests.post(
- "https://opchatgpts.net/wp-json/ai-chatbot/v1/chat", json=payload
- )
+ messages = messages,
+ temperature = temperature,
+ max_tokens = max_tokens,
+ system_prompt = system_prompt)
+
+ response = requests.post("https://opchatgpts.net/wp-json/ai-chatbot/v1/chat", json=payload)
+
response.raise_for_status()
yield response.json()["reply"]
@@ -39,24 +38,23 @@ class Opchatgpts(BaseProvider):
def _create_payload(
messages: list[dict[str, str]],
temperature: float,
- max_tokens: int,
- system_prompt: str,
-):
+ max_tokens: int, system_prompt: str) -> dict:
+
return {
- "env": "chatbot",
- "session": "N/A",
- "prompt": "\n",
- "context": system_prompt,
- "messages": messages,
- "newMessage": messages[::-1][0]["content"],
- "userName": '<div class="mwai-name-text">User:</div>',
- "aiName": '<div class="mwai-name-text">AI:</div>',
- "model": "gpt-3.5-turbo",
- "temperature": temperature,
- "maxTokens": max_tokens,
- "maxResults": 1,
- "apiKey": "",
- "service": "openai",
- "embeddingsIndex": "",
- "stop": "",
+ "env" : "chatbot",
+ "session" : "N/A",
+ "prompt" : "\n",
+ "context" : system_prompt,
+ "messages" : messages,
+ "newMessage" : messages[::-1][0]["content"],
+ "userName" : '<div class="mwai-name-text">User:</div>',
+ "aiName" : '<div class="mwai-name-text">AI:</div>',
+ "model" : "gpt-3.5-turbo",
+ "temperature" : temperature,
+ "maxTokens" : max_tokens,
+ "maxResults" : 1,
+ "apiKey" : "",
+ "service" : "openai",
+ "embeddingsIndex" : "",
+ "stop" : "",
}