Skip to content

Commit

Permalink
api class
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gleeson committed Apr 16, 2024
1 parent d2e2d77 commit aac07f9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
AWS_SAGEMAKER_ENDPOINT = os.environ.get(
"AWS_SAGEMAKER_ENDPOINT", "llama-meta-textgeneration"
)

MODEL = "claude-v3-sonnet"
46 changes: 46 additions & 0 deletions hackathon/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import requests
import time

from config.settings import MODEL
# from config.settings import SUMMARISE_API
# from config.settings import SUMMARISE_URL
# from config.settings import FACTCHECK_API
# from config.settings import FACTCHECK_URL
# from config.settings import GLOSSERY_API
# from config.settings import GLOSSERY_URL

class API:

def __init__(self, api_key, url):
self.api_key = api_key
self.url = url
self.headers = {
"Content-Type": "application/json",
"X-API-Key": f"{self.api_key}",
}

def invoke_post(self, message):
post_data = {
"content": [
{
"contentType": "text",
"mediaType": "string",
"body": message
}
],
"model": MODEL
}
response = requests.post(self.url+ "/conversation", json=post_data, headers=self.headers)
json_respn = response.json()
return json_respn

def invoke_get(self, conversation_id, message_id = None ):
uri_path = "/conversation/ "+conversation_id
if message_id:
uri_path = uri_path + "/" + message_id
response = requests.get(
self.url + uri_path,
headers=self.headers,
)

return response

0 comments on commit aac07f9

Please sign in to comment.