Creating Our Python AI Project

As noted in a previous blog post, we’ll be building our project on two platforms: Python and .NET (C#). For Python, we’ll build on Colab. For now, you can use a free account.

The first step is to get an OpenAI key, as described in this previous blog post (scroll to the bottom). Note, these are not free, but we’re talking a few dollars for this entire series of posts.

With that in hand, create a config.json file that looks like this:

{
    "API_KEY": "gl-U2FsdGVkX1/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/MA8peF",
}

Next, open a browser to colab.research.google.com. Create a new notebook.

Click on the folder icon on the left, and when you see a number of folders, drag your config file to that window…

We’ll need some modules, so in the first cell enter:

!pip install langchain==0.3.25 \
                langchain-core==0.3.65 \
                langchain-openai==0.3.24 \
                chromadb==1.3.4 \
                langchain-community==0.3.20 \
                pypdf==5.4.0

A lot of lines will follow as the correct modules are loaded, and then you will be instructed to restart the runtime. Do this once.

Now let’s add that config file. In the next cell enter

import json
import os

# Load the JSON file and extract values
file_name = "config.json"
with open(file_name, 'r') as file:
    config = json.load(file)
    os.environ['OPENAI_API_KEY'] = config.get("API_KEY") # Loading the API Key
 

After you run it (click on the triangle) You will see a green check mark next to the cell (on the left) and the time it took to run your command.

You are all set! In the next blog post we’ll instantiate our first LLM

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in AI and tagged , , . Bookmark the permalink.