Initial commit
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
import os
|
||||
import requests
|
||||
from base64 import b64decode
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
def get_basic_auth_header(token: str) -> dict:
|
||||
"""Decode the base64 token and return the appropriate header."""
|
||||
decoded_token = b64decode(token).decode('utf-8')
|
||||
return {"Authorization": f"Basic {token}"}
|
||||
|
||||
@router.get("/data/{id}")
|
||||
async def fetch_arbor_data(id: int, token: str):
|
||||
url_mapping = {
|
||||
1: os.environ["KS3_COURSE_CLASS_MEMBERSHIP_URL"],
|
||||
2: os.environ["TEACHING_GROUP_MEMBERSHIPS_2023_2024_URL"],
|
||||
3: os.environ["SCHEDULED_TIMETABLE_SLOTS_URL"],
|
||||
4: os.environ["BEHAVIOURAL_INCIDENTS_REPORTING_URL"],
|
||||
5: os.environ["Y7_LESSON_TIMETABLE_URL"]
|
||||
}
|
||||
if id not in url_mapping:
|
||||
raise HTTPException(status_code=404, detail="Data ID not supported")
|
||||
|
||||
headers = get_basic_auth_header(token)
|
||||
response = requests.get(url_mapping[id], headers=headers)
|
||||
if response.status_code != 200:
|
||||
raise HTTPException(status_code=response.status_code, detail="Failed to fetch data from Arbor")
|
||||
return response.json()
|
||||
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
import json
|
||||
|
||||
def filter_by_staff(data, staff_name="Kevin Carter"):
|
||||
return [entry for entry in data if entry.get("Staff") == staff_name]
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) > 1:
|
||||
staff_name = sys.argv[1]
|
||||
else:
|
||||
staff_name = "Kevin Carter"
|
||||
|
||||
input_data = sys.stdin.read()
|
||||
try:
|
||||
data = json.loads(input_data)
|
||||
filtered_data = filter_by_staff(data, staff_name)
|
||||
print(json.dumps(filtered_data, indent=4))
|
||||
except json.JSONDecodeError:
|
||||
print("Invalid JSON input", file=sys.stderr)
|
||||
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import requests
|
||||
|
||||
def format_timetable_with_ollama(timetable_data):
|
||||
url = f"{os.environ.get('APP_API_URL')}/llm/private/ollama/ollama_generate"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
prompt = (
|
||||
"Create a markdown formatted table of the following timetable data. "
|
||||
"The table should have columns for 'Day', 'Time Slot', 'Effective Dates', 'Event', 'Room', and 'Staff':\n\n"
|
||||
f"{json.dumps(timetable_data, indent=4)}"
|
||||
)
|
||||
payload = {
|
||||
"model": "llama3", # Adjust the model name if necessary
|
||||
"prompt": prompt
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload)
|
||||
if response.status_code == 200:
|
||||
return response.json().get("response")
|
||||
else:
|
||||
raise Exception(f"Failed to get response from Ollama: {response.status_code} {response.text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
input_data = sys.stdin.read()
|
||||
try:
|
||||
timetable_data = json.loads(input_data)
|
||||
markdown_table = format_timetable_with_ollama(timetable_data)
|
||||
print(markdown_table)
|
||||
except json.JSONDecodeError:
|
||||
print("Invalid JSON input", file=sys.stderr)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
@@ -0,0 +1,45 @@
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
|
||||
def format_timetable_with_openai(timetable_data):
|
||||
url = f"{os.environ.get('APP_API_URL')}/llm/public/openai/openai_general_prompt"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
prompt = (
|
||||
"Create a markdown formatted table of the following timetable data. "
|
||||
"The table should have columns for 'Day', 'Time Slot', 'Effective Dates', 'Event', 'Room', and 'Staff':\n\n"
|
||||
f"{json.dumps(timetable_data, indent=4)}"
|
||||
)
|
||||
payload = {
|
||||
"model": "gpt-4-turbo", # Adjust the model name if necessary
|
||||
"prompt": prompt,
|
||||
"max_tokens": 1500,
|
||||
"temperature": 0.7,
|
||||
"top_p": 1.0,
|
||||
"n": 1,
|
||||
"stop": None
|
||||
}
|
||||
|
||||
response = requests.post(url, headers=headers, json=payload)
|
||||
if response.status_code == 200:
|
||||
return response.json().get("response")
|
||||
else:
|
||||
raise Exception(f"Failed to get response from OpenAI: {response.status_code} {response.text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
input_data = sys.stdin.read()
|
||||
try:
|
||||
timetable_data = json.loads(input_data)
|
||||
markdown_table = format_timetable_with_openai(timetable_data)
|
||||
|
||||
# Save the markdown table to a .md file
|
||||
output_file = "timetable.md"
|
||||
with open(output_file, "w") as file:
|
||||
file.write(markdown_table)
|
||||
|
||||
print(f"Markdown table saved to {output_file}")
|
||||
except json.JSONDecodeError:
|
||||
print("Invalid JSON input", file=sys.stderr)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}", file=sys.stderr)
|
||||
Reference in New Issue
Block a user