JeCabrera commited on
Commit
a8e76ea
·
verified ·
1 Parent(s): 5a03936

Update session_state.py

Browse files
Files changed (1) hide show
  1. session_state.py +21 -1
session_state.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import joblib
3
  import os
4
  from google import genai
 
5
 
6
  DEFAULT_GEMINI_MODEL = 'gemini-3.1-flash-lite-preview'
7
  DATA_DIR = 'data'
@@ -38,6 +39,9 @@ class SessionState:
38
 
39
  if 'prompt' not in st.session_state:
40
  st.session_state.prompt = None
 
 
 
41
 
42
  # Getters y setters para cada propiedad
43
  @property
@@ -103,6 +107,14 @@ class SessionState:
103
  @prompt.setter
104
  def prompt(self, value):
105
  st.session_state.prompt = value
 
 
 
 
 
 
 
 
106
 
107
  # Métodos de utilidad
108
  def add_message(self, role, content, avatar=None):
@@ -128,10 +140,14 @@ class SessionState:
128
  self.client = genai.Client(api_key=api_key)
129
  self.model = model_name
130
 
131
- def initialize_chat(self, history=None):
132
  """Inicializa el chat con el modelo"""
133
  if history is None:
134
  history = self.gemini_history
 
 
 
 
135
 
136
  # Asegurar que el modelo está inicializado
137
  if self.model is None or self.client is None:
@@ -140,6 +156,10 @@ class SessionState:
140
  chat_kwargs = {'model': self.model}
141
  if history:
142
  chat_kwargs['history'] = history
 
 
 
 
143
 
144
  # Inicializar chat con el SDK moderno
145
  self.chat = self.client.chats.create(**chat_kwargs)
 
2
  import joblib
3
  import os
4
  from google import genai
5
+ from google.genai import types
6
 
7
  DEFAULT_GEMINI_MODEL = 'gemini-3.1-flash-lite-preview'
8
  DATA_DIR = 'data'
 
39
 
40
  if 'prompt' not in st.session_state:
41
  st.session_state.prompt = None
42
+
43
+ if 'system_instruction' not in st.session_state:
44
+ st.session_state.system_instruction = None
45
 
46
  # Getters y setters para cada propiedad
47
  @property
 
107
  @prompt.setter
108
  def prompt(self, value):
109
  st.session_state.prompt = value
110
+
111
+ @property
112
+ def system_instruction(self):
113
+ return st.session_state.system_instruction
114
+
115
+ @system_instruction.setter
116
+ def system_instruction(self, value):
117
+ st.session_state.system_instruction = value
118
 
119
  # Métodos de utilidad
120
  def add_message(self, role, content, avatar=None):
 
140
  self.client = genai.Client(api_key=api_key)
141
  self.model = model_name
142
 
143
+ def initialize_chat(self, history=None, system_instruction=None):
144
  """Inicializa el chat con el modelo"""
145
  if history is None:
146
  history = self.gemini_history
147
+ if system_instruction is None:
148
+ system_instruction = self.system_instruction
149
+ else:
150
+ self.system_instruction = system_instruction
151
 
152
  # Asegurar que el modelo está inicializado
153
  if self.model is None or self.client is None:
 
156
  chat_kwargs = {'model': self.model}
157
  if history:
158
  chat_kwargs['history'] = history
159
+ if system_instruction:
160
+ chat_kwargs['config'] = types.GenerateContentConfig(
161
+ system_instruction=system_instruction
162
+ )
163
 
164
  # Inicializar chat con el SDK moderno
165
  self.chat = self.client.chats.create(**chat_kwargs)