55
66from openai import OpenAI
77
8+ __all__ = ["get_chat_completion" ]
9+
810# Authenticate
911client = 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 ]
0 commit comments