File size: 2,368 Bytes
6558cd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain import PromptTemplate, LLMChain
from langchain.output_parsers import ResponseSchema, StructuredOutputParser
from langchain.prompts import ChatPromptTemplate

if "GOOGLE_API_KEY" not in os.environ:
    raise ValueError("GOOGLE_API_KEY environment variable is not set")

llm_prompt_template = """Olá, sou uma IA treinada para gerar conteúdo educacional. Por favor, gere cinco questões de múltipla escolha sobre o seguinte tema:
Instruções para cada questão:
- Crie uma questão clara e relevante para o tema.
- Forneça cinco opções de resposta, rotuladas de A) a E).
- Apenas uma das opções de resposta deve ser correta.
- Indique a resposta correta ao final de cada questão.

Exemplo de uma questão:
Tema: Fotossíntese

Questão:
Qual é o pigmento primário responsável pela fotossíntese nas plantas?

Opções de Resposta:
A) Clorofila
B) Hemoglobina
C) Mioglobina
D) Citocromo
E) Queratina

Resposta Correta:
A) Clorofila

Context: {context}
Question: {question}
Answer:


{format_questions_instructions}
"""

llm_prompt = PromptTemplate.from_template(llm_prompt_template)

gemini_embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")

llm = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.7, top_p=1)

questions_template = ChatPromptTemplate.from_template(template=llm_prompt_template)

questions_chain = LLMChain(llm=llm, prompt=questions_template)

questions_schema = ResponseSchema(
    name="questions",
    description="""Give the questions in json as an array""",
)

questions_schemas = [questions_schema]

questions_parser = StructuredOutputParser.from_response_schemas(questions_schemas)
format_questions_instructions = questions_parser.get_format_instructions()
format_questions_instructions = """
The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```":
```json
{
	"questions": [
    {
      question: "Qual é o pigmento primário responsável pela fotossíntese nas plantas?",
      options: ["A) Clorofila",
                "B) Hemoglobina",
                "C) Mioglobina",
                "D) Citocromo",
                "E) Queratina"],
      answer: "A"
    }
  ]
```
}"""