#!/usr/bin/env python # coding: utf-8 #
#
# # # **Modelos del lenguaje basados en redes neuronales artificiales** # ## **GPT (Generative Pre-Training Transformer)** # # Consituyen una serie de modelos del lenguaje desarrollados por OpenAI. Estos modelos son conocidos por su capacidad para generar texto, responder preguntas, traducir idiomas, resumir documentos y realizar una variedad de otras tareas lingüísticas. La arquitectura de GPT se basa en el concepto de *Transformer*. # In[1]: from ctransformers import AutoModelForCausalLM llm = AutoModelForCausalLM.from_pretrained("TheBloke/Mistral-7B-Instruct-v0.1-GGUF", model_file="mistral-7b-instruct-v0.1.Q5_K_M.gguf", model_type="mistral", gpu_layers=50) # In[2]: print(llm("¿Si tengo 15 manzanas y me como 3, cuántas me quedan?")) # # # Descarga e instala LM Studio desde [aquí](https://lmstudio.ai/). # In[3]: import os import openai openai.api_base = "http://localhost:1234/v1" # point to the local server openai.api_key = "" # no need for an API key completion = openai.ChatCompletion.create( model="local-model", # this field is currently unused messages=[ {"role": "system", "content": "You are an assistant helping a student with their homework"}, {"role": "assistant", "content": "Hi, how can I help you today?"}, {"role": "user", "content": "I need help with my chemistry homework. Can you help me?"}, {"role": "assistant", "content": "Of course! What specific topic or problem are you working on? Please provide more details so I can better assist you."}, {"role": "user", "content": "Do you know how to formulate oxides?"}, ] ) print(completion.choices[0].message) # # In[4]: print(completion.choices[0].message["content"])