Python
Jeimy es compatible con el formato de OpenAI, así que se usa con su SDK oficial cambiando la URL base.
pip install openaiimport osfrom openai import OpenAI
client = OpenAI( api_key=os.environ["JEIMY_API_KEY"], base_url="https://api.jeimy.ai/v1",)Una respuesta
Sección titulada «Una respuesta»r = client.chat.completions.create( model="colibri", messages=[ {"role": "system", "content": "Responde en español de Perú, breve."}, {"role": "user", "content": "¿Qué es un RUC?"}, ],)print(r.choices[0].message.content)print(r.usage.total_tokens, "tokens")Streaming
Sección titulada «Streaming»stream = client.chat.completions.create( model="colibri", messages=[{"role": "user", "content": "Escribe un poema corto sobre Lima"}], stream=True,)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)Una conversación
Sección titulada «Una conversación»historial = [{"role": "system", "content": "Eres un tutor de matemáticas."}]
while True: pregunta = input("Tú: ") historial.append({"role": "user", "content": pregunta}) r = client.chat.completions.create(model="aguila", messages=historial) texto = r.choices[0].message.content historial.append({"role": "assistant", "content": texto}) print("Jeimy:", texto)Errores
Sección titulada «Errores»from openai import APIStatusError
try: r = client.chat.completions.create(model="colibri", messages=[{"role": "user", "content": "Hola"}])except APIStatusError as e: print(e.status_code, e.response.json()["error"]["code"])Ver Errores para la lista de códigos.
