anthropic

package
v0.27.2-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2024 License: MIT Imports: 9 Imported by: 0

README

---
title: "Anthropic"
lang: "en-US"
draft: false
description: "Learn about how to set up a VDP Anthropic component https://github.com/instill-ai/instill-core"
---

The Anthropic component is an AI component that allows users to connect the AI models served on the Anthropic Platform.
It can carry out the following tasks:

- [Text Generation Chat](#text-generation-chat)



## Release Stage

`Alpha`



## Configuration

The component configuration is defined and maintained [here](https://github.com/instill-ai/component/blob/main/ai/anthropic/v0/config/definition.json).




## Setup




In order to communicate with Anthropic, the following connection details need to be
provided. You may specify them directly in a pipeline recipe as key-value pairs
withing the component's `setup` block, or you can create a **Connection** from
the [**Integration Settings**](https://www.instill.tech/docs/vdp/integration)
page and reference the whole `setup` as `setup:
${connection.<my-connection-id>}`.

| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| API Key | `api-key` | string | Fill in your Anthropic API key. To find your keys, visit the Anthropic console page. |




## Supported Tasks

### Text Generation Chat

Provide text outputs in response to text inputs.


| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_TEXT_GENERATION_CHAT` |
| Model Name (required) | `model-name` | string | The Anthropic model to be used |
| Prompt (required) | `prompt` | string | The prompt text |
| System message | `system-message` | string | The system message helps set the behavior of the assistant. For example, you can modify the personality of the assistant or provide specific instructions about how it should behave throughout the conversation. By default, the model’s behavior is set using a generic message as "You are a helpful assistant." |
| Prompt Images | `prompt-images` | array[string] | The prompt images (Note: The prompt images will be injected in the order they are provided to the 'prompt' message. Anthropic doesn't support sending images via image-url, use this field instead) |
| Chat history | `chat-history` | array[object] | Incorporate external chat history, specifically previous messages within the conversation. Please note that System Message will be ignored and will not have any effect when this field is populated. Each message should adhere to the format: : \{"role": "The message role, i.e. 'system', 'user' or 'assistant'", "content": "message content"\}. |
| Seed | `seed` | integer | The seed (Note: Not supported by Anthropic Models) |
| Temperature | `temperature` | number | The temperature for sampling |
| Top K | `top-k` | integer | Top k for sampling |
| Max new tokens | `max-new-tokens` | integer | The maximum number of tokens for model to generate |



| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Text | `text` | string | Model Output |
| Usage (optional) | `usage` | object | Usage tokens in Anthropic |






## Example Recipes

Recipe for the [List GitHub Repo Issues](https://instill.tech/instill-ai/pipelines/github-demo/playground) pipeline.

```yaml
version: v1beta
component:
    anthropic-0:
        type: anthropic
        task: TASK_TEXT_GENERATION_CHAT
        input:
            max-new-tokens: 1000
            model-name: claude-3-5-sonnet-20240620
            prompt: Summarise and pick the most important issues from this list ${github.output.issues}
            system-message: You are a helpful assistant.
            temperature: 0.7
            top-k: 10
        setup:
            api-key: ${secret.INSTILL_SECRET}
    github:
        type: github
        task: TASK_LIST_ISSUES
        input:
            direction: desc
            no-pull-request: false
            owner: ${variable.repository-owner}
            page: 1
            per-page: 30
            repository: ${variable.repository-name}
            since: "2021-01-01T00:00:00Z"
            sort: created
            state: open
        setup:
            token: ${secret.github-demo}
variable:
    repository-name:
        title: Repository Name
        description: Name of the repository i.e. instill-core
        instill-format: string
    repository-owner:
        title: Repository Owner
        description: Name of the repository owner i.e. instill-ai
        instill-format: string
output:
    result:
        title: Result
        value: ${anthropic-0.output.text}
```

Documentation

Index

Constants

View Source
const (
	TextGenerationTask = "TASK_TEXT_GENERATION_CHAT"
)

Variables

This section is empty.

Functions

func Init

func Init(bc base.Component) *component

Types

type AnthropicClient

type AnthropicClient interface {
	// contains filtered or unexported methods
}

type ChatMessage

type ChatMessage struct {
	Role    string              `json:"role"`
	Content []MultiModalContent `json:"content"`
}

type MessagesInput

type MessagesInput struct {
	ChatHistory  []ChatMessage `json:"chat-history"`
	MaxNewTokens int           `json:"max-new-tokens"`
	ModelName    string        `json:"model-name"`
	Prompt       string        `json:"prompt"`
	PromptImages []string      `json:"prompt-images"`
	Seed         int           `json:"seed"`
	SystemMsg    string        `json:"system-message"`
	Temperature  float32       `json:"temperature"`
	TopK         int           `json:"top-k"`
}

type MessagesOutput

type MessagesOutput struct {
	Text  string        `json:"text"`
	Usage messagesUsage `json:"usage"`
}

type MultiModalContent

type MultiModalContent struct {
	ImageURL URL    `json:"image-url"`
	Text     string `json:"text"`
	Type     string `json:"type"`
}

type URL

type URL struct {
	URL string `json:"url"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL