Skip to content

Commit

Permalink
Merge branch 'main' into namwoam/cohere
Browse files Browse the repository at this point in the history
  • Loading branch information
namwoam authored Jul 8, 2024
2 parents d3199e8 + e27e46c commit 1daa986
Show file tree
Hide file tree
Showing 29 changed files with 557 additions and 523 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## [0.21.0-beta](https://github.com/instill-ai/component/compare/v0.20.2-beta...v0.21.0-beta) (2024-07-02)


### Features

* add mail component ([#178](https://github.com/instill-ai/component/issues/178)) ([04b19d0](https://github.com/instill-ai/component/commit/04b19d0537e8870b1207de6910eb362c517a2eed))
* add read task for gcs ([#155](https://github.com/instill-ai/component/issues/155)) ([77fe2fc](https://github.com/instill-ai/component/commit/77fe2fc60f22bc5121d5835947954af3ba4f7400))
* add read task in bigquery component ([#156](https://github.com/instill-ai/component/issues/156)) ([4d2e7ec](https://github.com/instill-ai/component/commit/4d2e7ecc10904a93ffa32dd4600856dccbba68b7))
* **anthropic:** add Anthropic component ([#176](https://github.com/instill-ai/component/issues/176)) ([030881d](https://github.com/instill-ai/component/commit/030881dac345759cf00c1f33880b9c1398b8f3a9))
* **anthropic:** add UsageHandler functions in anthropic ([#186](https://github.com/instill-ai/component/issues/186)) ([ebaa61f](https://github.com/instill-ai/component/commit/ebaa61f66e1996540fa6b0c4f425408bec70b290))
* **compogen:** add extra section with --extraContents flag' ([#171](https://github.com/instill-ai/component/issues/171)) ([391bb98](https://github.com/instill-ai/component/commit/391bb9850aa6dca207c2c5157beb0f5d6fa011cb))
* **instill:** remove extra-params field ([#188](https://github.com/instill-ai/component/issues/188)) ([b17ff73](https://github.com/instill-ai/component/commit/b17ff73fe350d3785031ec154c37e2f83a352978))
* **redis:** simplify the TLS configuration ([#194](https://github.com/instill-ai/component/issues/194)) ([0a8baf7](https://github.com/instill-ai/component/commit/0a8baf73440e0fef5d2601701f0bcfccd8e5e363))


### Bug Fixes

* **all:** fix typos ([#174](https://github.com/instill-ai/component/issues/174)) ([cb3c2fb](https://github.com/instill-ai/component/commit/cb3c2fbbb7362885c3f763fc5f690e0526b19bc5))
* **compogen:** wrong bracket direction in substitution ([#184](https://github.com/instill-ai/component/issues/184)) ([dfe8306](https://github.com/instill-ai/component/commit/dfe83060f2b5024c72e28340246498d1a553497a))
* expose input and output for anthropic for instill credit ([#190](https://github.com/instill-ai/component/issues/190)) ([a36e876](https://github.com/instill-ai/component/commit/a36e876869b3c2812736b66f56fa4ebe0a9f4985))
* update doc ([#185](https://github.com/instill-ai/component/issues/185)) ([6e6639a](https://github.com/instill-ai/component/commit/6e6639aa59ab0bc8c78c24a596e1393be9cd7db5))

## [0.20.2-beta](https://github.com/instill-ai/component/compare/v0.20.1-beta...v0.20.2-beta) (2024-06-21)


Expand Down
9 changes: 5 additions & 4 deletions ai/anthropic/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

qt "github.com/frankban/quicktest"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"

"github.com/instill-ai/component/base"
Expand All @@ -31,7 +30,8 @@ func TestComponent_Execute(t *testing.T) {
c := qt.New(t)
ctx := context.Background()

bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}

connector := Init(bc)

testcases := []struct {
Expand Down Expand Up @@ -97,7 +97,8 @@ func TestComponent_Execute(t *testing.T) {
func TestComponent_Connection(t *testing.T) {
c := qt.New(t)

bc := base.Component{Logger: zap.NewNop()}

bc := base.Component{}
connector := Init(bc)

c.Run("nok - error", func(c *qt.C) {
Expand Down Expand Up @@ -178,7 +179,7 @@ func (m *MockAnthropicClient) generateTextChat(request messagesReq) (messagesRes
func TestComponent_Generation(t *testing.T) {
c := qt.New(t)
ctx := context.Background()
bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}
connector := Init(bc)

mockHistory := []message{
Expand Down
2 changes: 1 addition & 1 deletion ai/anthropic/v0/config/definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"TASK_TEXT_GENERATION_CHAT"
],
"custom": false,
"documentationUrl": "https://www.instill.tech/docs/latest/vdp/ai-connectors/anthropic",
"documentationUrl": "https://www.instill.tech/docs/component/ai/anthropic",
"icon": "assets/anthropic.svg",
"id": "anthropic",
"public": true,
Expand Down
66 changes: 17 additions & 49 deletions ai/anthropic/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ var (

type component struct {
base.Component

usageHandlerCreator base.UsageHandlerCreator
secretAPIKey string
instillAPIKey string
}

type AnthropicClient interface {
Expand Down Expand Up @@ -144,43 +142,15 @@ func Init(bc base.Component) *component {
type execution struct {
base.ComponentExecution

execute func(*structpb.Struct) (*structpb.Struct, error)
client AnthropicClient
usesSecret bool
}

// WithSecrets loads secrets into the connector, which can be used to configure
// it with globaly defined parameters.
func (c *component) WithSecrets(s map[string]any) *component {
c.secretAPIKey = base.ReadFromSecrets(cfgAPIKey, s)
return c
}

// WithUsageHandlerCreator overrides the UsageHandlerCreator method.
func (c *component) WithUsageHandlerCreator(newUH base.UsageHandlerCreator) *component {
c.usageHandlerCreator = newUH
return c
}

// UsageHandlerCreator returns a function to initialize a UsageHandler.
func (c *component) UsageHandlerCreator() base.UsageHandlerCreator {
if c.usageHandlerCreator == nil {
return c.Component.UsageHandlerCreator()
}
return c.usageHandlerCreator
}

func (c *component) CreateExecution(sysVars map[string]any, setup *structpb.Struct, task string) (*base.ExecutionWrapper, error) {

resolvedSetup, resolved, err := c.resolveSecrets(setup)
if err != nil {

Check failure on line 146 in ai/anthropic/v0/main.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected if, expected field name or embedded type

Check failure on line 146 in ai/anthropic/v0/main.go

View workflow job for this annotation

GitHub Actions / codecov

syntax error: unexpected if, expected field name or embedded type
return nil, err
}

e := &execution{

Check failure on line 150 in ai/anthropic/v0/main.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: non-declaration statement outside function body) (typecheck)

Check failure on line 150 in ai/anthropic/v0/main.go

View workflow job for this annotation

GitHub Actions / codecov

syntax error: non-declaration statement outside function body
ComponentExecution: base.ComponentExecution{Component: c, SystemVariables: sysVars, Task: task, Setup: setup},
client: newClient(getAPIKey(resolvedSetup), getBasePath(resolvedSetup), c.GetLogger()),
usesSecret: resolved,
ComponentExecution: base.ComponentExecution{Component: c, SystemVariables: sysVars, Task: task, Setup: resolvedSetup},
client: newClient(getAPIKey(resolvedSetup), getBasePath(resolvedSetup), c.GetLogger()),
usesInstillCredentials: resolved,
}
switch task {
case TextGenerationTask:
Expand All @@ -191,25 +161,27 @@ func (c *component) CreateExecution(sysVars map[string]any, setup *structpb.Stru
return &base.ExecutionWrapper{Execution: e}, nil
}

// resolveSecrets looks for references to a global secret in the setup
// and replaces them by the global secret injected during initialization.
func (c *component) resolveSecrets(conn *structpb.Struct) (*structpb.Struct, bool, error) {

apiKey := conn.GetFields()[cfgAPIKey].GetStringValue()

// resolveSetup checks whether the component is configured to use the Instill
// credentials injected during initialization and, if so, returns a new setup
// with the secret credential values.
func (c *component) resolveSetup(setup *structpb.Struct) (*structpb.Struct, bool, error) {
apiKey := setup.GetFields()[cfgAPIKey].GetStringValue()
if apiKey != base.SecretKeyword {
return conn, false, nil
return setup, false, nil
}

if c.secretAPIKey == "" {
return nil, false, base.NewUnresolvedSecret(cfgAPIKey)
if c.instillAPIKey == "" {
return nil, false, base.NewUnresolvedCredential(cfgAPIKey)
}

conn.GetFields()[cfgAPIKey] = structpb.NewStringValue(c.secretAPIKey)
return conn, true, nil
setup.GetFields()[cfgAPIKey] = structpb.NewStringValue(c.instillAPIKey)
return setup, true, nil
}

func (e *execution) UsesSecret() bool {
return e.usesSecret
func (e *execution) UsesInstillCredentials() bool {
return e.usesInstillCredentials
}

func (e *execution) Execute(_ context.Context, inputs []*structpb.Struct) ([]*structpb.Struct, error) {
Expand Down Expand Up @@ -247,8 +219,6 @@ func (e *execution) generateText(in *structpb.Struct) (*structpb.Struct, error)
message := message{Role: chatMessage.Role, Content: contents}
messages = append(messages, message)
}


finalMessage := message{
Role: "user",
Content: []content{{Type: "text", Text: prompt}},
Expand All @@ -267,8 +237,6 @@ func (e *execution) generateText(in *structpb.Struct) (*structpb.Struct, error)
}
finalMessage.Content = append(finalMessage.Content, image)
}


messages = append(messages, finalMessage)

req := messagesReq{
Expand Down
7 changes: 3 additions & 4 deletions ai/archetypeai/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/instill-ai/component/internal/util/httpclient"
"github.com/instill-ai/x/errmsg"

"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"
)

Expand Down Expand Up @@ -228,7 +227,7 @@ func TestComponent_Execute(t *testing.T) {
},
}

bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}
component := Init(bc)

for _, tc := range testcases {
Expand Down Expand Up @@ -288,7 +287,7 @@ func TestComponent_Execute(t *testing.T) {
func TestComponent_CreateExecution(t *testing.T) {
c := qt.New(t)

bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}
component := Init(bc)

c.Run("nok - unsupported task", func(c *qt.C) {
Expand All @@ -304,7 +303,7 @@ func TestComponent_CreateExecution(t *testing.T) {
func TestComponent_Test(t *testing.T) {
c := qt.New(t)

bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}
component := Init(bc)

c.Run("ok - connected", func(c *qt.C) {
Expand Down
2 changes: 1 addition & 1 deletion ai/archetypeai/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Init(bc base.Component) *component {
func (c *component) CreateExecution(sysVars map[string]any, setup *structpb.Struct, task string) (*base.ExecutionWrapper, error) {
e := &execution{
ComponentExecution: base.ComponentExecution{Component: c, SystemVariables: sysVars, Setup: setup, Task: task},
client: newClient(setup, c.Logger),
client: newClient(setup, c.GetLogger()),
}

switch task {
Expand Down
3 changes: 1 addition & 2 deletions ai/huggingface/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

qt "github.com/frankban/quicktest"
"go.uber.org/zap"
"google.golang.org/protobuf/types/known/structpb"

"github.com/instill-ai/component/base"
Expand Down Expand Up @@ -221,7 +220,7 @@ func TestComponent_ExecuteSpeechRecognition(t *testing.T) {
}

func testTask(c *qt.C, p taskParams) {
bc := base.Component{Logger: zap.NewNop()}
bc := base.Component{}
connector := Init(bc)
ctx := context.Background()

Expand Down
2 changes: 1 addition & 1 deletion ai/huggingface/v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func (e *execution) Execute(_ context.Context, inputs []*structpb.Struct) ([]*st
}

func (c *component) Test(sysVars map[string]any, setup *structpb.Struct) error {
req := newClient(setup, c.Logger).R()
req := newClient(setup, c.GetLogger()).R()
resp, err := req.Get("")
if err != nil {
return err
Expand Down
Loading

0 comments on commit 1daa986

Please sign in to comment.