forked from phoenix/litellm-mirror
adding proxy api keys to docs
This commit is contained in:
parent
56a912ac88
commit
281491f6cf
3 changed files with 85 additions and 38 deletions
63
docs/my-website/src/components/QuickStart.js
Normal file
63
docs/my-website/src/components/QuickStart.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
import React, { useState, useEffect } from 'react';
|
||||
|
||||
const QuickStartCodeBlock = ({ token }) => {
|
||||
return (
|
||||
<pre>
|
||||
{`
|
||||
from litellm import completion
|
||||
import os
|
||||
|
||||
## set ENV variables
|
||||
os.environ["OPENAI_API_KEY"] = "${token}"
|
||||
os.environ["COHERE_API_KEY"] = "${token}"
|
||||
|
||||
messages = [{ "content": "Hello, how are you?","role": "user"}]
|
||||
|
||||
# openai call
|
||||
response = completion(model="gpt-3.5-turbo", messages=messages)
|
||||
|
||||
# cohere call
|
||||
response = completion("command-nightly", messages)
|
||||
`}
|
||||
</pre>
|
||||
);
|
||||
};
|
||||
|
||||
const QuickStart = () => {
|
||||
const [token, setToken] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const generateToken = async () => {
|
||||
try {
|
||||
const response = await fetch('https://proxy.litellm.ai/key/new', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer sk-liteplayground',
|
||||
},
|
||||
body: JSON.stringify({'total_budget': 100})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
setToken(`${data.api_key}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch new token: ', error);
|
||||
}
|
||||
};
|
||||
|
||||
generateToken();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<QuickStartCodeBlock token={token} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default QuickStart;
|
Loading…
Add table
Add a link
Reference in a new issue