-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
47 lines (36 loc) · 1.18 KB
/
app.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
import requests
from openai import OpenAI
client = OpenAI(api_key='OPENAI_API')
def fetch_json_from_api(url):
response = requests.get(url)
if response.status_code == 200:
return response.json()
else:
return None
def fetch_json_from_api(url):
response = requests.get(url)
if response.status_code == 200:
return response.text # Returns raw JSON string
else:
return None
def generate_summary_for_json(api_url):
json_str = fetch_json_from_api(api_url) # Raw JSON string
if json_str is None:
return "Failed to fetch or parse JSON data from the API."
system_message = "You are a helpful assistant. You will generate a summary of the JSON file."
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": json_str}
],
temperature=1,
max_tokens=1812,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content
api_url = "ENDPOINT_URL"
summary = generate_summary_for_json(api_url)
print(summary)