File size: 1,344 Bytes
f134294 |
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 |
import os
import json
from llamaapi import LlamaAPI
from openai import OpenAI
# Initialize
llama = LlamaAPI("LL-AirERHEk0jLIE1yEPvMXeobNfLsqLWJWcxLRS53obrZ3XyqMTfZc4EAuOs7r3wso")
api_key = "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"
os.environ["OPENAI_API_KEY"] = api_key
client = OpenAI()
def classify_learning_content(user_input):
messages = [
{"role": "system", "content": "Classify the need as either "
"'Vocabulary Building', 'Writing instruction', "
"'Speaking Practice', 'Writing Assessment'."},
{"role": "user", "content": user_input}
]
completion = client.chat.completions.create(
model="gpt-4",
messages=messages
)
classification_text = completion.choices[0].message.content.strip().lower() # Normalize the text
# Simplify the comparison using keywords, assuming each category is distinct enough
if "writing assessment" in classification_text:
return 4
elif "vocabulary building" in classification_text:
return 3
elif "writing instruction" in classification_text:
return 2
elif "speaking practice" in classification_text:
return 1
else:
return 0
if __name__ == '__main__':
print(classify_learning_content("Vocabulary")) |