Skip to content

Commit d81d623

Browse files
committed
Blacken, requirements
1 parent c35e659 commit d81d623

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

prompt-engineering/app.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from openai import OpenAI
77

8+
__all__ = ["get_chat_completion"]
9+
810
# Authenticate
911
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
1012

@@ -30,23 +32,35 @@ def get_chat_completion(content: str) -> str:
3032
"""Send a request to the /chat/completions endpoint."""
3133
response = client.chat.completions.create(
3234
model=SETTINGS["general"]["model"],
33-
messages=assemble_chat_messages(content),
35+
messages=_assemble_chat_messages(content),
3436
temperature=SETTINGS["general"]["temperature"],
3537
seed=12345, # Doesn't do anything for older models
3638
)
3739
return response.choices[0].message.content
3840

3941

40-
def assemble_chat_messages(content: str) -> list[dict]:
42+
def _assemble_chat_messages(content: str) -> list[dict]:
4143
"""Combine all messages into a well-formatted list of dicts."""
4244
messages = [
4345
{"role": "system", "content": SETTINGS["prompts"]["role_prompt"]},
4446
{"role": "user", "content": SETTINGS["prompts"]["negative_example"]},
45-
{"role": "system", "content": SETTINGS["prompts"]["negative_reasoning"]},
46-
{"role": "assistant", "content": SETTINGS["prompts"]["negative_output"]},
47+
{
48+
"role": "system",
49+
"content": SETTINGS["prompts"]["negative_reasoning"],
50+
},
51+
{
52+
"role": "assistant",
53+
"content": SETTINGS["prompts"]["negative_output"],
54+
},
4755
{"role": "user", "content": SETTINGS["prompts"]["positive_example"]},
48-
{"role": "system", "content": SETTINGS["prompts"]["positive_reasoning"]},
49-
{"role": "assistant", "content": SETTINGS["prompts"]["positive_output"]},
56+
{
57+
"role": "system",
58+
"content": SETTINGS["prompts"]["positive_reasoning"],
59+
},
60+
{
61+
"role": "assistant",
62+
"content": SETTINGS["prompts"]["positive_output"],
63+
},
5064
{"role": "user", "content": f">>>>>\n{content}\n<<<<<"},
5165
{"role": "user", "content": SETTINGS["prompts"]["instruction_prompt"]},
5266
]
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
aiohttp==3.8.4
2-
aiosignal==1.3.1
3-
async-timeout==4.0.2
4-
attrs==23.1.0
5-
certifi==2023.5.7
6-
charset-normalizer==3.1.0
7-
frozenlist==1.3.3
8-
idna==3.4
9-
multidict==6.0.4
10-
openai==0.27.8
11-
python-dotenv==1.0.0
12-
requests==2.31.0
13-
tqdm==4.65.0
14-
urllib3==2.0.3
15-
yarl==1.9.2
1+
annotated-types==0.6.0
2+
anyio==4.3.0
3+
certifi==2024.2.2
4+
distro==1.9.0
5+
h11==0.14.0
6+
httpcore==1.0.4
7+
httpx==0.27.0
8+
idna==3.6
9+
openai==1.13.3
10+
pydantic==2.6.3
11+
pydantic-core==2.16.3
12+
sniffio==1.3.1
13+
tqdm==4.66.2
14+
typing-extensions==4.10.0

0 commit comments

Comments
 (0)