top of page

Integrating LLM in your applikation

Integrating Large Language Models (LLMs) can be a cost-effective way to enhance AI applications using effective prompting techniques. While LLMs simplify some development aspects, building complex applications typically requires combining them with other technologies and comprehensive development practices. By incorporating LLMs alongside essential components, developers can create sophisticated applications more efficiently.

llmIntegration.jpeg

Prerequisites:

  • You need an OpenAI account, which requires registering a credit card, but it's not too expensive. See OpenAI's pricing for details. Typically, $5 to $10 can support your usage for a reasonable period. It's also possible to limit costs by setting up usage limits and notification alerts in your account settings.

  • The examples are built using Python in Visual Studio Code (VS Code), so you need both VS Code and a Python installation. You also need to install necessary libraries using commands like pip install openai.

First, a bit of prompt engineering.

In ChatGPT, you have a prompt where you can write text and ask anything. You also have a paperclip icon where you can upload a file as 'content.' The content could be something you want ChatGPT to read and then do something based on it. The file you upload could be of any type—picture, text document, etc. Sometimes, I use ChatGPT to identify flowers by uploading a picture and asking for identification. There are various formatting techniques that can help ChatGPT perform its tasks more effectively.

There are also many variables you can use to customize how ChatGPT responds, such as making it adopt a particular persona or adjust how it reads your input and formats the output. For instance, using {Topic}, {Style}, {Length}, etc., allows you to tailor the response to meet specific needs.

Example: Finding the Explicit GPS Coordinates of a Town

P.S. To create this prompt, I used ChatGPT to generate the prompt text.

Prompt Structure Using Variables:

"Provide only the latitude and longitude coordinates for the center of [Town Name], [Country Name] in degrees, minutes, and seconds (DMS) format, without any additional text. Use the following format: Lat_Deg°Lat_Min'Lat_Sec"Lat_Dir, Lon_Deg°Lon_Min'Lon_Sec"Lon_Dir."

 

Result:

48°51'24"N, 2°21'8"E

 

This demonstrates that we can create an application that returns the coordinates using this prompt.

 

Steps to Create the Application:

  • Step 1: Create a new Visual Studio Code project named "GPSCoordinates".

  • Step 2: In your project, add a file named .env. In this file, add your api_key (this is to hide your key in your source code). Ensure that the .env file is added to your .gitignore file if Git is used, to prevent the API key from being committed to version control.

  • Step 3: Install necessary libraries, such as the OpenAI Python library or any geocoding libraries you plan to use.

    • Example: Run pip install openai or pip install geopy.

  • Step 4: Write the code to send the prompt to the API and handle the response.

    • Include sample code snippets to guide the reader.

bottom of page