Merge pull request #578 from ezerinz/main

This commit is contained in:
xtekky 2023-05-21 10:42:56 +01:00 committed by GitHub
commit 261f4dbd20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 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

13
testing/aiassistest.py Normal file
View File

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