-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (47 loc) · 1.56 KB
/
Program.cs
File metadata and controls
59 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Betalgo.Ranul.OpenAI;
using Betalgo.Ranul.OpenAI.ObjectModels;
using Betalgo.Ranul.OpenAI.Extensions;
using Betalgo.Ranul.OpenAI.Interfaces;
using Betalgo.Ranul.OpenAI.ObjectModels.RequestModels;
var builder = WebApplication.CreateBuilder(args);
// Add OpenAI services
builder.Services.AddOpenAIService(settings =>
{
settings.ApiKey = builder.Configuration["OpenAI:ApiKey"];
settings.Organization = builder.Configuration["OpenAI:OrganizationId"]; // Organization is optional
});
// Existing service configurations...
// Add this with your other service configurations
builder.Services.AddRazorPages();
var app = builder.Build();
app.UseStaticFiles(); // This needs to be before UseRouting
app.UseRouting();
// And add this before app.Run()
app.MapRazorPages();
// Add test endpoint
app.MapGet("/test-openai", async (IOpenAIService openAIService) =>
{
try
{
var response = await openAIService.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
{
Messages = new List<ChatMessage>
{
ChatMessage.FromSystem("You are a helpful assistant."),
ChatMessage.FromUser("Say hello!")
},
Model = Models.Gpt_3_5_Turbo,
MaxTokens = 50
});
if (response.Successful)
{
return Results.Ok(response.Choices[0].Message.Content);
}
return Results.BadRequest($"Error: {response.Error?.Message}");
}
catch (Exception ex)
{
return Results.BadRequest($"Exception: {ex.Message}");
}
});
app.Run();