-
Notifications
You must be signed in to change notification settings - Fork 0
/
DIZ_llama_api.py
69 lines (56 loc) · 1.92 KB
/
DIZ_llama_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
Main file for the DIZ Llama API
Version: 0.1
Date : 12.12.2024
Author : Eric Einspänner
Mail : eric.einspaenner@med.ovgu.de
"""
# **************************************************************************
# * Import
# **************************************************************************
import os
import requests
from dotenv import load_dotenv
# **************************************************************************
# * Init
# **************************************************************************
# Load API keys
load_dotenv()
DIZ_API_KEY = os.getenv("DIZ_API_KEY")
# Define the API endpoint and headers
url = "https://ki-plattform.diz-ag.med.ovgu.de/api/chat/completions"
headers = {
"Authorization": f"Bearer {DIZ_API_KEY}",
"Content-Type": "application/json"
}
# **************************************************************************
# * Function
# **************************************************************************
def request_DIZ_llama(prompt: str) -> str:
r"""
Send a prompt to DIZ API (Llama) and return the response.
Args:
- prompt: The prompt to send to the API.
Returns:
The response from the API.
"""
# Define the JSON data to be sent in the POST request
data = {
"model": "llama3.2-vision:90b",
"messages": [
{
"role": "user",
"content": prompt
}
]
}
# Make the POST request using the requests library
response = requests.post(url, headers=headers, json=data)
return response.json().get("choices")[0].get("message").get("content")
# **************************************************************************
# * Main
# **************************************************************************
if __name__ == '__main__':
# Test the DIZ Llama API
response = request_DIZ_llama("What is the capital of Germany?")
print(response)