File size: 1,331 Bytes
4ec8dba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import React, { useState, useEffect } from 'react';
const CodeBlock = ({ token }) => {
const codeWithToken = `
import os
from litellm import completion
# set ENV variables
os.environ["LITELLM_TOKEN"] = '${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)
`;
const codeWithoutToken = `
from litellm import completion
## set ENV variables
os.environ["OPENAI_API_KEY"] = "openai key"
os.environ["COHERE_API_KEY"] = "cohere key"
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)
`;
return (
<pre>
{console.log("token: ", token)}
{token ? codeWithToken : codeWithoutToken}
</pre>
)
}
const QueryParamReader = () => {
const [token, setToken] = useState(null);
useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
console.log("urlParams: ", urlParams)
const token = urlParams.get('token');
setToken(token);
}, []);
return (
<div>
<CodeBlock token={token} />
</div>
);
}
export default QueryParamReader; |