Skip to content

Commit 3462f4b

Browse files
Merge pull request #129 from prompt-foundry/anthonyjgrove-patch-1
Add Anthropic example to README.md
2 parents 4f42cd8 + ec9e451 commit 3462f4b

File tree

1 file changed

+76
-8
lines changed

1 file changed

+76
-8
lines changed

README.md

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,93 @@ npm install @prompt-foundry/typescript-sdk
2020

2121
The full API of this library can be found in [api.md](api.md).
2222

23-
<!-- prettier-ignore -->
23+
### OpenAI Integration
24+
25+
Install the OpenAI SDK
26+
27+
```sh
28+
npm install openai
29+
```
30+
31+
Import the OpenAI and Prompt Foundry SDKs
32+
2433
```js
25-
import PromptFoundry from '@prompt-foundry/typescript-sdk';
34+
import PromptFoundry from "@prompt-foundry/typescript-sdk";
35+
import { Configuration, OpenAIApi } from "openai";
2636

37+
// Initialize Prompt Foundry SDK with your API key
2738
const promptFoundry = new PromptFoundry({
28-
apiKey: process.env['PROMPT_FOUNDRY_API_KEY'], // This is the default and can be omitted
39+
apiKey: process.env["PROMPT_FOUNDRY_API_KEY"],
2940
});
3041

42+
// Initialize OpenAI SDK with your API key
43+
const configuration = new Configuration({
44+
apiKey: process.env["OPENAI_API_KEY"],
45+
});
46+
const openai = new OpenAIApi(configuration);
47+
3148
async function main() {
32-
const modelParameters = await promptFoundry.prompts.getParameters('1212121', {
33-
variables: { hello: 'world' },
49+
// Retrieve model parameters for the prompt
50+
const modelParameters = await promptFoundry.prompts.getParameters("1212121", {
51+
variables: { hello: "world" },
3452
});
3553

36-
const modelResponse = await openai.chat.completions.create(modelParameters.parameters)
54+
// check if provider is Open AI
55+
if (modelParameters.provider === "openai") {
56+
// Use the retrieved parameters to create a chat completion request
57+
const modelResponse = await openai.chat.completions.create(
58+
modelParameters.parameters
59+
);
3760

38-
console.log(modelResponse);
61+
// Print the response from OpenAI
62+
console.log(modelResponse.data);
63+
}
3964
}
4065

41-
main();
66+
main().catch(console.error);
67+
```
68+
69+
### Anthropic Integration
70+
71+
Install the Anthropic SDK
72+
73+
```sh
74+
npm install @anthropic-ai/sdk
75+
```
76+
77+
Import the Anthropic and Prompt Foundry SDKs
78+
79+
```js
80+
import PromptFoundry from "@prompt-foundry/typescript-sdk";
81+
import Anthropic from "@anthropic-ai/sdk";
82+
83+
// Initialize Prompt Foundry SDK with your API key
84+
const promptFoundry = new PromptFoundry({
85+
apiKey: process.env["PROMPT_FOUNDRY_API_KEY"],
86+
});
87+
88+
// Initialize Anthropic SDK with your API key
89+
const anthropic = new Anthropic({
90+
apiKey: process.env["ANTHROPIC_API_KEY"],
91+
});
92+
93+
async function main() {
94+
// Retrieve model parameters for the prompt
95+
const modelParameters = await promptFoundry.prompts.getParameters("1212121", {
96+
variables: { hello: "world" },
97+
});
98+
99+
// check if provider is Open AI
100+
if (modelParameters.provider === "anthropic") {
101+
// Use the retrieved parameters to create a chat completion request
102+
const message = await anthropic.messages.create(modelParameters.parameters);
103+
104+
// Print the response from Anthropic
105+
console.log(message.content);
106+
}
107+
}
108+
109+
main().catch(console.error);
42110
```
43111

44112
### Request & Response types

0 commit comments

Comments
 (0)