User Tools

Site Tools


informatica:inteligencia_artificial:openai

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
informatica:inteligencia_artificial:openai [2023/03/01 22:19] – created joseinformatica:inteligencia_artificial:openai [2023/03/02 23:03] (current) jose
Line 332: Line 332:
 Varios servicios Machine Learning de Amazon:\\ Varios servicios Machine Learning de Amazon:\\
 https://aws.amazon.com/es/free/machine-learning/ https://aws.amazon.com/es/free/machine-learning/
 +
 +
 +====== Nueva API ======
 +En Marzo de 2023 salió el nuevo modelo gpt-3.5-turbo con su API
 +
 +Fuente:\\
 +https://platform.openai.com/docs/guides/chat/introduction \\
 +https://github.com/openai/openai-cookbook/blob/main/examples/How_to_format_inputs_to_ChatGPT_models.ipynb
 +
 +Exportamos la key en bash:
 +  export API_KEY='sk-aslasdjkasldjasldjasldjkasldkj'
 +Dede python:
 +<code>
 +import openai
 +
 +response = openai.ChatCompletion.create(
 +  model="gpt-3.5-turbo",
 +  messages=[
 +        {"role": "system", "content": "You are a helpful assistant."},
 +        {"role": "user", "content": "Who won the world series in 2020?"},
 +        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
 +        {"role": "user", "content": "Where was it played?"}
 +    ]
 +)
 +
 +print(response)
 +</code>
 +
 +Respuesta:
 +<code>
 +{
 +  "choices": [
 +    {
 +      "finish_reason": "stop",
 +      "index": 0,
 +      "message": {
 +        "content": "The 2020 World Series was played at a neutral site due to the COVID-19 pandemic. The games were played at Globe Life Field in Arlington, Texas.",
 +        "role": "assistant"
 +      }
 +    }
 +  ],
 +  "created": 1677797684,
 +  "id": "chatcmpl-6pm6uk0cGDiLdRTq8GB8vy90AWzbb",
 +  "model": "gpt-3.5-turbo-0301",
 +  "object": "chat.completion",
 +  "usage": {
 +    "completion_tokens": 35,
 +    "prompt_tokens": 56,
 +    "total_tokens": 91
 +  }
 +}
 +</code>
 +
 +Con curl:
 +  curl https://api.openai.com/v1/chat/completions -H "Authorization: Bearer $API_KEY" -H "Content-Type: application/json" -d '{ "model": "gpt-3.5-turbo",  "messages": [{"role": "user", "content": "Inventate una historia de un asesinato en Carabanchel"}] }' 
 + 
  
informatica/inteligencia_artificial/openai.1677709148.txt.gz · Last modified: 2023/03/01 22:19 by jose