add aiassist.site

This commit is contained in:
ezerinz 2023-05-20 21:45:05 +08:00
parent 74f949e099
commit 8449728aa3
No known key found for this signature in database
GPG Key ID: 8713BDED6DE33C4D
2 changed files with 53 additions and 0 deletions

View File

@ -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)
```

View File

@ -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