|
import os |
|
import json |
|
from llamaapi import LlamaAPI |
|
from openai import OpenAI |
|
|
|
|
|
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() |
|
|
|
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")) |