OpenAISpamDetect/main.py

19 lines
799 B
Python

import openai
import sys
#ai = openai.OpenAI(base_url="http://localai.rz.l--n.de:8000/v1", api_key=False)
#ai = openai.OpenAI(base_url="https://api.mistral.ai/v1", api_key="qA6fMdwKuPTHU19wTeqVpwyp2mrELBY7")
ai = openai.OpenAI(base_url="http://localhost:8080/v1", api_key=False)
for fn in sys.argv[1:]:
with open(fn) as f:
text = f.read()
prompt = "Classify the following email message as SPAM or HAM. Do not explain anything. Answer only with one word, either SPAM or HAM.\n\n{}".format(text[:4096])
chat_completion = ai.chat.completions.create(messages=[{
"role": "user",
"content": prompt,
}], model="mistral-large-2402")
#model="/opt/models/dolphin-2.7-mixtral-8x7b.Q8_0.gguf"
print("{}: {}".format(fn, chat_completion.choices[0].message.content))