ForOpenAI - A Fortran library for OpenAI API

I am excited to introduce the most recent release of the ForOpenAI package! This Fortran package introduces new opportunities for integrating OpenAI’s capabilities directly into your Fortran applications. In this latest release, I have incorporated three key enhancements: Chat Completion, Conversation and Transcription.

Absolutely, contributions to ForOpenAI are warmly welcome! Your collaboration can help make this library even more valuable for the Fortran community. Feel free to join the project and share your ideas and improvements.

Thanks to http-client, json-fortran and FACE.

17 Likes

Thanks @ali to offer that tool to the community. And it is great to see that the brand new http-client is already used in another tool as a fpm dependency.

Could you present a few ideas of what could be done in Fortran with your library?

2 Likes

I think this could be interesting as a helper plugin for fpm:

$ fpm gpt? Please tell me the purpose of module X.
   ...
$ fpm gpt? Show me a list of pure functions.
  ...
$ fpm gpt? Suggest a docstring for procedure linsolve.
   ...
$ fpm gpt? How do I tell fpm to build in release mode?
  ...
$ fpm gpt? Generate a template for root-solving using the roots-fortran library
  ...
$ fpm gpt? Generate a file solve.f90 with an example of solving a linear system using lapack
   ...
$ fpm gpt? What is Intel Fortran equivalent for the gcc -Wall option?
  ...
$ fpm gpt? Suggest me some fpm packages for root-solving.
  ...

You could make fpm store all successful commands (not the gpt? ones) in a database to be used as a training dataset, for an auto-correct feature.

Instead of OpenAPI, perhaps you could also use fastGPT or other Fortran LLM’s to give you advice like this. But I lack the full picture of how these things work. It could be interesting to eliminate some round-trips to the browser and back. Instead you just remain comfortably within your IDE / tmux / vi+terminal session.

One more idea would be to train the thing on the compiler documentation from GCC and Intel, and provide suggestions on which compiler flags to pick.

Once the fpm registry is up, it should become easier to train a Fortran-only transformer. We also have the Package Index. Gary Klimowicz (cc @gak) has made a GitHub repository with several Fortran packages as git submodules.
Of course this has some ethical questions to it, i.e. do authors of the package registry agree to such data mining.

5 Likes

First, I should mention that this version includes Chat GPT. You can use it in the terminal or input a text file. It also includes the feature to convert audio to text, which essentially takes an input file and converts it to text.

For the next version, I am working on adding the ability to create and edit images. After that, I believe we can proceed to submit this unofficial version to the OpenAI website. I attempted this through the provided form on the website, but I haven’t received a response yet.

Finally, I think in the next version, by adding the ability for function calling, we can perform more useful tasks without the need for training new data. For example, using GPT and function calling, it may be possible to utilize it in the following ways(these are some basic ideas, I don’t know if they are all possible):

  • How to use the intrinsic pack function in Fortran? This can call a help function if it exists.
  • Use ‘fpm’ to create a new project named ‘my_project’ and include ‘foropenai’ as a dependency! This can call a ‘create a new project’ function of ‘fpm’ if it exists.
  • Compile Fortran code located at ‘~/my_code.f90’ using an online compiler. This can utilize an online compiler API to compile a Fortran code.
  • Debug my Fortran project under ‘~/my_project’ using ‘lfortran’. This can use ‘fpm’ to debug the project using ‘lfortran’!
  • Create a B-spline using this knot vector [0, 0, 0.5, 1, 1]. This can call a B-spline function, if it exists to create a B-spline!
  • Run ‘my_project’ under ‘~/my_project’ using these input variables: a = 10, b = 5, L = 25.
  • And many more opportunities that you can imagine!
3 Likes

The latest version of ForOpenAI supports:

  • Image generation based on a text description.
  • Translation of audio files into English.

Next steps:

  • Editing or extending images.
  • Implementing function calling.
1 Like