Skip to content

Commit

Permalink
updated adapters examples
Browse files Browse the repository at this point in the history
  • Loading branch information
csansoon committed Nov 14, 2024
1 parent f662f65 commit 65aa16e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions docs/promptl/usage/adapters/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ description: Learn how to use PromptL with Anthropic

You can specify the `Anthropic` adapter when rendering a prompt to automatically format the output for Anthropic's API.

<Note>
Anthropic does not support system messages in the messages array. PromptL will
automatically move the first system message to the `config` object, as
Anthropic recommends, but that means that:
- You can only have system messages at the beggining of your prompt.
- You must define non-system messages (the messages array cannot be empty).
</Note>

## Example

```typescript
Expand All @@ -19,7 +27,9 @@ model: claude-3-opus-20240229
max_tokens: 1024
---
Generate a joke about {{ topic }}.
<user>
Generate a joke about {{ topic }}.
</user>
`

const { messages, config } = await render({
Expand All @@ -28,11 +38,11 @@ const { messages, config } = await render({
adapter: Adapters.anthropic,
})

const client = new Anthropic()
const client = new Anthropic({ apiKey: YOUR_ANTHROPIC_API_KEY })
const response = await client.messages.create({
...config,
messages,
})

console.log(response)
console.log(response.content[0].text)
```
4 changes: 3 additions & 1 deletion docs/promptl/usage/adapters/openai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const { messages, config } = await render({
parameters: { topic: 'chickens' },
})

const client = new OpenAI()
const client = new OpenAI({ apiKey: YOUR_OPENAI_API_KEY })
const response = await client.chat.completions.create({
...config,
messages,
})

console.log(response.choices[0].message.content)
```

0 comments on commit 65aa16e

Please sign in to comment.