top of page

Getting Started with Python

​​

​

The PeopleCode.AI Python Library

The PeopleCode.AI library provides high-level access to OpenAI's powers, so even beginning and novice Python coders can create generative AI apps. The PeopleCode.AI library provides a simple API and hides some of the complexities within OpenAI's library, which is designed for expert coders. With a lower barrier to entry, great thinkers who are not Python experts can become AI creators. You can access the library at GitHub by downloading the zip file below, and we have lots of sample code for you to learn from.

​​​​​​

​​​

The instructions below are for Linux or Mac Users. For Windows users, see this tutorial.

​​​​​​

Library Features

  • Simple Python API for asking OpenAI questions, very little Python knowledge is needed.

  • Function for generating sample questions, e.g., for chatbot users who don't know how to begin

  • Function for generating follow-up questions for chatbot users

  • RAG capabilities-- the PeopleCode.ai library has methods for calling custom GPTs, which are called "assistants" at OpenAI. You can go to OpenAI, create an assistant, and add documents to it. OpenAI assigns an id to every assistant. You then use the PeopleCode.ai Library calls and provide the assistant id as a parameter. Your requests are then answered using information in the document set instead of the broader frontier. For example, a professor might upload course notes and/or a book into an "assistant", and let students ask questions of it.

​​​​​​​​​Here is the "simplest" sample using the library:
 

import sys

import os

 

sys.path.append("..")

from PeopleCodeOpenAI import OpenAI_Conversation

​

api_key = os.getenv('OPENAI_API_KEY')

if not api_key:

print("Error: The API key is not set. Set the environment variable 'OPENAI_API_KEY'.")

sys.exit(-1)

​

conversation_manager = OpenAI_Conversation(api_key=api_key, model="gpt-4") ​

instructions = "You are a helpful assistant."

 

print("How can I help you today?")

while True:

user_prompt = input("Enter a prompt. Type 'exit' to quit: ").strip()

if user_prompt.lower() == "exit":

print("Goodbye!")

sys.exit(0)

​

response = conversation_manager.ask_question(instructions, user_prompt)

print("Response:\n" + response)

​​

The Python code to access the library is just a function call to getQuestion which has string parameters and a dictionary return value. Very minimal Python knowledge is needed and the key "programming" is the English instructions  provided to OpenAI.

Setup

​

​0. You need Python3 installed on your computer to run the samples and you’ll need Pip to install some Python packages. Generally Pip comes with your Python installation.​

​

1. Clone the GitHub repo into a local folder. Open a terminal and enter the following command to clone the app.

% git clone https://github.com/People-Museum-Project/PeopleCode-OpenAI-Library.git

​

Alternatively, you can download the library directly from Git Repository. To do so:

a. Open the Git Repository at given link.

b. Click on arrow next to '<> Code'.

​

​​

​

​

​

c. Click on 'Download Zip' option Extract the zip folder to the location of your choice.​

​

​

​

​

​

​

​​

​

​

​

2. Install the OpenAI library. In a terminal, enter the following command:

% pip install OpenAI​

click on code_edited.jpg
click on download zip_edited.jpg

3. Get an OpenAI/API key and set it in your environment variables.

  • You need a key to build an app that talks to OpenAI.You need a credit card to get a key, but you can put a limit of $5, with auto-increase off, and this will allow a fair amount of testing. Go to openai.com/api to get an account and a key (see this video for help)

  • Once you have a key, set your command-line environment variables with it. At the terminal run the following command, replacing "your-api-key" with the key you got from OpenAI:

% export OPENAI_API_KEY="your-api-key”

​

You have just completed all the set up needed. To test whether the set-up is successful, jump to the next section to run a sample chatbot.

Command Line Chatbot

The command-line samples are in the Command-Line-Apps subfolder. From that folder, run one of the samples, e.g., simpleChatApp.py.
​

% python simpleChatApp.py​

​

If you are able to successfully run the app, you can a conversation with it like shown below:

Customize it: Try modifying the prompt used in SimpleChat.py. For instance, have it answer as Shakespeare or some other famous person, or ask it to answer at a 4th grade level.

​

# Instructions for the assistant

instructions = "You are a helpful assistant. Respond like you are talking to a 4 year old."

                 //or

instructions = "You are a helpful assistant. Respond for the perspective of Shakespeare."

Web Apps Using 

image.png
What is Streamlit?

Streamlit turns Python code from command-line to a shareable web app with a UI. You code the user interface using Python calls to create the components, so your development is all Python with no need to learn HTML, CSS, or Javascript. Streamlit also provides hosting, so you can quickly get your apps up and running for free. It is a great tool for quickly building web apps.​​​​​​

