Skip to content

Commit 601685b

Browse files
author
thomaslrt05
committed
1 parent 0231327 commit 601685b

File tree

55 files changed

+2901
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2901
-169
lines changed

src/API-GenerateConference/.gitignore

+402
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<RootNamespace>API_GenerateConference</RootNamespace>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.14" />
12+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
13+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
14+
</ItemGroup>
15+
16+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@API_GenerateConference_HostAddress = http://localhost:5126
2+
3+
GET {{API_GenerateConference_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34622.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API-GenerateConference", "API-GenerateConference.csproj", "{9B98D1AA-D1E7-4329-AD17-13819763F83C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9B98D1AA-D1E7-4329-AD17-13819763F83C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9B98D1AA-D1E7-4329-AD17-13819763F83C}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9B98D1AA-D1E7-4329-AD17-13819763F83C}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9B98D1AA-D1E7-4329-AD17-13819763F83C}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B2BD11D8-E8C9-4C4B-81B0-1FE91C05ECD7}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
using Microsoft.AspNetCore.DataProtection.KeyManagement;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Azure;
4+
using Azure.AI.OpenAI;
5+
using static System.Environment;
6+
using System.Text;
7+
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Linq;
9+
using System.Threading.Tasks;
10+
using API_GenerateConference.Models;
11+
12+
13+
namespace API_GenerateConference.Controllers
14+
{
15+
[ApiController]
16+
[Route("[controller]")]
17+
public class GenerateConference : Controller
18+
{
19+
private string endpoint = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
20+
private string endpointDalle = GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT_DALLE");
21+
private string key = GetEnvironmentVariable("AZURE_OPENAI_API_KEY");
22+
23+
[HttpGet]
24+
public async Task<ActionResult<string>> GenerateText(string context)
25+
{
26+
OpenAIClient client = new(new Uri(endpoint), new AzureKeyCredential(key));
27+
StringBuilder generatedText = new StringBuilder("");
28+
var prompt = "You are tasked with delivering a presentation about "
29+
+ context +
30+
" you'll need a well-defined structure with 4 paragraphs. " +
31+
"first paragraph Introduce the context, " +
32+
"second paragraph : talk about its history, "+
33+
"third paragraph : explain what can be done with the context today, " +
34+
"fourth paragraph : then draw up a conclusion that covers all the points of the conference.";
35+
36+
try
37+
{
38+
var chatCompletionsOptions = new ChatCompletionsOptions()
39+
{
40+
DeploymentName = "gpt-35-turbo",
41+
Temperature = 0.4f,
42+
Messages = { new ChatRequestSystemMessage(prompt),}
43+
};
44+
45+
await foreach (StreamingChatCompletionsUpdate chatUpdate in client.GetChatCompletionsStreaming(chatCompletionsOptions))
46+
{
47+
if (chatUpdate.Role.HasValue)
48+
{
49+
generatedText.Append($"{chatUpdate.Role.Value.ToString().ToUpperInvariant()}: ");
50+
}
51+
if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate))
52+
{
53+
generatedText.Append(chatUpdate.ContentUpdate);
54+
}
55+
}
56+
return generatedText.ToString();
57+
}
58+
catch
59+
{
60+
return NotFound();
61+
}
62+
}
63+
64+
[HttpGet("GenerateUrlImage")]
65+
public async Task<ActionResult<string>> GenerateUrlImage(string context, int whichParagraph)
66+
{
67+
try
68+
{
69+
var client = new HttpClient();
70+
var request = new HttpRequestMessage(HttpMethod.Post, endpointDalle);
71+
request.Headers.Add("api-key", key);
72+
73+
var jsonContent = new JsonDalle
74+
{
75+
prompt = $" in the following context {context} generates a photo in relation to the {whichParagraph} paragraph ",
76+
size = "1024x1024",
77+
n = 1,
78+
quality = "hd",
79+
style = "vivid"
80+
};
81+
82+
var serializedContent = JsonConvert.SerializeObject(jsonContent);
83+
var content = new StringContent(serializedContent, Encoding.UTF8, "application/json");
84+
request.Content = content;
85+
86+
var response = await client.SendAsync(request);
87+
response.EnsureSuccessStatusCode();
88+
89+
var responseData = await response.Content.ReadAsStringAsync();
90+
var jsonObject = JObject.Parse(responseData);
91+
var imageUrl = jsonObject["data"][0]["url"].ToString();
92+
93+
return imageUrl;
94+
}
95+
catch (Exception ex)
96+
{
97+
return BadRequest(ex.Message);
98+
}
99+
}
100+
101+
102+
[HttpGet("GenerateConference")]
103+
public async Task<ActionResult<string>> GenerateConferance(string prompt)
104+
{
105+
try
106+
{
107+
var conferenceText = await GenerateText(prompt);
108+
Conference newConference = new Conference();
109+
if(conferenceText.Value != null)
110+
{
111+
try
112+
{
113+
newConference.ConferenceTalk = conferenceText.Value;
114+
for (int iParagraph = 1; iParagraph <= 4; iParagraph++)
115+
{
116+
var imageUrlResult = await GenerateUrlImage(newConference.ConferenceTalk, iParagraph);
117+
if (imageUrlResult != null && imageUrlResult.Value != null)
118+
{
119+
newConference.imagesUrl.Add(imageUrlResult.Value);
120+
}
121+
}
122+
return JsonConvert.SerializeObject(newConference);
123+
}
124+
catch(Exception ex)
125+
{
126+
return BadRequest(ex.Message);
127+
}
128+
}
129+
else { return BadRequest("GenerateText failed"); }
130+
}
131+
catch (Exception ex)
132+
{
133+
return BadRequest(ex.Message);
134+
}
135+
}
136+
137+
138+
}
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace API_GenerateConference.Models
2+
{
3+
public class Conference
4+
{
5+
public string ConferenceTalk;
6+
public List<string> imagesUrl;
7+
8+
public Conference()
9+
{
10+
imagesUrl = new List<string>();
11+
}
12+
13+
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace API_GenerateConference.Models
2+
{
3+
public class JsonDalle
4+
{
5+
public string prompt { get; set; }
6+
public string size { get; set; }
7+
public int n { get; set; }
8+
public string quality { get; set; }
9+
public string style { get; set; }
10+
}
11+
}

src/API-GenerateConference/Program.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
// Add services to the container.
4+
5+
builder.Services.AddControllers();
6+
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
7+
builder.Services.AddEndpointsApiExplorer();
8+
builder.Services.AddSwaggerGen();
9+
10+
var app = builder.Build();
11+
12+
// Configure the HTTP request pipeline.
13+
if (app.Environment.IsDevelopment())
14+
{
15+
app.UseSwagger();
16+
app.UseSwaggerUI();
17+
}
18+
19+
app.UseHttpsRedirection();
20+
21+
app.UseAuthorization();
22+
23+
app.MapControllers();
24+
25+
app.Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:23931",
8+
"sslPort": 44331
9+
}
10+
},
11+
"profiles": {
12+
"http": {
13+
"commandName": "Project",
14+
"dotnetRunMessages": true,
15+
"launchBrowser": true,
16+
"launchUrl": "swagger",
17+
"applicationUrl": "http://localhost:5126",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
},
22+
"https": {
23+
"commandName": "Project",
24+
"dotnetRunMessages": true,
25+
"launchBrowser": true,
26+
"launchUrl": "swagger",
27+
"applicationUrl": "https://localhost:7177;http://localhost:5126",
28+
"environmentVariables": {
29+
"ASPNETCORE_ENVIRONMENT": "Development"
30+
}
31+
},
32+
"IIS Express": {
33+
"commandName": "IISExpress",
34+
"launchBrowser": true,
35+
"launchUrl": "swagger",
36+
"environmentVariables": {
37+
"ASPNETCORE_ENVIRONMENT": "Development"
38+
}
39+
}
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6ad114d2e1b2d1b3071433a7b77157f676b7c0e16bbf9e5153e74d32edbe5d04
2+
oid sha256:68b5efb07801637aa994d4eb78756cbbac24184fd97939316586dd408bd357f6
33
size 66048
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c05d4d36550505b2d88440004ea4ac21bccb0dfc818834bfd02204a6b4c4ec69
2+
oid sha256:da94adfbddbab0c27fffb5fa03e448b2808d70c0e3bfd8858df067159a80129d
33
size 149504
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:94f8b8361916b77362feaca8b41322131523931081dedff00664199c07ee5f9e
2+
oid sha256:00023c592e0d5cd080d32efe2f8fda96151366ed9ec091f94b06f04a81b68212
33
size 62464
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:85a6b3e6ff31e37cac992f528833a33b1372d76b33ea98ebba111f4f7f6e4b20
2+
oid sha256:da94adfbddbab0c27fffb5fa03e448b2808d70c0e3bfd8858df067159a80129d
33
size 149504

src/MIC/Assets/.MeshCloudScripting/Presentation1/bin/Release/net6.0/mesh.cloudscripting.manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"wasLastProvisionAppSuccessful": "True",
2121
"wasLastDeployAppSuccessful": null,
2222
"wasLastUploadBlobSuccessful": "False",
23-
"meshAppBuildId": "eb579890-4910-4dee-97de-e6b088d826ae",
23+
"meshAppBuildId": "c75ad0b4-ddd9-40f3-988b-2a6ef4a6dfab",
2424
"debugTimeoutSecs": 120,
2525
"provisionState": "Inactive"
2626
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:5dad8d2eb4f4620e689632bbbd97c6920c2bb9c7cd8cdbcab998463e84b19caf
3-
size 87421810
2+
oid sha256:e4f78a73e7f897e6cbf268d28d188c4a2cbdcf941cbe209ff1163f30c4545c9c
3+
size 87421860
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6ad114d2e1b2d1b3071433a7b77157f676b7c0e16bbf9e5153e74d32edbe5d04
3-
size 66048
2+
oid sha256:00023c592e0d5cd080d32efe2f8fda96151366ed9ec091f94b06f04a81b68212
3+
size 62464
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c05d4d36550505b2d88440004ea4ac21bccb0dfc818834bfd02204a6b4c4ec69
2+
oid sha256:da94adfbddbab0c27fffb5fa03e448b2808d70c0e3bfd8858df067159a80129d
33
size 149504

src/MIC/Assets/.MeshCloudScripting/Presentation1/bin/publish/Presentation1.runtimeconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
],
1414
"configProperties": {
1515
"System.GC.Server": true,
16+
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
1617
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
1718
}
1819
}

