Spaces:
Sleeping
Sleeping
Add .env to .gitignore and update genai_service to load API key from environment
Browse files- .gitignore +3 -0
- routes/chat.py +3 -3
- services/genai_service.py +4 -1
.gitignore
CHANGED
@@ -16,3 +16,6 @@ __pycache__/
|
|
16 |
# Mac/Windows
|
17 |
.DS_Store
|
18 |
Thumbs.db
|
|
|
|
|
|
|
|
16 |
# Mac/Windows
|
17 |
.DS_Store
|
18 |
Thumbs.db
|
19 |
+
|
20 |
+
# Arquivos de configuração do ambiente
|
21 |
+
.env
|
routes/chat.py
CHANGED
@@ -37,9 +37,9 @@ def chat(user_id):
|
|
37 |
|
38 |
prompt = (
|
39 |
f"Você é uma especialista em livros e pode conversar livremente "
|
40 |
-
f"sobre obras literárias, personagens, enredos, gêneros e autores.
|
41 |
-
f"O nome do usuário é {history.get('name', f'Usuário {user_id}')}
|
42 |
-
f"As preferências dele são: "
|
43 |
f"{', '.join(history.get('preferences', [])) or 'nenhuma'}. "
|
44 |
f"Histórico: {history}. "
|
45 |
f"Pergunta: {question} "
|
|
|
37 |
|
38 |
prompt = (
|
39 |
f"Você é uma especialista em livros e pode conversar livremente "
|
40 |
+
f"sobre obras literárias, personagens, enredos, gêneros e autores."
|
41 |
+
f" O nome do usuário é {history.get('name', f'Usuário {user_id}')}"
|
42 |
+
f". As preferências dele são: "
|
43 |
f"{', '.join(history.get('preferences', [])) or 'nenhuma'}. "
|
44 |
f"Histórico: {history}. "
|
45 |
f"Pergunta: {question} "
|
services/genai_service.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import os
|
2 |
import google.generativeai as genai
|
|
|
|
|
|
|
3 |
|
4 |
|
5 |
def configure_genai():
|
6 |
"""
|
7 |
Configura a chave de API e inicializa o modelo Gemini.
|
8 |
"""
|
9 |
-
api_key = os.
|
10 |
|
11 |
if not api_key:
|
12 |
raise EnvironmentError(
|
|
|
1 |
import os
|
2 |
import google.generativeai as genai
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
|
7 |
|
8 |
def configure_genai():
|
9 |
"""
|
10 |
Configura a chave de API e inicializa o modelo Gemini.
|
11 |
"""
|
12 |
+
api_key = os.getenv("GOOGLE_API_KEY")
|
13 |
|
14 |
if not api_key:
|
15 |
raise EnvironmentError(
|