diff options
-rw-r--r-- | gpt4free/aiassist/README.md | 19 | ||||
-rw-r--r-- | gpt4free/aiassist/__init__.py | 34 | ||||
-rw-r--r-- | testing/aiassistest.py | 13 |
3 files changed, 66 insertions, 0 deletions
diff --git a/gpt4free/aiassist/README.md b/gpt4free/aiassist/README.md new file mode 100644 index 00000000..b6101784 --- /dev/null +++ b/gpt4free/aiassist/README.md @@ -0,0 +1,19 @@ +aiassist.site + +### Example: `aiassist` <a name="example-assist"></a> + +```python +import aiassist + +question1 = "Who won the world series in 2020?" +req = aiassist.Completion.create(prompt=question1) +answer = req["text"] +message_id = req["parentMessageId"] + +question2 = "Where was it played?" +req2 = aiassist.Completion.create(prompt=question2, parentMessageId=message_id) +answer2 = req2["text"] + +print(answer) +print(answer2) +``` diff --git a/gpt4free/aiassist/__init__.py b/gpt4free/aiassist/__init__.py new file mode 100644 index 00000000..10082c22 --- /dev/null +++ b/gpt4free/aiassist/__init__.py @@ -0,0 +1,34 @@ +import json +import requests + + +class Completion: + @staticmethod + def create( + systemMessage: str = "You are a helpful assistant", + prompt: str = "", + parentMessageId: str = "", + temperature: float = 0.8, + top_p: float = 1, + ): + json_data = { + "prompt": prompt, + "options": {"parentMessageId": parentMessageId}, + "systemMessage": systemMessage, + "temperature": temperature, + "top_p": top_p, + } + + url = "http://43.153.7.56:8080/api/chat-process" + request = requests.post(url, json=json_data) + content = request.content + + response = Completion.__load_json(content) + return response + + @classmethod + def __load_json(cls, content) -> dict: + decode_content = str(content.decode("utf-8")) + split = decode_content.rsplit("\n", 1)[1] + to_json = json.loads(split) + return to_json diff --git a/testing/aiassistest.py b/testing/aiassistest.py new file mode 100644 index 00000000..57a34f15 --- /dev/null +++ b/testing/aiassistest.py @@ -0,0 +1,13 @@ +import aiassist + +question1 = "Who won the world series in 2020?" +req = aiassist.Completion.create(prompt=question1) +answer = req["text"] +message_id = req["parentMessageId"] + +question2 = "Where was it played?" +req2 = aiassist.Completion.create(prompt=question2, parentMessageId=message_id) +answer2 = req2["text"] + +print(answer) +print(answer2) |