{"id":22820840,"url":"https://github.com/gha3mi/foropenai","last_synced_at":"2025-08-02T16:36:38.478Z","repository":{"id":184215417,"uuid":"671237594","full_name":"gha3mi/foropenai","owner":"gha3mi","description":"ForOpenAI - A Fortran library for OpenAI API.","archived":false,"fork":false,"pushed_at":"2024-01-10T22:31:09.000Z","size":7538,"stargazers_count":19,"open_issues_count":7,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T01:57:04.908Z","etag":null,"topics":["api","chatgpt","dall-e","fortran","fortran-package-manager","gpt","openai","openai-api","whisper"],"latest_commit_sha":null,"homepage":"https://gha3mi.github.io/foropenai/","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gha3mi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-26T21:31:40.000Z","updated_at":"2025-03-15T15:33:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"f87596e7-7fbe-4420-8b0a-e403f914cde1","html_url":"https://github.com/gha3mi/foropenai","commit_stats":null,"previous_names":["gha3mi/foropenai"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha3mi%2Fforopenai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha3mi%2Fforopenai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha3mi%2Fforopenai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gha3mi%2Fforopenai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gha3mi","download_url":"https://codeload.github.com/gha3mi/foropenai/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250354303,"owners_count":21416751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","chatgpt","dall-e","fortran","fortran-package-manager","gpt","openai","openai-api","whisper"],"created_at":"2024-12-12T15:42:37.859Z","updated_at":"2025-04-23T01:57:10.984Z","avatar_url":"https://github.com/gha3mi.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub](https://img.shields.io/badge/GitHub-ForOpenAI-blue.svg?style=social\u0026logo=github)](https://github.com/gha3mi/foropenai)\n[![Version](https://img.shields.io/github/release/gha3mi/foropenai.svg)](https://github.com/gha3mi/foropenai/releases/latest)\n[![Documentation](https://img.shields.io/badge/ford-Documentation%20-blueviolet.svg)](https://gha3mi.github.io/foropenai/)\n[![License](https://img.shields.io/github/license/gha3mi/foropenai?color=yellow)](https://github.com/gha3mi/foropenai/blob/main/LICENSE)\n[![CI_test](https://github.com/gha3mi/foropenai/actions/workflows/CI_test.yml/badge.svg)](https://github.com/gha3mi/foropenai/actions/workflows/CI_test.yml)\n\n\u003cimg alt=\"ForOpenAI\" src=\"https://github.com/gha3mi/foropenai/raw/main/media/logo.png\" width=\"750\"\u003e\n\n**ForOpenAI**: An **unofficial** Fortran library for OpenAI.\n\n## How to use\n\n**Prerequisites:**\n\nOn Ubuntu, you need to install the curl development headers. Use the following command:\n\n```shell\nsudo apt install -y libcurl4-openssl-dev\n```\n\n**Clone the repository:**\n\nYou can clone the ForOpenAI repository from GitHub using the following command:\n\n```shell\ngit clone https://github.com/gha3mi/foropenai.git\n```\n\n```shell\ncd foropenai\n```\n\n**OpenAI API Key Configuration:**\n\nYour Secret API key can be located by accessing the OpenAI [User settings](https://platform.openai.com/account/api-keys).\n\nFor enhanced security and convenience, it is strongly recommended to configure the API key as an environment variable. \n\n- On Ubuntu, use the following command, replacing `\"your_api_key\"` with your actual API key:\n\n    ```shell\n    export OPENAI_API_KEY=\"your_api_key\"\n    ```\n\n- (Optional) If desired for organizational purposes, you can also establish an optional environment variable on Ubuntu:\n\n    ```shell\n    export OPENAI_ORG=\"your_organization\"\n    ```\n\n- Alternatively, the OpenAI API key can be included in the `foropenai.json` configuration file.\n\n    ```json\n    {\n        \"base\": {\n            \"api_key\": \"OPENAI_API_KEY\",\n            \"organization\": \"\"\n        }\n    }\n    ```\n\n**Use ChatGPT from the terminal:**\n\n```shell\nfpm run\n```\n\n**Example**\n\n![Alt text](media/example.png)\n\n## Audio\n\n### Create transcription\n\n```fortran\nprogram test_Transcription\n\n   use foropenai, only: Transcription\n\n   implicit none\n\n   type(Transcription) :: trs\n\n   call trs%set_base_data(file_name='foropenai.json')\n   call trs%set(file_name='foropenai.json')\n\n   call trs%create(file='test/audio.mp3')\n   call trs%print_file()\n   call trs%print_assistant_response()\n\n   call trs%finalize()\n\nend program test_Transcription\n```\n\n#### Settings\n\n`foropenai.json`\n\n```json\n{\n    \"base\": {\n        \"api_key\": \"OPENAI_API_KEY\",\n        \"organization\": \"\"\n    },\n\n    \"Transcription\": {\n        \"url\": \"https://api.openai.com/v1/audio/transcriptions\",\n        \"model\": \"whisper-1\",\n        \"temperature\": 0.0,\n        \"language\": \"en\",\n        \"response_format\": \"json\"\n    }\n}\n```\n\n\u003caudio src=\"test/audio.mp3\" controls title=\"Transcription\"\u003e\u003c/audio\u003e\n\n#### Result\n\n```shell\nfile: test/audio.mp3\nWhisper: FORTRAN stands for Formula Translation.\n```\n\n### Create translation\n\n```fortran\nprogram test_Translation\n\n   use foropenai, only: Translation\n\n   implicit none\n\n   type(Translation) :: trs\n\n   call trs%set_base_data(file_name='foropenai.json')\n   call trs%set(file_name='foropenai.json')\n\n   call trs%create(file='test/audio_de.mp3')\n   call trs%print_file()\n   call trs%print_assistant_response()\n\n   call trs%finalize()\n\nend program test_Translation\n```\n\n#### Settings\n\n`foropenai.json`\n\n```json\n{\n    \"base\": {\n        \"api_key\": \"OPENAI_API_KEY\",\n        \"organization\": \"\"\n    },\n\n    \"Translation\": {\n        \"url\": \"https://api.openai.com/v1/audio/translations\",\n        \"model\": \"whisper-1\",\n        \"temperature\": 0.0,\n        \"response_format\": \"json\"\n    }\n}\n```\n\n\u003caudio src=\"test/audio_de.mp3\" controls title=\"Translation\"\u003e\u003c/audio\u003e\n\n#### Result\n\n```shell\nfile: test/audio_de.mp3\nWhisper: FORTRAN stands for Formula Translation and is a programming language.\n```\n\n## Chat\n\n### Create chat completion\n\n```fortran\nprogram test_ChatCompletion\n\n   use foropenai, only: ChatCompletion\n\n   implicit none\n\n   type(ChatCompletion) :: chat\n\n   call chat%set_base_data(file_name='foropenai.json')\n   call chat%set(file_name='foropenai.json')\n\n   call chat%init_messages(n=3)\n   call chat%messages(1)%set(role='system', content='You are a helpful assistant.')\n   call chat%messages(2)%set(role='user', content='Hello?')\n   call chat%messages(3)%set(role='assistant', content='')\n\n   call chat%print_user_message()\n   call chat%create()\n   call chat%print_assistant_response()\n\n   call chat%usage%print()\n\n   call chat%finalize()\n\nend program test_ChatCompletion\n```\n\n#### Settings\n\n`foropenai.json`\n\n```json\n{\n    \"base\": {\n        \"api_key\": \"OPENAI_API_KEY\",\n        \"organization\": \"\"\n    },\n\n    \"ChatCompletion\": {\n        \"user_name\": \"Ali\",\n        \"url\": \"https://api.openai.com/v1/chat/completions\",\n        \"model\": \"gpt-3.5-turbo\",\n        \"temperature\": 1.0,\n        \"max_tokens\": 200,\n        \"top_p\": 1.0,\n        \"frequency_penalty\": 0.0,\n        \"presence_penalty\": 0.0,\n        \"n\": 1,\n        \"stream\": false\n    }\n}\n```\n\n#### Result\n\n```shell\nAli: Hello?\nChatGPT: Hello! How can I assist you today?\n```\n\n## Image\n\n### Image Generation\n\n```fortran\nprogram test_ImageGeneration\n\n   use foropenai, only: ImageGeneration\n\n   implicit none\n\n   type(ImageGeneration) :: image\n\n   call image%set_base_data(file_name='foropenai.json')\n   call image%set(file_name='foropenai.json')\n\n   call image%create(prompt='a cat with a computer')\n   call image%print_prompt()\n   call image%print_assistant_response()\n\n   call image%finalize()\n\nend program test_ImageGeneration\n```\n\n#### Settings\n\n`foropenai.json`\n\n```json\n{\n    \"base\": {\n        \"api_key\": \"OPENAI_API_KEY\",\n        \"organization\": \"\"\n    },\n\n    \"ImageGeneration\": {\n        \"user_name\": \"Ali\",\n        \"url\": \"https://api.openai.com/v1/images/generations\",\n        \"size\": \"1024x1024\",\n        \"n\": 1,\n        \"response_format\": \"url\"\n    }\n}\n```\n\n#### Result\n\n\u003cimg src=\"test/image.png\" alt=\"image\" width=\"200\" height=\"\" /\u003e\n\n## fpm dependency\n\nIf you want to use `ForOpenAI` as a dependency in your own fpm project,\nyou can easily include it by adding the following line to your `fpm.toml` file:\n\n```toml\n[dependencies]\nforopenai = {git=\"https://github.com/gha3mi/foropenai.git\"}\n```\n\n## API documentation\n\nThe most up-to-date API documentation for the master branch is available\n[here](https://gha3mi.github.io/foropenai/).\nTo generate the API documentation for `ForOpenAI` using\n[ford](https://github.com/Fortran-FOSS-Programmers/ford) run the following\ncommand:\n\n```shell\nford ford.yml\n```\n\n## Contributing\n\nContributions to `ForOpenAI` are welcome!\nIf you find any issues or would like to suggest improvements, please open an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgha3mi%2Fforopenai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgha3mi%2Fforopenai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgha3mi%2Fforopenai/lists"}