-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExaminer.py
More file actions
68 lines (57 loc) · 2.22 KB
/
Copy pathExaminer.py
File metadata and controls
68 lines (57 loc) · 2.22 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
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
import os
import openai
import base64
# Examine if a indicator is trustworthy for medical diagnosis
class Examiner:
def __init__(self, api_key):
"""
Initialize the Examiner object with the OpenAI API Key.
Args:
api_key (str): OpenAI 的 API Key
"""
self.api_key = api_key
openai.api_key = self.api_key
self.function = "Determine if the result is confidential and accurate?\
Answer with only one word (Yes or No)"
def encode_image(self, image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
def examine(self, prompt, image_path=None, result=None):
image_messages = []
base64_image = self.encode_image(image_path)
image_messages.append({
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
},
})
if os.path.isfile(result):
base64_image = self.encode_image(result)
image_messages.append({
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
},
})
messages = [
{"role": "system", "content": "You are a helpful assistant. Please help me make decision"},
{"role": "user", "content": image_messages + [{
"type": "text",
"text": prompt + self.function,
}]}
]
else:
messages = [
{"role": "system", "content": "You are a helpful assistant. Please determine if the result is confidential and accurate?\
Answer with only one word (Yes or No)"},
{"role": "user", "content": image_messages + [{
"type": "text",
"text": prompt + self.function + "\n" + result,
}]}
]
completion = openai.ChatCompletion.create(
model="gpt-4o",
messages=messages
)
result = completion.choices[0].message.content
return result