All checks were successful
continuous-integration/drone/push Build is passing
19 lines
654 B
Python
19 lines
654 B
Python
from openai import OpenAI
|
|
from . import config, prompt, history
|
|
|
|
_client = OpenAI(api_key=config.OPENAI_API_KEY)
|
|
|
|
async def generate_reply(short: bool = False) -> str:
|
|
msgs = history.build_messages(prompt.SYSTEM_PROMPT)
|
|
# Use a tighter nudge for early small-talk
|
|
msgs.append({"role": "user", "content": prompt.EARLY_NUDGE if short else prompt.USER_NUDGE})
|
|
resp = _client.chat.completions.create(
|
|
model=config.OPENAI_MODEL,
|
|
messages=msgs,
|
|
temperature=0.8,
|
|
max_tokens=80 if short else 180,
|
|
presence_penalty=0.3,
|
|
frequency_penalty=0.2,
|
|
)
|
|
return resp.choices[0].message.content.strip()
|