GPAL - Generally Positive Automation Library
v1.0
GPAL The Fluent Automation LIbrary
Toggle main menu visibility
Loading...
Searching...
No Matches
AIProvidersConfig.cs
1
// =============================================================================
2
// GPAL - Generally Positive Automation Library
3
// Copyright © 2026 Software Decisions, Inc. All rights reserved.
4
//
5
// This file is part of GPAL.
6
// Licensed under the Business Source License 1.1
7
//
8
// Primary development, architecture, and vision by Michael B. Vederman,
9
// CEO of Software Decisions, Inc., Texas.
10
//
11
// Internal development maintained privately.
12
// Public releases appear on GitHub: https://github.com/SoftwareDecisionsInc/GPAL.
13
//
14
// See LICENSE for full terms, including Additional Use Grant.
15
// =============================================================================
16
17
using
System;
18
using
System.Collections.Generic;
19
using
System.IO;
20
using
System.Linq;
21
using
static
GenerallyPositive
.
Enums
;
22
23
namespace
GenerallyPositive
24
{
29
public
class
AIProviderDefinition
30
{
31
public
string
Name {
get
;
set
; }
32
public
string
BaseUrl {
get
;
set
; }
33
public
string
ChatEndpoint {
get
;
set
; }
34
public
string
DefaultModel {
get
;
set
; }
35
public
string
AuthHeader {
get
;
set
; }
36
public
string
AuthPrefix {
get
;
set
; }
37
public
string
ResponseFormat {
get
;
set
; }
38
public
Dictionary<string, string> AdditionalHeaders {
get
;
set
; } =
new
Dictionary<string, string>();
39
}
40
47
public
class
AIProvidersConfig
48
{
49
private
static
string
ConfigFilePath =
"./AIProvidersConfig.yaml"
;
50
51
public
static
AIProvidersConfig
Current {
get
;
private
set
; } = Default();
52
53
public
List<AIProviderDefinition> Providers {
get
;
set
; } =
new
List<AIProviderDefinition>();
54
55
public
AIProviderDefinition
Find(AIProviderType type) =>
56
Providers.FirstOrDefault(p =>
string
.Equals(p.Name, type.Name, StringComparison.OrdinalIgnoreCase));
57
63
public
static
AIProvidersConfig
Load
(
GPALFile
file =
null
)
64
{
65
if
(file !=
null
) ConfigFilePath = file.Filename;
66
if
(!File.Exists(ConfigFilePath))
67
{
68
Default().Save();
69
GPAL
.
PublishSimpleEvent
(GPALEventType.WARNING, $
"[{ConfigFilePath}] not found. Default written for editing."
,
null
, GPALObjectType.None);
70
return
Default();
71
}
72
try
73
{
74
var loaded =
new
AIProvidersConfig
();
75
GPAL.Converter
76
.WithInput((
GPALFile
)
GPAL
.
File
.WithFileName(ConfigFilePath))
77
.SaveTo(ref loaded);
78
if
(loaded?.Providers !=
null
&& loaded.Providers.Count > 0)
79
{
80
Current = loaded;
81
GPAL
.
PublishSimpleEvent
(GPALEventType.INFO, $
"[{ConfigFilePath}] loaded ([{loaded.Providers.Count}] AI provider(s))."
,
null
, GPALObjectType.None);
82
return
loaded;
83
}
84
}
85
catch
(Exception ex)
86
{
87
GPAL
.
PublishSimpleEvent
(GPALEventType.WARNING, $
"Failed to load AIProvidersConfig"
,
null
, GPALObjectType.None, ex);
88
}
89
return
Default();
90
}
91
95
public
void
Save
(
GPALFile
file =
null
)
96
{
97
if
(file !=
null
) ConfigFilePath = file.Filename;
98
GPAL.Converter
99
.WithInput(
this
)
100
.SaveTo((
GPALFile
)
GPAL
.
File
.WithFileName(ConfigFilePath));
101
}
102
107
internal
static
void
TryAutoLoad()
108
{
109
if
(!File.Exists(ConfigFilePath))
return
;
110
Current =
Load
();
111
}
112
113
private
static
AIProvidersConfig Default() =>
new
AIProvidersConfig
114
{
115
Providers =
new
List<AIProviderDefinition>
116
{
117
new
AIProviderDefinition
118
{
119
Name =
"XAI"
,
120
BaseUrl =
"https://api.x.ai/v1"
,
121
ChatEndpoint =
"/chat/completions"
,
122
DefaultModel =
"grok-2-latest"
,
123
AuthHeader =
"Authorization"
,
124
AuthPrefix =
"Bearer "
,
125
ResponseFormat =
"openai"
,
126
AdditionalHeaders =
new
Dictionary<string, string>()
127
},
128
new
AIProviderDefinition
129
{
130
Name =
"OpenAI"
,
131
BaseUrl =
"https://api.openai.com/v1"
,
132
ChatEndpoint =
"/chat/completions"
,
133
DefaultModel =
"gpt-4o-mini"
,
134
AuthHeader =
"Authorization"
,
135
AuthPrefix =
"Bearer "
,
136
ResponseFormat =
"openai"
,
137
AdditionalHeaders =
new
Dictionary<string, string>()
138
},
139
new
AIProviderDefinition
140
{
141
Name =
"Anthropic"
,
142
BaseUrl =
"https://api.anthropic.com/v1"
,
143
ChatEndpoint =
"/messages"
,
144
DefaultModel =
"claude-sonnet-4-6"
,
145
AuthHeader =
"x-api-key"
,
146
AuthPrefix =
""
,
147
ResponseFormat =
"anthropic"
,
148
AdditionalHeaders =
new
Dictionary<string, string> { {
"anthropic-version"
,
"2023-06-01"
} }
149
}
150
}
151
};
152
}
153
}
GenerallyPositive.AIProviderDefinition
Per-provider connection definition: base URL, endpoint, default model, auth style,...
Definition
AIProvidersConfig.cs:30
GenerallyPositive.AIProvidersConfig
Loads and saves the AI provider definitions used by GPAL.AI.WithProvider. Stored as ....
Definition
AIProvidersConfig.cs:48
GenerallyPositive.AIProvidersConfig.Load
static AIProvidersConfig Load(GPALFile file=null)
Loads AI provider definitions from AIProvidersConfig.yaml (or a custom path). If the file is missing,...
Definition
AIProvidersConfig.cs:63
GenerallyPositive.AIProvidersConfig.Save
void Save(GPALFile file=null)
Saves this configuration to AIProvidersConfig.yaml (or a custom path).
Definition
AIProvidersConfig.cs:95
GenerallyPositive.Enums
Definition
Enums.cs:37
GenerallyPositive.GPALFile
GPAL File object instantied with GPAL.File Used to load tokens into a GPALGrid [rows/columns].
Definition
GPALFile.cs:36
GenerallyPositive.GPAL
Everything starts here, all the GPAL controls and global settings using fluent syntax are here....
Definition
GPAL.cs:49
GenerallyPositive.GPAL.Converter
static IAllowConverterInput Converter
New GPAL Convertor.
Definition
GPAL.cs:560
GenerallyPositive.GPAL.PublishSimpleEvent
static void PublishSimpleEvent(GPALEventType gPALEventType, string msg, dynamic gPALObject=null, Enums.GPALObjectType gPALObjectType=GPALObjectType.None, Exception ex=null)
Publish a message to either the information channel or exception channel (if exception passed in) Pub...
Definition
GPAL.cs:2406
GenerallyPositive.GPAL.File
static IAllowFileName File
Instantiates a new fluent File SETTINGS object. This data object defines settings for use by the ....
Definition
GPAL.cs:508
GenerallyPositive
Definition
Application.cs:32
Common
AIProvidersConfig.cs
Generated by
1.17.0