Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cer/faramir-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Faramir: An LLM powered microservice for validating and formatting phone numbers

I was recently reminded of a tweet from 3 years that described how some websites make it difficult to enter information, such as a phone number:

mytweet

The obvious solution is to use today’s golden hammer: an LLM, or more specifically, OpenAI’s GPT-4.

About Faramir

Faramir is a simple (micro)service that uses OpenAI to validate and format phone numbers. You could, for example, use Faramir to make it easier for users to enter phone numbers in a web form.

Technology stacks

There are the following versions of the service:

  • python-langchain - Python, FastAPI, and Langchain

  • spring-boot-spring-ai - Spring Boot and Spring AI

Running the service

Python:

export OPENAI_API_KEY=<your-openai-api-key>

$ uvicorn --reload faramir:app --port 8080

Spring Boot:

export OPENAI_API_KEY=<your-openai-api-key>

$ ./gradlew bootRun

Validating and parsing phone numbers

$ http POST localhost:8080/parse phoneNumber=5105551212
HTTP/1.1 200 OK
content-length: 27
content-type: application/json
date: Fri, 29 Mar 2024 22:25:58 GMT
server: uvicorn
{
    "result": "(510) 555-1212"
}

and

$ http POST localhost:8080/parse phoneNumber=510555121
HTTP/1.1 400 Bad Request
content-type: application/json
date: Fri, 29 Mar 2024 22:26:26 GMT
server: uvicorn

How it works - Python

The Python version of the service uses Langchain, which is a popular Python framework, to invoke OpenAI’s LLM to parse the phone number.

The code invokes the LLM with a prompt that instructs the LLM to validate the phone and, if it’s correct, return it in a standard format.

How it works - Spring Boot

The Spring Boot version of the service uses Spring AI, which is a new project that provides abstractions for developing AI-powered services in Spring Boot.

Why Faramir?

It’s important for a service to have an intention revealing name. Famamir, a character from Lord of the Rings, was chosen because to quote ChatGPT:

Faramir is known for his discernment, integrity, and the careful consideration he gives to his actions, much like the precision required in validating and formatting phone numbers. He’s also a communicator and a mediator in several key situations, making the link to a service that ensures communication can proceed smoothly quite appropriate.

Parody warning

The timing of this project is not a coincidence. It’s a parody of the current state of the industry where services often have intention obscuring names and it seems like every problem is should be solved by an LLM.

Having said that, this project is a simple example of how to use an LLM to solve what could be a real-world problem.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published