Initial Checkin of the AI-projects
This commit is contained in:
43
.gitignore
vendored
Normal file
43
.gitignore
vendored
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
*.swp
|
||||||
|
*.*~
|
||||||
|
project.lock.json
|
||||||
|
.DS_Store
|
||||||
|
*.pyc
|
||||||
|
nupkg/
|
||||||
|
|
||||||
|
# Visual Studio Code
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
# Rider
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Visual Studio
|
||||||
|
.vs/
|
||||||
|
|
||||||
|
# Fleet
|
||||||
|
.fleet/
|
||||||
|
|
||||||
|
# Code Rush
|
||||||
|
.cr/
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
build/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Oo]ut/
|
||||||
|
msbuild.log
|
||||||
|
msbuild.err
|
||||||
|
msbuild.wrn
|
||||||
32
simpleOpenAiAzureChatBot/Program.cs
Normal file
32
simpleOpenAiAzureChatBot/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using Azure;
|
||||||
|
using Azure.AI.OpenAI;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
var client=new OpenAIClient(new Uri("https://espopenaitest1.openai.azure.com/"), new AzureKeyCredential("simpleChatBot.Keys.OpenAIKey"));
|
||||||
|
//var options=new ChatCompletionsOptions { MaxTokens = 4096, Temperature = 0.7f, ChoicesPerPrompt = 1 };
|
||||||
|
var options=new ChatCompletionsOptions { MaxTokens = 4096, Temperature = 0.7f };
|
||||||
|
|
||||||
|
options.Messages.Add(new ChatMessage(ChatRole.System, """
|
||||||
|
You are a friendly and funny chap, used to amuse an online audience.
|
||||||
|
You respond as if you were John Cleese from Monty Python but with an old-English, medieval way of talking.
|
||||||
|
"""));
|
||||||
|
|
||||||
|
while (true){
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.Write(">> ");
|
||||||
|
var prompt = Console.ReadLine();
|
||||||
|
if (prompt?.ToLower() == "exit") break;
|
||||||
|
|
||||||
|
options.Messages.Add(new ChatMessage(ChatRole.User, prompt));
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine();
|
||||||
|
var currentResponse = String.Empty;
|
||||||
|
//var response = await client.GetChatCompletionsAsync("ESPChatTest",options);
|
||||||
|
var response = await client.GetChatCompletionsAsync(options);
|
||||||
|
|
||||||
|
Console.WriteLine(response.Value.Choices[0].Message.Content);
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
options.Messages.Add(new ChatMessage(ChatRole.Assistant, currentResponse));
|
||||||
|
}
|
||||||
14
simpleOpenAiAzureChatBot/simpleChatBot.csproj
Normal file
14
simpleOpenAiAzureChatBot/simpleChatBot.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.9" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
25
simpleOpenAiAzureChatBot/simpleChatBot.sln
Normal file
25
simpleOpenAiAzureChatBot/simpleChatBot.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.002.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "simpleChatBot", "simpleChatBot.csproj", "{225DB841-135B-4D4C-B66F-462516705837}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{225DB841-135B-4D4C-B66F-462516705837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{225DB841-135B-4D4C-B66F-462516705837}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{225DB841-135B-4D4C-B66F-462516705837}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{225DB841-135B-4D4C-B66F-462516705837}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {F32F20DA-CA42-422F-B5FF-3166D6149D35}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
63
simpleOpenAiDirectChatBot/Program.cs
Normal file
63
simpleOpenAiDirectChatBot/Program.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static async Task Main()
|
||||||
|
{
|
||||||
|
string apiKey = "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";
|
||||||
|
string prompt = "What is the meaning of life?";
|
||||||
|
|
||||||
|
string response = await GetChatGPTResponse(apiKey, prompt);
|
||||||
|
|
||||||
|
Console.WriteLine("ChatGPT Response: ");
|
||||||
|
Console.WriteLine(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
static async Task<string> GetChatGPTResponse(string apiKey, string prompt)
|
||||||
|
{
|
||||||
|
using (HttpClient client = new HttpClient())
|
||||||
|
{
|
||||||
|
string apiUrl = "https://api.openai.com/v1/chat/completions";
|
||||||
|
|
||||||
|
// Prepare the request data
|
||||||
|
var requestData = new
|
||||||
|
{
|
||||||
|
messages = new[] {
|
||||||
|
new { role = "system", content = "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." },
|
||||||
|
new { role = "user", content = "Compose a poem that explains the concept of recursion in programming." }
|
||||||
|
},
|
||||||
|
model = "gpt-3.5-turbo",
|
||||||
|
max_tokens = 100,
|
||||||
|
temperature = 0.7
|
||||||
|
};
|
||||||
|
|
||||||
|
string jsonData = JsonSerializer.Serialize(requestData);
|
||||||
|
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
// Set OpenAI API key in the Authorization header
|
||||||
|
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
|
||||||
|
|
||||||
|
// Make the API request
|
||||||
|
HttpResponseMessage response = await client.PostAsync(apiUrl, content);
|
||||||
|
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
|
//Console.WriteLine(responseBody);
|
||||||
|
var responseObject = JsonDocument.Parse(responseBody);
|
||||||
|
return responseObject?.RootElement.GetProperty("choices")[0].GetProperty("message").GetProperty("content").ToString().Trim();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: {response.StatusCode}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
simpleOpenAiDirectChatBot/appsettings.json
Normal file
6
simpleOpenAiDirectChatBot/appsettings.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"OpenAICredentials": {
|
||||||
|
"ApiKey": "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",
|
||||||
|
"ApiHost": "https://api.openai.com/v1/"
|
||||||
|
}
|
||||||
|
}
|
||||||
14
simpleOpenAiDirectChatBot/simpleOpenAiDirectChatBot.csproj
Normal file
14
simpleOpenAiDirectChatBot/simpleOpenAiDirectChatBot.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="OpenAI.ChatGPT" Version="3.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
25
simpleOpenAiDirectChatBot/simpleOpenAiDirectChatBot.sln
Normal file
25
simpleOpenAiDirectChatBot/simpleOpenAiDirectChatBot.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.002.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "simpleOpenAiDirectChatBot", "simpleOpenAiDirectChatBot.csproj", "{4FDE452E-E09C-44D3-B6B7-6298BCF8CF35}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4FDE452E-E09C-44D3-B6B7-6298BCF8CF35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4FDE452E-E09C-44D3-B6B7-6298BCF8CF35}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4FDE452E-E09C-44D3-B6B7-6298BCF8CF35}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4FDE452E-E09C-44D3-B6B7-6298BCF8CF35}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {79592704-E9CD-4A38-821E-7D80E745FD19}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user