There is a mistake in the code example provided in the README file. The code snippet uses await portkey.chat but it should be await gateway.chat as defined in the const declaration. There is no variable named portkey in the provided code.
Code Snippet with Issue:
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'
const gateway = new OpenAI({
apiKey: "ANTHROPIC_API_KEY",
baseURL: PORTKEY_GATEWAY_URL, // Or http://localhost:8787/v1 when running locally
defaultHeaders: createHeaders({
provider: "anthropic",
apiKey: "PORTKEY_API_KEY" // Grab from https://app.portkey.ai / Not needed when running locally
})
});
async function main(){
const chatCompletion = await portkey.chat.completions.create({
messages: [{ role: 'user', content: 'Who are you?' }],
model: 'claude-3-sonnet-20240229',
maxTokens:512
});
console.log(chatCompletion.choices[0].message.content);
}
main()
Suggested Fix:
The variable portkey should be replaced with gateway in the await statement.
Corrected Code Snippet:
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'
const gateway = new OpenAI({
apiKey: "ANTHROPIC_API_KEY",
baseURL: PORTKEY_GATEWAY_URL, // Or http://localhost:8787/v1 when running locally
defaultHeaders: createHeaders({
provider: "anthropic",
apiKey: "PORTKEY_API_KEY" // Grab from https://app.portkey.ai / Not needed when running locally
})
});
async function main(){
const chatCompletion = await gateway.chat.completions.create({
messages: [{ role: 'user', content: 'Who are you?' }],
model: 'claude-3-sonnet-20240229',
maxTokens:512
});
console.log(chatCompletion.choices[0].message.content);
}
main()
Steps to Reproduce:
Copy the code snippet from the README.
Attempt to run the code.
Observe the error due to the undefined variable portkey.
Expected Behavior:
The code should run without errors and produce the expected output.
Actual Behavior:
The code throws an error because portkey is not defined.
What Should Have Happened?
The code should run without errors and produce the expected output.
Relevant Code Snippet
import OpenAI from 'openai';
import { PORTKEY_GATEWAY_URL, createHeaders } from 'portkey-ai'
const gateway = new OpenAI({
apiKey: "ANTHROPIC_API_KEY",
baseURL: PORTKEY_GATEWAY_URL, // Or http://localhost:8787/v1 when running locally
defaultHeaders: createHeaders({
provider: "anthropic",
apiKey: "PORTKEY_API_KEY" // Grab from https://app.portkey.ai / Not needed when running locally
})
});
async function main(){
const chatCompletion = await portkey.chat.completions.create({
messages: [{ role: 'user', content: 'Who are you?' }],
model: 'claude-3-sonnet-20240229',
maxTokens:512
});
console.log(chatCompletion.choices[0].message.content);
}
main()
What Happened?
There is a mistake in the code example provided in the README file. The code snippet uses
await portkey.chat
but it should beawait gateway.chat
as defined in theconst
declaration. There is no variable namedportkey
in the provided code.Code Snippet with Issue:
Suggested Fix:
The variable
portkey
should be replaced withgateway
in theawait
statement.Corrected Code Snippet:
Steps to Reproduce:
portkey
.Expected Behavior:
The code should run without errors and produce the expected output.
Actual Behavior:
The code throws an error because
portkey
is not defined.What Should Have Happened?
The code should run without errors and produce the expected output.
Relevant Code Snippet
Your Twitter/LinkedIn
https://x.com/Arindam_1729 and https://www.linkedin.com/in/arindam2004/