Skip to content

Commit aef015e

Browse files
authored
secrets for third party api keys (#110)
* secrets for third party api keys
1 parent 7b45ad5 commit aef015e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

examples/mixture-of-agents/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"GPT-4o Mini",
166166
"Llama 3.1 8B",
167167
"Mixtral 8x7B",
168-
]
168+
];
169169
const individualResults = "{{ individual }}";
170170
const aggResults = "{{ summaries }}";
171171

@@ -190,7 +190,7 @@
190190
contentArea.textContent =
191191
individualResults[currentLayer][currentIndex].trim();
192192

193-
cardTitle.textContent = `${modelNames[currentIndex]} - Layer ${ currentLayer + 1 }`;
193+
cardTitle.textContent = `${modelNames[currentIndex]} - Layer ${currentLayer + 1}`;
194194
} else {
195195
contentArea.textContent = aggResults[currentLayer].trim();
196196
cardTitle.textContent = `MoA Layer ${currentLayer + 1}`;

src/Substrate.ts

+20
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ type Configuration = {
2727
*/
2828
timeout?: number;
2929

30+
/**
31+
* Secrets for third party services.
32+
*/
33+
secrets?: Secrets;
34+
3035
/**
3136
* Add additional headers to each request. These may override headers set by the Substrate client.
3237
*/
3338
additionalHeaders?: Record<string, string>;
3439
};
3540

41+
export type Secrets = {
42+
openai?: string;
43+
anthropic?: string;
44+
};
45+
3646
/**
3747
* [docs/introduction](https://docs.substrate.run)
3848
*/
@@ -51,6 +61,7 @@ export class Substrate {
5161
baseUrl,
5262
apiVersion,
5363
timeout,
64+
secrets,
5465
additionalHeaders,
5566
}: Configuration) {
5667
if (!apiKey) {
@@ -63,6 +74,15 @@ export class Substrate {
6374
this.apiVersion = apiVersion ?? OpenAPIjson["info"]["version"];
6475
this.timeout = timeout ?? 300_000;
6576
this.additionalHeaders = additionalHeaders ?? {};
77+
if (secrets) {
78+
if (secrets.openai) {
79+
this.additionalHeaders["x-substrate-openai-api-key"] = secrets.openai;
80+
}
81+
if (secrets.anthropic) {
82+
this.additionalHeaders["x-substrate-anthropic-api-key"] =
83+
secrets.anthropic;
84+
}
85+
}
6686
}
6787

6888
/**

0 commit comments

Comments
 (0)