mirror of
https://github.com/jbranchaud/til
synced 2026-01-21 16:08:03 +00:00
Compare commits
2 Commits
b766f20012
...
f3d7cf8a06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3d7cf8a06 | ||
|
|
72089e11db |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1412 TILs and counting..._
|
_1414 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -41,6 +41,7 @@ _1412 TILs and counting..._
|
|||||||
* [jq](#jq)
|
* [jq](#jq)
|
||||||
* [Kitty](#kitty)
|
* [Kitty](#kitty)
|
||||||
* [Linux](#linux)
|
* [Linux](#linux)
|
||||||
|
* [LLM](#llm)
|
||||||
* [Mac](#mac)
|
* [Mac](#mac)
|
||||||
* [MongoDB](#mongodb)
|
* [MongoDB](#mongodb)
|
||||||
* [MySQL](#mysql)
|
* [MySQL](#mysql)
|
||||||
@@ -554,6 +555,10 @@ _1412 TILs and counting..._
|
|||||||
- [Show Used And Available System Memory](linux/show-used-and-available-system-memory.md)
|
- [Show Used And Available System Memory](linux/show-used-and-available-system-memory.md)
|
||||||
- [Upgrading Ubuntu](linux/upgrading-ubuntu.md)
|
- [Upgrading Ubuntu](linux/upgrading-ubuntu.md)
|
||||||
|
|
||||||
|
### LLM
|
||||||
|
|
||||||
|
- [Send cURL To Claude Text Completion API](llm/send-curl-to-claude-text-completion-api.md)
|
||||||
|
|
||||||
### Mac
|
### Mac
|
||||||
|
|
||||||
- [Access All Screen And Video Capture Options](mac/access-all-screen-and-video-capture-options.md)
|
- [Access All Screen And Video Capture Options](mac/access-all-screen-and-video-capture-options.md)
|
||||||
@@ -1633,6 +1638,7 @@ _1412 TILs and counting..._
|
|||||||
### Workflow
|
### Workflow
|
||||||
|
|
||||||
- [Add Subtitles To Existing Mux Video Asset](workflow/add-subtitles-to-existing-mux-video-asset.md)
|
- [Add Subtitles To Existing Mux Video Asset](workflow/add-subtitles-to-existing-mux-video-asset.md)
|
||||||
|
- [Access 1Password Credential From CLI](workflow/access-1password-credential-from-cli.md)
|
||||||
- [Change Window Name In iTerm](workflow/change-window-name-in-iterm.md)
|
- [Change Window Name In iTerm](workflow/change-window-name-in-iterm.md)
|
||||||
- [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md)
|
- [Convert An ePub Document To PDF On Mac](workflow/convert-an-epub-document-to-pdf-on-mac.md)
|
||||||
- [Create A Local Sanity Dataset Backup](workflow/create-a-local-sanity-dataset-backup.md)
|
- [Create A Local Sanity Dataset Backup](workflow/create-a-local-sanity-dataset-backup.md)
|
||||||
|
|||||||
40
llm/send-curl-to-claude-text-completion-api.md
Normal file
40
llm/send-curl-to-claude-text-completion-api.md
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Send cURL To Claude Text Completion API
|
||||||
|
|
||||||
|
Here is how we can make a `cURL` (`POST`) request to the Claude text completion
|
||||||
|
API. It requires already having a Claude API account with (paid) credits. At
|
||||||
|
this time, you can get $5 in free credits to try it out.
|
||||||
|
|
||||||
|
Assuming all that, we can grab an API key, store it somewhere safe and
|
||||||
|
accessible like 1Password, and then start formatting a request.
|
||||||
|
|
||||||
|
We need to specify a couple headers as well as `POST` body parameters.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "x-api-key: $(op item get "Anthropic Claude API Key" --field credential)" \
|
||||||
|
-H "anthropic-version: 2023-06-01" \
|
||||||
|
-d \
|
||||||
|
'{
|
||||||
|
"model": "claude-2.1",
|
||||||
|
"max_tokens_to_sample": 1024,
|
||||||
|
"prompt": "Human: Show me an example of a simple Ruby program.\n\nAssistant:"
|
||||||
|
}' \
|
||||||
|
https://api.anthropic.com/v1/complete
|
||||||
|
```
|
||||||
|
|
||||||
|
The required headers are:
|
||||||
|
- `"Content-Type: application/json"`
|
||||||
|
- `x-api-key` with our API key
|
||||||
|
- `"anthropic-version: 2023-06-01"` (the latest Anthropic API version)
|
||||||
|
|
||||||
|
Then, in the body, we specify:
|
||||||
|
- the `model` (e.g. `claude-2.1`)
|
||||||
|
- the max number of tokens you want the model to use
|
||||||
|
- a prompt that starts with `Human:` and then prompts the `Assistant:`
|
||||||
|
|
||||||
|
Note: this is a legacy API and the [Messages
|
||||||
|
API](https://docs.anthropic.com/claude/reference/messages_post) should be
|
||||||
|
preferred.
|
||||||
|
|
||||||
|
[source](https://docs.anthropic.com/claude/reference/complete_post)
|
||||||
29
workflow/access-1password-credential-from-cli.md
Normal file
29
workflow/access-1password-credential-from-cli.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# Access 1Password Credential From CLI
|
||||||
|
|
||||||
|
With the `op` CLI, I can store things like API keys and secrets in my 1Password
|
||||||
|
vault and then access them from the command line. This assumes I've already
|
||||||
|
installed the CLI (`brew install 1password-cli`) and connected it to the
|
||||||
|
1Password app via the _Developer_ settings.
|
||||||
|
|
||||||
|
The `op item get` command takes a credential name and returns all the details
|
||||||
|
for the entry with that _Title_. Here is how I can access my _Anthropic Claude
|
||||||
|
API Key_ details.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ op item get "Anthropic Claude API Key"
|
||||||
|
```
|
||||||
|
|
||||||
|
With the `--field` flag, I can grab a specific field, such as the `credential`,
|
||||||
|
from that entry.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ op item get "Anthropic Claude API Key" --field credential
|
||||||
|
sk-ant-api03-abc......xyz
|
||||||
|
```
|
||||||
|
|
||||||
|
A command like this can be embedded in other commands as a way of referencing
|
||||||
|
secrets without explicitly entering them into your shell history.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ curl https://api -H "x-api-key: $(op item get "Anthropic Claude API Key" --field credential)" ...
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user