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.
There are the following versions of the service:
-
python-langchain- Python, FastAPI, and Langchain -
spring-boot-spring-ai- Spring Boot and Spring AI
Python:
export OPENAI_API_KEY=<your-openai-api-key>
$ uvicorn --reload faramir:app --port 8080Spring Boot:
export OPENAI_API_KEY=<your-openai-api-key>
$ ./gradlew bootRun$ 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: uvicornThe 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.
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.
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.
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.