{"id":13645546,"url":"https://github.com/johniwasz/whetstone.chatgpt","last_synced_at":"2025-05-16T19:07:42.664Z","repository":{"id":65143954,"uuid":"583474990","full_name":"johniwasz/whetstone.chatgpt","owner":"johniwasz","description":"A simple light-weight library that wraps the Open AI API.","archived":false,"fork":false,"pushed_at":"2025-04-27T17:16:44.000Z","size":659527,"stargazers_count":95,"open_issues_count":5,"forks_count":18,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-27T18:21:16.550Z","etag":null,"topics":["chatgpt","dotnet","dotnet-standard2","dotnet-standard2-1","gpt-3","gpt-35-turbo","gpt-4","openai","whisper","whisper-ai"],"latest_commit_sha":null,"homepage":"https://johniwasz.github.io/whetstone.chatgpt/","language":"CSS","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/johniwasz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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,"zenodo":null}},"created_at":"2022-12-29T22:22:26.000Z","updated_at":"2025-04-27T17:06:45.000Z","dependencies_parsed_at":"2024-01-14T10:00:55.926Z","dependency_job_id":"eda819d9-fe51-497d-818b-377808ff1367","html_url":"https://github.com/johniwasz/whetstone.chatgpt","commit_stats":{"total_commits":61,"total_committers":2,"mean_commits":30.5,"dds":"0.19672131147540983","last_synced_commit":"c6dba7e5edf436bc58ae149d84f04f940bbd7f89"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johniwasz%2Fwhetstone.chatgpt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johniwasz%2Fwhetstone.chatgpt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johniwasz%2Fwhetstone.chatgpt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johniwasz%2Fwhetstone.chatgpt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johniwasz","download_url":"https://codeload.github.com/johniwasz/whetstone.chatgpt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254592395,"owners_count":22097013,"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":["chatgpt","dotnet","dotnet-standard2","dotnet-standard2-1","gpt-3","gpt-35-turbo","gpt-4","openai","whisper","whisper-ai"],"created_at":"2024-08-02T01:02:36.994Z","updated_at":"2025-05-16T19:07:42.642Z","avatar_url":"https://github.com/johniwasz.png","language":"CSS","funding_links":[],"categories":["Openai","API tools","SDK, Libraries, Frameworks"],"sub_categories":["JavaScript","C# library, sdk or frameworks"],"readme":"[![CodeQL](https://github.com/johniwasz/whetstone.chatgpt/actions/workflows/codeql.yml/badge.svg)](https://github.com/johniwasz/whetstone.chatgpt/actions/workflows/codeql.yml)\n\n# Whetstone.ChatGPT\n\nA simple light-weight library that wraps the Open AI API with support for dependency injection.\n\nSupported features include:\n\n- GPT 4, GPT 3.5 Turbo and Chat Completions\n- Audio Transcription and Translation (Whisper API)\n- Chat Completions\n- Vision Completions\n- Files\n- Fine Tunes\n- Images\n- Embeddings\n- Moderations\n- Response streaming\n\nFor a video walkthrough of a Blazor web app built on this library, please see:\n\nhttps://user-images.githubusercontent.com/44126651/224557966-cbbb6b67-0f6c-4bf7-9416-b8114cd06de8.mp4\n\nThis is deployed to github pages and available at: [Open AI UI](https://johniwasz.github.io/whetstone.chatgpt/). Source for the Blazor web app is at [Whetstone.ChatGPT.Blazor.App](https://github.com/johniwasz/whetstone.chatgpt/tree/main/src/examples/blazor/Whetstone.ChatGPT.Blazor.App/Whetstone.ChatGPT.Blazor.App).\n\n[Examples](https://github.com/johniwasz/whetstone.chatgpt/tree/main/src/examples) include:\n\n- [Command line bot](https://github.com/johniwasz/whetstone.chatgpt/tree/main/src/examples/Whetstone.ChatGPT.SimpleCommandlineBot)\n\n## Dependency Injection Quickstart\n\n```C#\nservices.Configure\u003cChatGPTCredentials\u003e(options =\u003e\n{    \n    options.ApiKey = \"YOURAPIKEY\";\n    options.Organization = \"YOURORGANIZATIONID\";\n});\n```\n\nUse: \n```C#\nservices.AddHttpClient();\n```\nor:\n```C#\nservices.AddHttpClient\u003cIChatGPTClient, ChatGPTClient\u003e();\n```\nConfigure `IChatGPTClient` service:\n```C#\nservices.AddScoped\u003cIChatGPTClient, ChatGPTClient\u003e();\n```\n\n## Chat Completions\n\nChat completions are a special type of completion that are optimized for chat. They are designed to be used in a conversational context.\n\n### Chat Completion Quickstart\n\nThis shows a usage of the GPT-3.5 Turbo model.\n\n``` C#\nusing Whetstone.ChatGPT;\nusing Whetstone.ChatGPT.Models;\n\n. . .\n\nvar gptRequest = new ChatGPTChatCompletionRequest\n{\n    Model = ChatGPT35Models.Turbo,\n    Messages = new List\u003cChatGPTChatCompletionMessage\u003e()\n        {\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.System, \"You are a helpful assistant.\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.User, \"Who won the world series in 2020?\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.Assistant, \"The Los Angeles Dodgers won the World Series in 2020.\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.User, \"Where was it played?\")\n        },\n    Temperature = 0.9f,\n    MaxTokens = 100\n};\n\nusing IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nvar response = await client.CreateChatCompletionAsync(gptRequest);\n\nConsole.WriteLine(response?.GetCompletionText());\n\n```\n\nGPT-4 models can also be used provided your account has been granted access to the [limited beta](https://openai.com/waitlist/gpt-4).\n\n## Completion\n\nCompletions use [models](https://beta.openai.com/docs/models) to answer a wide variety of tasks, including but not limited to classification, sentiment analysis, answering questions, etc. \n\n### Completion Quickstart\n\nThis shows a direct useage of the __gpt-3.5-turbo-instruct__ model without any prompts.\n\nPlease note, _CreateCompletionAsync_ is obsolete. Use _ChatGPTChatCompletionRequest_, _ChatGPTChatCompletionResponse_, and the _CreateChatCompletionAsync_ method instead.\n\n``` C#\nusing Whetstone.ChatGPT;\nusing Whetstone.ChatGPT.Models;\n\n. . .\n\nvar gptRequest = new ChatGPTCompletionRequest\n{\n    Model =  ChatGPT35Models.Gpt35TurboInstruct,\n    Prompt = \"How is the weather?\"\n};\n\nusing IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nvar response = await client.CreateCompletionAsync(gptRequest);\n\nConsole.WriteLine(response.GetCompletionText());\n```\n\nGPT-3.5 is not deterministic. One of the test runs of the sample above returned:\n\n\u003e The weather can vary greatly depending on location. In general, you can expect temperatures to be moderate and climate to be comfortable, but it is always best to check the forecast for your specific area.\n\n### Completion Code Sample\n\nA C# console application that uses completions is available at:\n\n[Whetstone.ChatGPT.CommandLineBot (chatgpt-marv)](https://github.com/johniwasz/whetstone.chatgpt/tree/main/src/examples/Whetstone.ChatGPT.CommandLineBot)\n\nThis sample includes:\n\n- Authentication\n- Created a completion request using a prompt\n- Processing completion responses\n\n## File Quickstart\n\nHow to create a upload a new fine tuning file.\n\n``` C#\n\nList\u003cChatGPTTurboFineTuneLine\u003e tuningInput = new() \n{\n    new ChatGPTTurboFineTuneLine()\n        { \n            Messages = new List\u003cChatGPTTurboFineTuneLineMessage\u003e()\n            { \n                 new(ChatGPTMessageRoles.System, \"Marv is a factual chatbot that is also sarcastic.\"),\n                 new(ChatGPTMessageRoles.User, \"What's the capital of France?\"),\n                 new(ChatGPTMessageRoles.Assistant, \"Paris, as if everyone doesn't know that already.\")\n            },\n        },\n    new ChatGPTTurboFineTuneLine()\n        {\n            Messages = new List\u003cChatGPTTurboFineTuneLineMessage\u003e()\n            {\n                 new(ChatGPTMessageRoles.System, \"Marv is a factual chatbot that is also sarcastic.\"),\n                 new(ChatGPTMessageRoles.User, \"Who wrote 'Romeo and Juliet'?\"),\n                 new(ChatGPTMessageRoles.Assistant, \"Oh, just some guy named William Shakespeare. Ever heard of him?\")\n            },\n        },\n    . . .\n};\n\nbyte[] tuningText = tuningInput.ToJsonLBinary();\n\nstring fileName = \"marvin.jsonl\";\n\nChatGPTUploadFileRequest? uploadRequest = new ChatGPTUploadFileRequest\n{\n    File = new ChatGPTFileContent\n    {\n        FileName = fileName,\n        Content = tuningText\n    }\n};\n\nChatGPTFileInfo? newTurboTestFile;\n\nusing (IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\"))\n{\n    newTurboTestFile = await client.UploadFileAsync(uploadRequest);\n}\n\n```\n\n## Fine Tuning Quickstart\n\nOnce the file has been created, get the fileId, and reference it when creating a new fine tuning.\n\n```C#\nIChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nuploadedFileInfo = await client.UploadFileAsync(uploadRequest);\n\nvar fileList = await client.ListFilesAsync();\nvar foundFile = fileList?.Data?.First(x =\u003e x.Filename.Equals(\"marvin.jsonl\"));\n\nChatGPTCreateFineTuneRequest tuningRequest = new ChatGPTCreateFineTuneRequest\n{\n    TrainingFileId = foundFile?.Id,\n    Model = \"gpt-3.5-turbo-1106\"\n};\n\nChatGPTFineTuneJob? tuneResponse = await client.CreateFineTuneAsync(tuningRequest);\n\nstring? fineTuneId = tuneResponse?.Id;\n\n```\n\nProcessing the fine tuning request will take some time. Once it finishes, the __Status__ will report \"succeeded\" and it's ready to be used in a completion request.\n\n```C#\nusing IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nChatGPTFineTuneJob? tuneResponse = await client.RetrieveFineTuneAsync(\"FINETUNEID\");\n\nif (tuneResponse.Status.Equals(\"succeeded\"))\n{\n    var gptRequest = new ChatGPTChatCompletionRequest\n    {\n        Model = \"FINETUNEID\",\n        Messages = new List\u003cChatGPTChatCompletionMessage\u003e()\n        {\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.System, \"You are a helpful assistant.\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.User, \"Who won the world series in 2020?\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.Assistant, \"The Los Angeles Dodgers won the World Series in 2020.\"),\n            new ChatGPTChatCompletionMessage(ChatGPTMessageRoles.User, \"Where was it played?\")\n        },\n        Temperature = 0.9f,\n        MaxTokens = 100\n    };\n    \n    var response = await client.CreateChatCompletionAsync(gptRequest);\n\n    Console.WriteLine(response?.GetCompletionText());\n\n```\n\n## Image Quickstart\n\nHere's an example that generates a 1024x1024 image.\n\n```C#\nChatGPTCreateImageRequest imageRequest = new()\n{\n    Prompt = \"A sail boat\",\n    Size = CreatedImageSize.Size1024,\n    ResponseFormat = CreatedImageFormat.Base64\n};\n\nusing IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nChatGPTImageResponse? imageResponse = await client.CreateImageAsync(imageRequest);\n\nvar imageData = imageResponse?.Data?[0];\n\nif (imageData != null)\n{\n    byte[]? imageBytes = await client.DownloadImageAsync(imageData);\n}\n```\n\n## Audio Transcription Quickstart\n\nHer's an example that transcribes an audio file using the Whisper.\n\n```C#\n\nstring audioFile = @\"audiofiles\\transcriptiontest.mp3\";\n\nbyte[] fileContents = File.ReadAllBytes(audioFile);\nChatGPTFileContent gptFile = new ChatGPTFileContent\n{\n    FileName = audioFile,\n    Content = fileContents\n};\n\nChatGPTAudioTranscriptionRequest? transcriptionRequest = new ChatGPTAudioTranscriptionRequest\n{\n    File = gptFile\n};\n\nusing IChatGPTClient client = new ChatGPTClient(\"YOURAPIKEY\");\n\nChatGPTAudioResponse? audioResponse = await client.CreateTranscriptionAsync(transcriptionRequest, true);\n\nConsole.WriteLine(audioResponse?.Text);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohniwasz%2Fwhetstone.chatgpt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohniwasz%2Fwhetstone.chatgpt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohniwasz%2Fwhetstone.chatgpt/lists"}