​​

The PeopleCode.ai library has a number of GenAI samples that use Streamlit for the UI.​ They are in the “Streamlit-Apps” subfolder of the repository.


To run one of the sample streamlit apps, perform the following steps:

​

1. Install the Streamlit library

% pip install streamlit

​

2. Set your Open AI Key similar to how you did when running the command line chatbot.

% export OPENAI_API_KEY="your-api-key”

​

3. From the main project folder, run the following command:

       % streamlit run ./Streamlit-Apps/EllaBakerStreamlit.py

​

​If you are able to successfully run the app, you should be able to see a local host open in your browser and use the app.

 

You can replace “EllaBakerStreamlit.py” with any of the other samples.

​

How to Deploy (Make Public) Streamlit Apps?

The above instructions will run the app locally, but it is not deployed for sharing with others. You can deploy a Streamlit apps so that it runs on the web with a URL you can share with others. Streamlit community will even host your app.
 

1. Get an account at Streamlit.com.

​

2. At Streamlit, choose “My Apps” and then click "Create app" on the top right.

create_app_edited.jpg

3. Select 'Deploy a public app from Github'. Before you execute this step, make sure you upload your code to a public repository.

4. Complete the necessary details of the app deployment.

5. To use an OpenAI api key, click on "Advanced settings". Set the key with OPENAI_API_KEY="".

6. Click "Save" and then "Deploy".

​

You will then get a URL which has your app available for use by others. You can simply share the link of the app with others.

Advanced Chatbot

There are several other samples in the library which are advanced chatbot with different features.

Some of which are mentioned below

  • ChatAppwithSamplePrompts: On giving a topic, the chatbot will generate some questions / prompts you related to the topic.​

​

  • ChatAppWithGenerateList: On giving a prompt it can generate a list of somekind associated with the topic. You can specify the number of items you want in the list and the number of words per item.

​​

  • ChatAppWithTTSResponseStreamlit: Takes your prompt and converts to audio file and returns the response in audio format as well.

​​

  • VoiceChatStreamlit: Allows users to have a voice conversation. You can give prompts via speech and then get response in audio format. â€‹â€‹

RAG / Custom GPTs (Assistants)

The PeopleCode.ai library has methods for calling custom GPTs, which are called "assistants" at OpenAI. OpenAI assigns an id to every assistant. In your PeopleCode.ai Library calls, you can provide the assistant id as a parameter so that your requests are answered using information in the document set instead of the broader frontier.

 

For example, a professor might upload course notes and/or a book into an "assistant", and let students ask questions of it. Here is a sample app for asking questions of my (Professor Wolber's) Thunkable book. You can run this app by running AskThunkable.py from Streamlit Apps.

How to Create an Assistant?

1. Open your Open AI's API account.

​

2. Click on 'Playground'.

click_on_playground_edited.jpg

3. Click on 'Assistants'.

4. Click on arrow sign next to Assistant ID. A drop down menu with a list of all the current assistants should appear. Select 'Create assistant' option from the menu.

assistant_id_click_edited.jpg
create_assistant_edited.jpg

5. It opens a new assistant with a uniquely generated Assistant ID. This Assistant ID is important, so be sure to copy it and take note of it. Add a name to the assistant. This name will represent the collection of documents you are creating. For example, if you are building a library of research papers relevant to your work, you can name the assistant 'Research Paper Collection.'

name_assistant_edited.jpg

6. Scroll down to 'Tools' section of the Assistant. Under that enable the 'File Search Option'. Click on '+ Files' icon to add the necessary documents.

7. 'Attach files to file search menu' will pop up. You are now starting to build your own custom knowledge base that will be referred to by your chatbot in future. Drag your files of use the 'Upload' button to add all the necessaty files. Once you are done adding all your necessary files, click on 'Attach' button. You always have the choice to modify - add or delete - your files from the knowledge base as and when needed.

8. You have now successfully created your knowledge base / custom assistant. You can test out your assistant in the chatbot next to it. Now go to your code, and you can simply add the assistant id as a variable. Here is a sample of how we did in AskThunkableBook.py sample that is a part of the library.

​

# Set assistant ID if using specific assistant functionality

ASSISTANT_ID = "asst_LBdQmnU4xdzxRhZ822zNZk4q";

(For any function that required an assistant, we simply called on the ASSISTANT_ID variable.)

# Ask button

if st.button("Ask"):

if user_prompt:

response = conversation.ask_question(st.session_state.instructions, user_prompt, ASSISTANT_ID)

st.text_area("Response:", response, height=200)​

© 2025 PeopleCode.AI.

bottom of page