How to use CryptoTalks with the OpenAI client
First, create an account:
curl -k -X POST https://cryptotalks.ai/v1/create_user/ \
-H 'Content-Type: application/json' \
-d '{"username":"testuser3@example.com","password":"testpassword","confirm_password":"testpassword"}'
Response:
{"message": "User created successfully! Save this token, do not share it.",
"token": "5d68e5723b5613cbf243a15569a0d3de282f2dea"}
Then, generate a BTC deposit address:
curl -k -X POST https://cryptotalks.ai/v1/generate_deposit_address/ \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 5d68e5723b5613cbf243a15569a0d3de282f2dea'
Response:
{"addresses": {"BTC": "1BitcoinEaterAddressDontSendf59kuE", ...}}
After deposit, use the OpenAI client with your CryptoTalks URL and API key (Python):
client = OpenAI(
base_url="https://cryptotalks.ai/v1",
api_key="5d68e5723b5613cbf243a15569a0d3de282f2dea",
)
completion = client.chat.completions.create(
model="anthropic/claude-3-opus",
messages=[
{
"role": "system",
"content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair.",
},
{
"role": "user",
"content": "Compose a poem that explains the concept of recursion in programming.",
},
],
)
print(completion.choices[0].message.content)
Response:
ChatCompletionMessage(content="In the realm of code, a concept lies\nRecursion, a trick that's rather wise\nA function that calls itself with pride\nUntil a base case is satisfied\n\nLike Russian dolls that nest inside\nEach one contains a smaller size\nRecursion works in similar ways\nSolving problems in elegant phase\n\nImagine a tree with branches grand\nEach branch divides, like a fractal's hand\nRecursion traverses every part\nFrom leaf to root, it plays its art\n\nFibonacci's sequence, a classic case\nRecursion shines in this number chase\nEach term, the sum of two before\nIt builds the sequence, forever more\n\nBut be cautious, dear programmer's mind\nLest infinite loops leave you in a bind\nEnsure a base case, a stopping point\nOr else, recursion will disappoint\n\nSo when complex problems come to play\nAnd iteration just won't make the grade\nThink recursion, with its clever might\nA powerful tool, in the coder's sight\n\nRecursion, a concept that's deep and vast\nIn programming's world, it's unsurpassed\nA elegant way to break things down\nAnd solve the puzzles that come", role='assistant', function_call=None, tool_calls=None)