metaphor

package
v0.1.2-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

// Package metaphor contains an implementation of the tool interface with the metaphor search api client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API defines a tool implementation for the Metaphor API.

func NewClient

func NewClient() (*API, error)

NewClient initializes a new API client.

It retrieves the API key from the environment variable "METAPHOR_API_KEY" and creates a new client using the retrieved API key. If the API key is not set or an error occurs during client creation, an error is returned.

Returns a pointer to the created API client and an error, if any.

func (*API) Call

func (tool *API) Call(ctx context.Context, input string) (string, error)

Call is a function that takes a context and an input string and returns a string and an error.

The function expects a JSON string as input and unmarshals it into a ToolInput struct. It then performs different operations based on the value of the Operation field in the ToolInput struct. The supported operations are "Search", "FindSimilar", and "GetContents".

If the Operation is "Search", the function calls the performSearch method passing the context and the ToolInput struct. If the Operation is "FindSimilar", the function calls the findSimilar method passing the context and the ToolInput struct. If the Operation is "GetContents", the function calls the getContents method passing the context and the ToolInput struct.

The function returns the result of the respective operation or an empty string and nil if the Operation is not supported.

func (*API) Description

func (tool *API) Description() string

Description returns the Description of the tool. Description contains a short instruction how to use the tool with the Metaphor API

No parameters. Returns a string.

func (*API) Name

func (tool *API) Name() string

Name returns the name of the tool.

No parameters. Returns a string.

type Documents

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

Documents defines a tool implementation for the Metaphor Web scrapper.

func NewDocuments

func NewDocuments(options ...metaphor.ClientOptions) (*Documents, error)

NewDocuments creates a new instance of the Documents struct.

The function takes in optional metaphorm.ClientOptions as parameters. It returns a pointer to a Documents struct and an error.

func (*Documents) Call

func (tool *Documents) Call(ctx context.Context, input string) (string, error)

Call calls the Documents API with the given input and returns the formatted contents.

The input is a string that contains a comma-separated list of IDs.

It returns a string which represents the formatted contents and an error if any.

func (*Documents) Description

func (tool *Documents) Description() string

Description returns the contents of web pages based on a list of ID strings.

It is designed to be used with Metaphor Search and/or Metaphor Links Search Tool. The expected input format is a list of ID strings obtained from either Metaphor Search or Metaphor Search Links tool. The function returns a string.

func (*Documents) Name

func (tool *Documents) Name() string

Name returns the name of the Documents tool.

It does not take any parameters. It returns a string, which is the name of the tool.

func (*Documents) SetOptions

func (tool *Documents) SetOptions(options ...metaphor.ClientOptions)

SetOptions sets the options for the Documents struct.

It takes in variadic parameter(s) of type `metaphor.ClientOptions`.

type LinksSearch

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

LinksSearch defines a tool implementation for the Metaphor Find Similar Links.

func NewLinksSearch

func NewLinksSearch(options ...metaphor.ClientOptions) (*LinksSearch, error)

NewLinksSearch creates a new metaphor Search instance, that can be used to find similar links.

It accepts an optional list of ClientOptions as parameters. It returns a pointer to a LinksSearch instance and an error.

func (*LinksSearch) Call

func (tool *LinksSearch) Call(ctx context.Context, input string) (string, error)

Call searches for similar links using the LinksSearch tool.

ctx - the context in which the function is called. input - the string input used to find similar links, i.e. the url. Returns a string containing the formatted links and an error if any occurred.

func (*LinksSearch) Description

func (tool *LinksSearch) Description() string

Description returns the description of the LinksSearch tool.

This function does not take any parameters. It returns a string that describes the purpose of the LinksSearch tool.

func (*LinksSearch) Name

func (tool *LinksSearch) Name() string

Name returns the name of the LinksSearch tool.

No parameters. Returns a string.

func (*LinksSearch) SetOptions

func (tool *LinksSearch) SetOptions(options ...metaphor.ClientOptions)

SetOptions sets the options for the LinksSearch tool.

It takes in one or more ClientOptions parameters and assigns them to the tool's options field.

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

Search defines a tool implementation for the Metaphor Search.

func NewSearch

func NewSearch(options ...metaphor.ClientOptions) (*Search, error)

NewSearch creates a new Metaphot Search instance.

It accepts an optional variadic parameter of type metaphor.ClientOptions. The function returns a pointer to a Search instance and an error.

func (*Search) Call

func (tool *Search) Call(ctx context.Context, input string) (string, error)

Call performs a search using the Search client.

It takes a context.Context and a search query as string input as parameters. It returns a string and an error.

func (*Search) Description

func (tool *Search) Description() string

Description returns the description of the Search tool.

This function does not take any parameters. It returns a string that contains the description of the Search tool.

func (*Search) Name

func (tool *Search) Name() string

Name returns the name of the Search tool.

This function takes no parameters. It returns a string.

func (*Search) SetOptions

func (tool *Search) SetOptions(options ...metaphor.ClientOptions)

SetOptions sets the options for the Search tool.

options is a variadic parameter of type metaphor.ClientOptions.

type ToolInput

type ToolInput struct {
	Operation  string                  `json:"operation"`
	Input      string                  `json:"input"`
	ReqOptions metaphor.RequestOptions `json:"reqOptions"`
}

ToolInput defines a struct the tool expects as input.

Jump to

Keyboard shortcuts

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