Spaces:
Sleeping
Sleeping
Download text_collection.py from Vignesh5656/transformation-api: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/Vignesh5656/transformation-api/resolve/main/text_collection.py
- Command line
-
hf download hf://spaces/Vignesh5656/transformation-api/text_collection.py
-
curl -L -o text_collection.py https://huggingface.co/spaces/Vignesh5656/transformation-api/resolve/main/text_collection.py
2.26 kB
| import json | |
| from util.horizon_helper import sendHttpRequest | |
| from typing import Dict | |
| class ContextMessage(Dict): | |
| role: str | |
| content: str | |
| # text chats | |
| def chats(authToken = "", address = "", role = 'user', content = 'How are you today?', messageObjects = []): | |
| messages = [] | |
| if len(messageObjects) > 0: | |
| for x in messageObjects: | |
| messages.append(x) | |
| # Add a message using function params | |
| message = ContextMessage() | |
| message["role"] = role | |
| message["content"] = content | |
| messages.append(message) | |
| payload = json.dumps({ | |
| "messages": | |
| messages | |
| }) | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer " + authToken | |
| } | |
| response = sendHttpRequest(data = payload, header = headers, method = "POST", address = address, endpoint = "/v2/text/chats") | |
| return response | |
| # text completions | |
| def completions(authToken = "", address = ""): | |
| payload = json.dumps( | |
| { | |
| "prompt": "Twinkle twinkle" | |
| } | |
| ) | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer " + authToken | |
| } | |
| response = sendHttpRequest(data = payload, header = headers, method = "POST", address = address, endpoint = "/v2/text/completions") | |
| return response | |
| # text translations | |
| def translations(authToken = "", address = ""): | |
| payload = json.dumps( | |
| { | |
| "text": "Twinkle twinkle", | |
| "sourceLanguage": "en", | |
| "targetLanguage": "fr" | |
| } | |
| ) | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer " + authToken | |
| } | |
| response = sendHttpRequest(data = payload, header = headers, method = "POST", address = address, endpoint = "/v2/text/translations") | |
| return response | |
| # text detections | |
| def detections(authToken = "", address = ""): | |
| payload = json.dumps( | |
| { | |
| "text": "Twinkle twinkle" | |
| } | |
| ) | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": "Bearer " + authToken | |
| } | |
| response = sendHttpRequest(data = payload, header = headers, method = "POST", address = address, endpoint = "/v2/text/detections") | |
| return response | |