ace

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 8 Imported by: 0

README

ace-go

概要

ace-go は来栖川電算の CLI 型 AI エージェント ACE を Go から簡単に利用するためのラッパーライブラリです。

インストール

go get github.com/kurusugawa-computer/ace-go

使用例

簡単な使用例です。環境変数 OPENAI_API_KEY に API キーを入れて実行します。

import (
 "context"
 "fmt"
 "log"
 "os"

 "github.com/kurusugawa-computer/ace-go"
)

func main() {
  apiKey := os.Getenv("OPENAI_API_KEY")
  ace := ace.New(ace.WitAPIKey(apiKey))

  ctx := context.Background()
  result, err := ace.Invoke(
    ctx,
    "simple.yaml",
    "root",
    map[string]any{"question": "今日の名古屋の天気は?"},
  )
  if err != nil {
    log.Fatalln(err)
  }

  type Response struct {
    Answer string `json:"answer"`
  }
  var response Response
  if err := result.Unmarshal(&response); err != nil {
    log.Fatalln(err)
  }

  fmt.Println(response.Answer)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ace

type Ace struct {
	// contains filtered or unexported fields
}

Ace は ace コマンドをラップするクライアント構造体です。 内部で実行コマンドのパスやログ設定、認証用のロックを保持します。

func New

func New(options ...AceOption) *Ace

New は ACE のインスタンスを作成します。 WithExecutablePath で ace コマンドの実行パスを指定します。 WithLogger で ace コマンドのログ出力を設定します。

func (*Ace) Invoke

func (ace *Ace) Invoke(ctx context.Context, configPath string, agentName string, input map[string]any, options ...InvokeOption) (*Result, error)

Invoke は ACE を実行して結果を返します。

func (*Ace) SetExecutablePath

func (ace *Ace) SetExecutablePath(path string)

SetExecutablePath は ACE インスタンスの実行ファイルパスを設定します。 テストやカスタムビルドを使う場合に利用します。

type AceOption

type AceOption func(*Ace)

AceOption は ACE の設定を変更するためのオプション関数です。 これを使って `New` 呼び出し時に実装固有の設定を注入できます。

func WitAPIKey

func WitAPIKey(apiKey string) AceOption

WithAPIKey は ACE が使用する OpenAI の API Key を設定する オプションを返します。

func WithExecutablePath

func WithExecutablePath(path string) AceOption

WithExecutablePath は ACE が使用する実行ファイルのパスを設定する オプションを返します。デフォルトは `ace` です。

type InvokeOption

type InvokeOption func(*invokeOptions) error

InvokeOption は Invoke 呼び出しに渡すオプション関数の型です。 各オプションは内部の `invokeOptions` を変更し、エラーを返すことができます。

func WithLogger

func WithLogger(w io.Writer, level string) InvokeOption

WithLogger は ACE のログ出力先とログレベルを設定するオプションを返します。 `w` にログが書き出され、`level` でログの詳細度を制御します。

func WithWorkdir

func WithWorkdir(workdir string) InvokeOption

WithWorkdir は ACE 実行時のカレントディレクトリを指定するオプションを返します。

type Result

type Result struct {
	Text string
}

func (Result) Unmarshal

func (result Result) Unmarshal(v any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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