Created
August 10, 2023 03:39
-
-
Save ranfysvalle02/f62306a4edf0b9497b1a456604963a60 to your computer and use it in GitHub Desktop.
Mendable.AI Wrapper Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def start_conversation(): | |
| url = "https://api.mendable.ai/v0/newConversation" | |
| payload = { | |
| "api_key": "API_KEY_GOES_HERE" | |
| } | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| response = requests.post(url, json=payload, headers=headers) | |
| print(response.json()) | |
| return (response.json()) | |
| def rate_msg(msg_id,msg_rating): | |
| url = "https://api.mendable.ai/v0/rateMessage" | |
| payload = { | |
| "api_key": "API_KEY_GOES_HERE", | |
| "message_id": msg_id, | |
| "rating_value": msg_rating | |
| } | |
| print(payload) | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| response = requests.post(url, json=payload, headers=headers) | |
| print(response.text) | |
| return (response.text) | |
| def start_new_chat(Q): | |
| url = "https://api.mendable.ai/v0/mendableChat" | |
| payload = { | |
| "api_key": "API_KEY_GOES_HERE", | |
| "question": str(Q), | |
| "history": [ | |
| #{ | |
| # "prompt": "How do I create a new project?", | |
| # "response": "You can create a new project by going to the projects page and clicking the new project button." | |
| #} | |
| ], | |
| "conversation_id": (start_conversation()['conversation_id']), | |
| "shouldStream":False | |
| } | |
| headers = { | |
| "Content-Type": "application/json" | |
| } | |
| response = requests.post(url, json=payload, headers=headers) | |
| response_json = response.json() | |
| if response_json.get('answer') and response_json['answer'].get('text'): | |
| print(response_json.keys()) | |
| #print('message_id:'+str(response_json['message_id'])) | |
| #print('sources:'+str(response_json['sources'])) | |
| #print('answer:'+str(response_json['answer'])) | |
| return response_json | |
| r = start_new_chat("How do I create a new Cluster to Cluster Sync process?") | |
| print(r['message_id']) | |
| print("NOW LETS RATE IT POSITIVE") | |
| print(rate_msg(r['message_id'],1)) | |
| #print("NOW LETS RATE IT NEGATIVE") | |
| #print(rate_msg(r['message_id'],-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment