Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -13,17 +13,26 @@ examples = ["¿Cómo puedo automatizar el alta de nuevos clientes y proveedores
|
|
| 13 |
# Inicializa la variable global
|
| 14 |
thread_id = None
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Función para generar la respuesta usando tu API
|
| 17 |
def generate_response_api(message, thread_id, assistant_id):
|
| 18 |
assistant_id = "asst_9Ij7ORMY2IQ8CEnWxmrmn8K2" # Variable dinámica
|
| 19 |
project_id = "65b3f1b7bbb53ccdfcd622f7" # Variable dinámica
|
| 20 |
base_url = "https://enjambre-api-mue2676eoa-uc.a.run.app"
|
| 21 |
url = f"{base_url}/v1/agents/{assistant_id}/completion"
|
| 22 |
-
response = requests.post(url, json=
|
| 23 |
-
"message": message,
|
| 24 |
-
"model": "gpt-3.5-turbo-0613",
|
| 25 |
-
"threadId": thread_id
|
| 26 |
-
})
|
| 27 |
response_json = response.json()
|
| 28 |
return response_json["message"], response_json["threadId"]
|
| 29 |
|
|
@@ -39,6 +48,8 @@ def chat_function(message, history):
|
|
| 39 |
|
| 40 |
def set_thread_id(thr_id:str):
|
| 41 |
global thread_id
|
|
|
|
|
|
|
| 42 |
thread_id = thr_id
|
| 43 |
|
| 44 |
# Configuración de ChatInterface usando valores dinámicos
|
|
@@ -56,7 +67,7 @@ with gr.Blocks() as demo:
|
|
| 56 |
submit_btn="Enviar",
|
| 57 |
stop_btn="Detener"
|
| 58 |
).queue()
|
| 59 |
-
gr.Interface(fn=set_thread_id, inputs="textbox",
|
| 60 |
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
|
|
|
| 13 |
# Inicializa la variable global
|
| 14 |
thread_id = None
|
| 15 |
|
| 16 |
+
|
| 17 |
+
def process_body(message: str, thr_id):
|
| 18 |
+
if thr_id == None:
|
| 19 |
+
return {
|
| 20 |
+
"message": message,
|
| 21 |
+
"model": "gpt-3.5-turbo-0613"
|
| 22 |
+
}
|
| 23 |
+
return {
|
| 24 |
+
"message": message,
|
| 25 |
+
"model": "gpt-3.5-turbo-0613",
|
| 26 |
+
"threadId": thr_id
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
# Función para generar la respuesta usando tu API
|
| 30 |
def generate_response_api(message, thread_id, assistant_id):
|
| 31 |
assistant_id = "asst_9Ij7ORMY2IQ8CEnWxmrmn8K2" # Variable dinámica
|
| 32 |
project_id = "65b3f1b7bbb53ccdfcd622f7" # Variable dinámica
|
| 33 |
base_url = "https://enjambre-api-mue2676eoa-uc.a.run.app"
|
| 34 |
url = f"{base_url}/v1/agents/{assistant_id}/completion"
|
| 35 |
+
response = requests.post(url, json=process_body(message, thread_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
response_json = response.json()
|
| 37 |
return response_json["message"], response_json["threadId"]
|
| 38 |
|
|
|
|
| 48 |
|
| 49 |
def set_thread_id(thr_id:str):
|
| 50 |
global thread_id
|
| 51 |
+
if thr_id == '':
|
| 52 |
+
return
|
| 53 |
thread_id = thr_id
|
| 54 |
|
| 55 |
# Configuración de ChatInterface usando valores dinámicos
|
|
|
|
| 67 |
submit_btn="Enviar",
|
| 68 |
stop_btn="Detener"
|
| 69 |
).queue()
|
| 70 |
+
gr.Interface(fn=set_thread_id, inputs="textbox", title="id del hilo")
|
| 71 |
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|