@@ -20,25 +20,93 @@ npm install @prompt-foundry/typescript-sdk
20
20
21
21
The full API of this library can be found in [ api.md] ( api.md ) .
22
22
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
+
24
33
``` js
25
- import PromptFoundry from ' @prompt-foundry/typescript-sdk' ;
34
+ import PromptFoundry from " @prompt-foundry/typescript-sdk" ;
35
+ import { Configuration , OpenAIApi } from " openai" ;
26
36
37
+ // Initialize Prompt Foundry SDK with your API key
27
38
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" ],
29
40
});
30
41
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
+
31
48
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" },
34
52
});
35
53
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
+ );
37
60
38
- console .log (modelResponse);
61
+ // Print the response from OpenAI
62
+ console .log (modelResponse .data );
63
+ }
39
64
}
40
65
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 );
42
110
```
43
111
44
112
### Request & Response types
0 commit comments