LearnableAI / src /services /use_case_one /word_to_sentence.py
ishworrsubedii's picture
add: image generation and refactor prompt
978360d
"""
project @ LearnableAI
created @ 2025-01-16
author @ github.com/ishworrsubedii
"""
import os
from typing import List, Dict
from groq import Groq
class UseCaseOne:
def __init__(self, client):
self.client = client
def generate_educational_content(self, interest: str, difficulties: str, words: List[str]) -> Dict:
prompt = f"""
# ๐ŸŽฏ Learning Content Generator
## ๐Ÿ“ Input Parameters
- **Interest Area:** {interest}
- **Target Words:** {', '.join(words)}
- **Difficulty Level:** {difficulties}
## โœจ Content Requirements
### 1. ๐Ÿ“– Creative Sentences
- Must use target words naturally
- Must relate to {interest}
- Must match {difficulties} difficulty level
- Should be engaging and educational
### 2. ๐Ÿค” Quiz Questions
- Must test word understanding
- Must be multiple choice
- Must have clear correct answers
- Must relate to {interest}
### 3. ๐ŸŽจ Image Generation Prompt
- Must incorporate target words
- Must be detailed for AI generation
- Must be creative and engaging
- Must relate to {interest}
### 4. ๐ŸŽฎ Activities
- Must be simple and engaging
- Must reinforce target words
- Must match {difficulties} level
- Must relate to {interest}
## ๐ŸŽ Output Format
### ๐Ÿ“š Sentences
1. [First creative sentence]
2. [Second creative sentence]
3. [Third creative sentence]
### โ“ Quiz
**Question 1**
[Question text]
- A) [Option]
- B) [Option]
- C) [Option]
- D) [Option]
*Correct Answer: [A/B/C/D]*
**Question 2**
[Question text]
- A) [Option]
- B) [Option]
- C) [Option]
- D) [Option]
*Correct Answer: [A/B/C/D]*
### ๐ŸŽฏ Activities
1. [Detailed description of first activity]
2. [Detailed description of second activity]
### ๐Ÿ–ผ๏ธ Image Generation Prompt
[Detailed scene description incorporating target words]
---
*Note: All content should be accessible and engaging for children with learning difficulties.* โœจ
"""
try:
completion = self.client.chat.completions.create(
messages=[{
"role": "system",
"content": "You are an expert in creating educational content for children with ADHD. and you need to generate some educational content for children to understand the concept of the given words."
},
{
"role": "user",
"content": prompt
}],
model="deepseek-r1-distill-llama-70b",
temperature=1.0, # if increase temperature, it will generate more creative content
max_tokens=2000,
top_p=1,
stream=False
)
return completion.choices[0].message.content
except Exception as e:
return {
"error": f"Error generating content: {str(e)}",
"status": "failed"
}
if __name__ == '__main__':
client = Groq(api_key=os.getenv
('GROQ_API_KEY'))
use_case_one = UseCaseOne(client=client)
result = use_case_one.generate_educational_content(
interest="spiderman",
difficulties="simple",
words=["apple", "banana", "orange"]
)
print(result)