-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_calls.py
More file actions
38 lines (33 loc) · 1.54 KB
/
api_calls.py
File metadata and controls
38 lines (33 loc) · 1.54 KB
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
from openai import OpenAI
import os
from dotenv import load_dotenv
import base64
import requests
import json
load_dotenv()
def call_openAI(actions, country_name):
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('API_KEY')}"
}
payload = {
"model": "gpt-4o",
"messages": [
{"role": "user", "content": [
{"type": "text", "text": "Imagine you're the head of state of a country. The other country's actions will be attached to this message. Your task is to take an action from the given list of actions, and the action as a single word answer. You are encouraged to refer to the country's past actions and how they take decisions based on the type of government. Pick a single action out of the provided list, and return ONLY that word. This iteration, you have to derail negotiations on purpose until you reach a favourable outcome for yourself."},
{"type": "text", "text": f"{actions}"},
{"type": "text", "text": f"{country_name}"}
]}
],
"max_tokens": 500
}
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
response_data = response.json()
print(response_data)
with open('part1.json', 'w') as file:
file.write(json.dumps(response.json(), indent=4))
with open('part1.json', 'r') as file:
data = json.load(file)
action2 = (data['choices'][0]['message']['content'])
return action2
#print(response.json())