src/MIC/Assets/.MeshCloudScripting/Presentation1/bin/publish/mesh.cloudscripting.manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"wasLastProvisionAppSuccessful": "True",
2121
"wasLastDeployAppSuccessful": null,
2222
"wasLastUploadBlobSuccessful": "False",
23-
"meshAppBuildId": "eb579890-4910-4dee-97de-e6b088d826ae",
23+
"meshAppBuildId": "c75ad0b4-ddd9-40f3-988b-2a6ef4a6dfab",
2424
"debugTimeoutSecs": 120,
2525
"provisionState": "Inactive"
2626
}

src/MIC/Assets/.MeshCloudScripting/Presentation1/obj/Debug/net6.0/Presentation1.AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
[assembly: System.Reflection.AssemblyCompanyAttribute("Presentation1")]
1414
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
1515
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
16-
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+35888276861f591c6e3436c322aabcddf9f750a8")]
16+
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+02313272697d3912cddd6f43857251ad48dc6ad7")]
1717
[assembly: System.Reflection.AssemblyProductAttribute("Presentation1")]
1818
[assembly: System.Reflection.AssemblyTitleAttribute("Presentation1")]
1919
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c4a67d9ca6f4ffa4e7520d8642e63549f63f1f3790ba6abc1848977726ef5b14
1+
057059a03119578becd41f09ddf884d786d7bb71d4446b14e449704d560434b6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:6ad114d2e1b2d1b3071433a7b77157f676b7c0e16bbf9e5153e74d32edbe5d04
2+
oid sha256:68b5efb07801637aa994d4eb78756cbbac24184fd97939316586dd408bd357f6
33
size 66048
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"documents":{"C:\\Users\\Thoma\\Desktop\\Mesh-Innovate-Connect\\*":"https://raw.githubusercontent.com/micbelgique/Mesh-Innovate-Connect/35888276861f591c6e3436c322aabcddf9f750a8/*"}}
1+
{"documents":{"C:\\Users\\Thoma\\Desktop\\Mesh-Innovate-Connect\\*":"https://raw.githubusercontent.com/micbelgique/Mesh-Innovate-Connect/02313272697d3912cddd6f43857251ad48dc6ad7/*"}}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c05d4d36550505b2d88440004ea4ac21bccb0dfc818834bfd02204a6b4c4ec69
2+
oid sha256:da94adfbddbab0c27fffb5fa03e448b2808d70c0e3bfd8858df067159a80129d
33
size 149504

0 commit comments

Comments
 (0)