Giter VIP home page Giter VIP logo

ai-personas's Introduction

Environment Setup Instructions

This guide outlines the steps necessary to set up your development environment for the project. Please follow the instructions in the order provided.

Prerequisites

Before you begin, ensure you have Docker and Python 3 installed on your machine. These tools are required to execute the setup steps.

Step 1: Set Up the Django Application

  1. Prepare Django Migrations:

    Before running the application, you need to prepare the database migrations. Use Docker Compose to run the migration commands within the containerized environment:

    docker-compose run web python3 Rag_persona/manage.py makemigrations
    docker-compose run web python3 Rag_persona/manage.py migrate
    docker-compose run web python3 Rag_persona/manage.py createsuperuser
    # creatine super user requires email and password input
    
    #creating a superuser account allows you to access the admin website provided by Django and to view all users and documents provided by users.

    These commands generate the necessary database migration files and apply them, setting up the database schema.

Step 2: Launch the Application

  1. Start the Application:

    Finally, start your Dockerized application. Ensure the Docker daemon is running, and execute the following command:

Start the Docker Compose services in detached mode with a custom .env file, and build images as necessary: docker-compose -f docker-compose.yml --env-file .env up -d --build

Wait for a moment to allow the services to start up. Then, to check the logs of the services to ensure everything is running smoothly: docker-compose logs

After confirming the application has started successfully, access the admin page by navigating to http://localhost:8000/admin/ in your web browser and log in with your credentials to manage the application.

API EndPoints

Here, I assume port 8000 is mapped.

import requests, json

Create User

ONLY EMAIL AND PASSWORD INPUTS ARE REQUIRED

endpoint = "http://localhost:8000/api/createuser/"
data = {
   email: [email protected],
   password: password,
   first_name: first,
   second_name: second,
   username: first_second
}

requests.post(endpoint,
   headers={
   "Content-Type": "application/json"},
   json=data
)

Authentication

Authentication is done using Django rest framework JWT

#token auth
endpoint_auth = "http://localhost:8000/api/token/"
data = {
   email: [email protected],
   password: password,
}
response = requests.post(endpoint_auth, json = data)

# token refresh
endpoint_refresh = "http://localhost:8000/api/token/refresh/"
data = {
   'refresh': #$%^^&%KKOJO
}
response = requests.post(endpoint_auth, json = data)

response.json() in both instances is a dictionary with 'refresh' and 'access' as dictionary keys

Add data to Database

This endpoint performs CREATE and READ using post and get requests, respectively

# Create new data to user's database

endpoint_data = "http://localhost:8000/api/"
endpoint_auth = "http://localhost:8000/api/token/"

data = {
   "text": """
      In the heart of night, under a velvet sky,
      Whispers of the moon, on a breeze, softly lie.
      Stars, like scattered dreams, in darkness dance,
      Weaving tales in silence, as if by chance.
      """

}
response = requests.post(endpoint_auth, json = data)
token = response.json()['access']
response = requests.post(endpoint_data,
                     headers={"Authorization": f"Bearer {token}",
                              "Content-Type": "application/json"},
                      json=post_doc)

# Response returns a dictionary with keys listed in ~ ['uploaded_at', 'topic', 'vector', 'text']
# topic is the first sentence
# vector is the word embeddings
# text as it
# uploaded_at is the date created

# List all user's data
response = requests.get(endpoint_data,
                headers={"Authorization": f"Bearer {token}"})

# response format ditto

Text Generation and Question/Answering

   data = {
     "query": "Write a poem about a Bentley car using my style?"
     }
   # token is generated using a similar call from the above function calls.
   response = requests.post(endpoint_prompt,
                     headers={"Authorization": f"Bearer {token}"},
                     data=data)
                     
   print(response.json())

ai-personas's People

Contributors

kunle-xy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.