Allegro Common Lisp ver 11.0 introduced support for OpenAI LLMs. In this article, let us look at some of the functions for interacting with OpenAI.
First we need to specify basic parameters such as the API key, LLM to use, Temperature, etc. I have defined a convenient function configure-openai to do this (full source is included at the end). So, let us launch the IDE and after loading our source file, execute this function:
I am using the “gpt-4o-mini” model for subsequent interaction.
The function list-openai-models returns a list of the currently supported models:
Let us define a simple function that asks the LLM a Math-related question:
As you can see, the function calls the built-in function ask-chat, finally returning a numeric value.
Let us see if this works as expected:
That is good! The answers are correct.
Another built-in function is ask-for-list. This sends a prompt to the LLM and returns the answer in the form of a list. Let us ask the LLM to give us a list of positive and negtive sentiment English words.
Another function ask-for-map is a variant of the above and it returns a list of key-value pairs. Let us ask for southern states of India and their respective capitals:
A further generalization of the above is ask-for-table, which returns multiple values as a table:
Here is the complete code that I wrote:
In addition to directly interacting with the LLM, Allegro CL also supports Vector database and RAG. I will discuss this in a future article.
It is not clear to me why Franz decided to support only OpenAI in this Alegro CL version. It is not difficult to support other vendors such as Anthropic and open-source models. That is a major disappointment for me. Hope they will include this in a future version soon.
Have a nice week!
Recent Comments