{"id":18745620,"url":"https://github.com/yazeedobaid/openai-fsharp","last_synced_at":"2025-04-12T21:32:57.763Z","repository":{"id":65667700,"uuid":"596555150","full_name":"yazeedobaid/openai-fsharp","owner":"yazeedobaid","description":"OpenAI - F# - A library that allows you to interact with OpenAI API in an easy, fluent, and typed way!","archived":false,"fork":false,"pushed_at":"2023-03-13T19:38:37.000Z","size":1990,"stargazers_count":59,"open_issues_count":2,"forks_count":5,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-11T09:59:55.568Z","etag":null,"topics":["api","fsharp","openai","openapi"],"latest_commit_sha":null,"homepage":"","language":"F#","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/yazeedobaid.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-02-02T12:51:24.000Z","updated_at":"2024-10-27T17:52:30.000Z","dependencies_parsed_at":"2023-02-18T05:16:06.971Z","dependency_job_id":null,"html_url":"https://github.com/yazeedobaid/openai-fsharp","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yazeedobaid%2Fopenai-fsharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yazeedobaid%2Fopenai-fsharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yazeedobaid%2Fopenai-fsharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yazeedobaid%2Fopenai-fsharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yazeedobaid","download_url":"https://codeload.github.com/yazeedobaid/openai-fsharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248636336,"owners_count":21137430,"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","fsharp","openai","openapi"],"created_at":"2024-11-07T16:18:54.627Z","updated_at":"2025-04-12T21:32:54.639Z","avatar_url":"https://github.com/yazeedobaid.png","language":"F#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\u003cdiv align=\"center\"\u003e\n    \u003cimg width=\"80%\" src=\"https://raw.githubusercontent.com/yazeedobaid/openai-fsharp/main/art/example-snippet.png\" alt=\"OpenAI F#\"\u003e\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003cp align=\"center\"\u003e\n        \u003ca href=\"https://github.com/yazeedobaid/openai-fsharp/actions\"\u003e\u003cimg alt=\"GitHub Workflow Status (main)\" src=\"https://img.shields.io/github/actions/workflow/status/yazeedobaid/openai-fsharp/build.yml?branch=main\u0026label=build\u0026style=round-square\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://github.com/yazeedobaid/openai-fsharp/blob/main/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/yazeedobaid/openai-fsharp\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://www.nuget.org/packages/OpenAI.Client\"\u003e\u003cimg alt=\"NuGet Version\" src=\"https://img.shields.io/nuget/v/openai.client?color=blue\"\u003e\u003c/a\u003e\n        \u003ca href=\"https://www.nuget.org/packages/OpenAI.Client\"\u003e\u003cimg alt=\"NuGet Version\" src=\"https://img.shields.io/nuget/dt/openai.client?color=green\"\u003e\u003c/a\u003e\n    \u003c/p\u003e\n\u003c/div\u003e\n\n------\n**OpenAI F#** is a library that allows you to interact with [Open AI API](https://beta.openai.com/docs/api-reference/introduction) in an easy,\nfluent, and typed way!\n\n## Get Started\n\nAdd the library to your project using DotNet CLI:\n\n```bash\ndotnet add package OpenAI.Client\n```\n\nOr using Paket:\n\n```bash\npaket add OpenAI.Client\n```\n\nThe library provide two styles to consume the APIs, either a methods calls through pipe operator as shown below:\n\n```fsharp\nopen OpenAI\nopen OpenAI.Client\nopen OpenAI.Models\n\nlet client =\n    Config(\n        { Endpoint = \"https://api.openai.com/v1\"\n          ApiKey = \"your-api-key\" },\n        HttpRequester()\n    )\n    \nlet result = client |\u003e models |\u003e list\n```\n\nOr using a computation expression builder object as shown below:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        models\n        list\n    }\n```\n\nYou can check OpenAI API reference at [API reference](https://platform.openai.com/docs/api-reference).\n\n## Usage\n\n### `Models` Resource\n\nList and describe the various models available in the API. You can refer to the Models documentation to understand \nwhat models are available and the differences between them.\n\n#### `list`\n\nLists the currently available models, and provides basic information about each one such as the owner and availability.\n\n```fsharp\nlet result = client |\u003e models |\u003e list\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        models\n        list\n    }\n```\n\n#### `retrieve`\n\nRetrieves a model instance, providing basic information about the model such as the owner and permissioning.\n\n```fsharp\nlet result = client |\u003e models |\u003e retrieve \"text-davinci-003\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        models\n        retrieve \"text-davinci-003\"\n    }\n```\n\n#### `delete`\n\nDelete a fine-tuned model.\n\n```fsharp\nlet result = client |\u003e models |\u003e delete \"curie:ft-acmeco-2021-03-03-21-44-20\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        models\n        delete \"curie:ft-acmeco-2021-03-03-21-44-20\"\n    }\n```\n\n\u003cbr /\u003e\n\n### `Completions` Resource\n\nGiven a prompt, the model will return one or more predicted completions, and can also return the probabilities \nof alternative tokens at each position.\n\n#### `create`\n\nCreates a completion for the provided prompt and parameters.\n\n```fsharp\nlet result =\n    client\n    |\u003e completions\n    |\u003e Completions.create\n        { Model = \"text-davinci-003\"\n          Prompt = \"What is the meaning of living?\"\n          Temperature = 0.5\n          Stop = \".\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n     endPoint \"https://api.openai.com/v1\"\n     apiKey \"your-api-key\"\n     completions\n     create\n        { Model = \"text-davinci-003\"\n          Prompt = \"What is the meaning of living?\"\n          Temperature = 0.5\n          Stop = \".\" }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Chat` Resource\n\nGiven a chat conversation, the model will return a chat completion response.\n\n#### `create`\n\nCreates a completion for the chat message.\n\n```fsharp\nlet result =\n    client\n    |\u003e chat\n    |\u003e create\n      { Model = \"text-davinci-003\"\n        Messages = [| {Role = \"user\"; Content = \"Hello!\"} |] }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n    endPoint (url \"\")\n    apiKey \"apiKey\"\n    chat\n    create\n      { Model = \"text-davinci-003\"\n        Messages = [| {Role = \"user\"; Content = \"Hello!\"} |] }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Edits` Resource\n\nGiven a prompt and an instruction, the model will return an edited version of the prompt.\n\n#### `create`\n\nCreates a new edit for the provided input, instruction, and parameters.\n\n```fsharp\nlet result =\n    client\n    |\u003e edits\n    |\u003e Edits.create\n           { Model = \"text-davinci-edit-001\"\n             Input = \"What day of the wek is it?\"\n             Instruction = \"Fix the spelling mistakes\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n     endPoint \"https://api.openai.com/v1\"\n     apiKey \"your-api-key\"\n     edits\n     create\n        { Model = \"text-davinci-edit-001\"\n         Input = \"What day of the wek is it?\"\n         Instruction = \"Fix the spelling mistakes\" }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Images` Resource\n\nGiven a prompt and/or an input image, the model will generate a new image.\n\n#### `create`\n\nCreates an image given a prompt.\n\n```fsharp\nlet result =\n    client\n    |\u003e images\n    |\u003e create\n         { Prompt = \"A cute baby sea otter\"\n           N = 2\n           Size = \"1024x1024\"\n           responseFormat = \"url\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        images\n        create\n            { Prompt = \"A cute baby sea otter\"\n              N = 2\n              Size = \"1024x1024\"\n              responseFormat = \"url\" }\n    }\n```\n\n#### `edit`\n\nCreates an edited or extended image given an original image and a prompt.\n\n```fsharp\nlet result =\n    client\n    |\u003e images\n    |\u003e edit\n        { Image = \"sample.png\"\n          Mask = \"sample.png\"\n          Prompt = \"A cute baby sea otter wearing a beret\"\n          N = 2\n          Size = \"1024x1024\"\n          responseFormat = \"url\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        images\n        edit\n            { Image = \"sample.png\"\n              Mask = \"sample.png\"\n              Prompt = \"A cute baby sea otter wearing a beret\"\n              N = 2\n              Size = \"1024x1024\"\n              responseFormat = \"url\" }\n    }\n```\n\n#### `variation`\n\nCreates a variation of a given image.\n\n```fsharp\nlet result =\n    client\n    |\u003e images\n    |\u003e variation\n        { Image = \"sample.png\"\n          N = 2\n          Size = \"1024x1024\"\n          responseFormat = \"url\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n     endPoint \"https://api.openai.com/v1\"\n     apiKey \"your-api-key\"\n     images\n     variation\n        { Image = \"sample.png\"\n          N = 2\n          Size = \"1024x1024\"\n          responseFormat = \"url\" }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Embeddings` Resource\n\nGet a vector representation of a given input that can be easily consumed by machine learning models and algorithms.\n\n#### `create`\n\nCreates an embedding vector representing the input text.\n\n```fsharp\nlet result =\n    client\n    |\u003e embeddings\n    |\u003e create\n        { Model = \"text-embedding-ada-002\"\n          Input = \"The food was delicious and the waiter...\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        embeddings\n        create\n             { Model = \"text-embedding-ada-002\"\n               Input = \"The food was delicious and the waiter...\" }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Audio` Resource\n\nTurn audio into text.\n\n#### `transcript`\n\nTranscribes audio into the input language.\n\n```fsharp\nlet result =\n    client\n    |\u003e audio\n    |\u003e transcript\n      { TranscriptRequest.Default with\n          File = \"sample-audio.mp3\"\n          Model = \"whisper-1\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n      endPoint (url \"\")\n      apiKey \"apiKey\"\n      audio\n      transcript\n          { TranscriptRequest.Default with\n              File = \"sample-audio.mp3\"\n              Model = \"whisper-1\" }\n    }\n```\n\n#### `translate`\n\nTranslates audio into into English.\n\n```fsharp\nlet result =\n    client\n    |\u003e audio\n    |\u003e translate\n      { File = \"sample-audio.mp3\"\n        Model = \"whisper-1\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n      endPoint (url \"\")\n      apiKey \"apiKey\"\n      audio\n      translate\n          { File = \"sample-audio.mp3\"\n            Model = \"whisper-1\" }\n    }\n```\n\n\u003cbr /\u003e\n\n### `Files` Resource\n\nFiles are used to upload documents that can be used with features like Fine-tuning.\n\n#### `list`\n\nReturns a list of files that belong to the user's organization.\n\n```fsharp\nlet result = client |\u003e files |\u003e list\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n     openAI {\n         endPoint \"https://api.openai.com/v1\"\n         apiKey \"your-api-key\"\n         files\n         list\n     }\n```\n\n#### `upload`\n\nUpload a file that contains document(s) to be used across various endpoints/features.\n\n```fsharp\nlet result =\n    client\n    |\u003e files\n    |\u003e upload\n        { File = @\"sample-json.txt\"\n          Purpose = \"fine-tune\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        files\n        upload\n             { File = @\"sample-json.txt\"\n               Purpose = \"fine-tune\" }\n    }\n```\n\n#### `delete`\n\nDelete a file.\n\n```fsharp\nlet result =\n    client\n    |\u003e files\n    |\u003e delete \"file-qtUwySute1Zf2yT6mWIGTCwq\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n         endPoint \"https://api.openai.com/v1\"\n         apiKey \"your-api-key\"\n         files\n         delete \"file-qtUwySute1Zf2yT6mWIGTCwq\"\n    }\n```\n\n#### `retrieve`\n\nReturns information about a specific file.\n\n```fsharp\nlet result = client |\u003e files |\u003e retrieve \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n         endPoint \"https://api.openai.com/v1\"\n         apiKey \"your-api-key\"\n         files\n         retrieve \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\"\n    }\n```\n\n#### `download`\n\nReturns the contents of the specified file.\n\n```fsharp\nlet result = client |\u003e files |\u003e download \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n         endPoint \"https://api.openai.com/v1\"\n         apiKey \"your-api-key\"\n         files\n         download \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\"\n    }\n```\n\n\u003cbr /\u003e\n\n### `FineTunes` Resource\n\nManage fine-tuning jobs to tailor a model to your specific training data.\n\n#### `create`\n\nCreates a job that fine-tunes a specified model from a given dataset.\n\n```fsharp\nlet result =\n    client\n    |\u003e fineTunes\n    |\u003e create { CreateRequest.Default with TrainingFile = \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result = \n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        fineTunes\n        create { CreateRequest.Default with TrainingFile = \"file-Lpe0n5tOHtoG6OVVbk5d4iXA\" }\n    }\n```\n\n#### `list`\n\nList your organization's fine-tuning jobs.\n\n```fsharp\nlet result = client |\u003e fineTunes |\u003e list\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        fineTunes\n        list\n    }\n```\n\n#### `retrieve`\n\nGets info about the fine-tune job.\n\n```fsharp\nlet result = client |\u003e fineTunes |\u003e retrieve \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        retrieve\n        retrieve \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n    }\n```\n\n#### `cancel`\n\nImmediately cancel a fine-tune job.\n\n```fsharp\nlet result = client |\u003e fineTunes |\u003e cancel \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n openAI {\n     endPoint \"https://api.openai.com/v1\"\n     apiKey \"your-api-key\"\n     fineTunes\n     cancel \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n }\n```\n\n#### `list events`\n\nGet fine-grained status updates for a fine-tune job.\n\n```fsharp\nlet result = client |\u003e fineTunes |\u003e listEvents \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n    openAI {\n        endPoint \"https://api.openai.com/v1\"\n        apiKey \"your-api-key\"\n        fineTunes\n        listEvents \"ft-kNJeZjAhlmFLdCuIzcpkrmNI\"\n    }\n```\n\n\u003cbr /\u003e\n\n### `Moderations` Resource\n\nGiven a input text, outputs if the model classifies it as violating OpenAI's content policy.\n\n#### `create`\n\nClassifies if text violates OpenAI's Content Policy.\n\n```fsharp\nlet result =\n client\n |\u003e moderations\n |\u003e create\n     { Model = \"text-moderation-latest\"\n       Input = \"I want to kill them.\" }\n```\n\nOr using a computation expression builder:\n\n```fsharp\nlet result =\n openAI {\n     endPoint \"https://api.openai.com/v1\"\n     apiKey \"your-api-key\"\n     moderations\n     create\n         { Model = \"text-moderation-latest\"\n           Input = \"I want to kill them.\" }\n }\n```\n\n## Credits\nThis library was inspired from [openai-php](https://github.com/openai-php/client) and [FsHttp](https://github.com/fsprojects/FsHttp).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyazeedobaid%2Fopenai-fsharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyazeedobaid%2Fopenai-fsharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyazeedobaid%2Fopenai-fsharp/lists"}