Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,8 @@
|
|
| 1 |
import time
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
-
from
|
| 5 |
-
from langfuse.openai import OpenAI
|
| 6 |
|
| 7 |
-
# set Langfuse api keys and host address
|
| 8 |
-
LANGFUSE_PUBLIC_KEY = 'pk-lf-5d3260be-dc58-40e9-9ff7-d50eaf6f30a1'
|
| 9 |
-
LANGFUSE_SECRET_KEY = 'sk-lf-0d292645-e04c-4ef5-a3e3-966b200843c0'
|
| 10 |
-
LANGFUSE_HOST = "https://cloud.langfuse.com"
|
| 11 |
MODELOS_DE_OPENROUTER = "https://openrouter.ai/api/v1/models"
|
| 12 |
URL="https://openrouter.ai/api/v1"
|
| 13 |
REQUEST_SUCESSFULL = 200
|
|
@@ -17,9 +12,7 @@ def obtener_modelos():
|
|
| 17 |
if respuesta.status_code == REQUEST_SUCESSFULL:
|
| 18 |
return [modelo["id"] for modelo in respuesta.json().get("data", [])]
|
| 19 |
|
| 20 |
-
@observe
|
| 21 |
def obtener_respuesta(modelo, api_key, prompt):
|
| 22 |
-
langfuse_context.update_current_observation(input=[modelo, prompt])
|
| 23 |
client = OpenAI(base_url=URL, api_key=api_key)
|
| 24 |
mensajes = [{"role": "assistant", "content": prompt}]
|
| 25 |
respuesta = client.chat.completions.create(model=modelo, messages=mensajes)
|
|
|
|
| 1 |
import time
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
+
from openai import OpenAI
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
MODELOS_DE_OPENROUTER = "https://openrouter.ai/api/v1/models"
|
| 7 |
URL="https://openrouter.ai/api/v1"
|
| 8 |
REQUEST_SUCESSFULL = 200
|
|
|
|
| 12 |
if respuesta.status_code == REQUEST_SUCESSFULL:
|
| 13 |
return [modelo["id"] for modelo in respuesta.json().get("data", [])]
|
| 14 |
|
|
|
|
| 15 |
def obtener_respuesta(modelo, api_key, prompt):
|
|
|
|
| 16 |
client = OpenAI(base_url=URL, api_key=api_key)
|
| 17 |
mensajes = [{"role": "assistant", "content": prompt}]
|
| 18 |
respuesta = client.chat.completions.create(model=modelo, messages=mensajes)
|