common

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenAIBase            = "https://api.chatanywhere.tech/v1"
	GaiaToolLlamaGroqBase = "https://llamatool.us.gaianet.network/v1"
	GaiaToolLlama70BBase  = "https://llama70b.gaia.domains/v1"
	GaiaToolLlama8BBase   = "https://llama8b.gaia.domains/v1"
	GaiaToolLlama3BBase   = "https://llama3b.gaia.domains/v1"
	GaiaToolQWen72BBase   = "https://qwen72b.gaia.domains/v1"
	GaiaQWen7BBase        = "https://qwen7b.gaia.domains/v1"
	GaiaWhisperBase       = "https://whisper.gaia.domains/v1"
)

Variables

View Source
var (
	GlobalTaskTools    = map[task.TaskID]map[ToolId]ToolRegistry{}
	GlobalTaskToolsets = map[task.TaskID]map[ToolsetId]ToolsetRegistry{}
)
View Source
var (
	APIEndpointMap = map[OpenAIFunctionType][]APIEndpointInfo{
		OpenAIFunctionTypeChatWithTools: {
			{
				Name:   "openai-toolchat",
				Model:  "gpt-4o",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/chat/completions",
			},
			{
				Name:   "qwen-toolchat-72b",
				Model:  "qwen",
				Base:   GaiaToolQWen72BBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
			{
				Name:   "llama-toolchat-70b",
				Model:  "llama",
				Base:   GaiaToolLlama70BBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
			{
				Name:   "llama-toolchat",
				Model:  "llama",
				Base:   GaiaToolLlamaGroqBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
			{
				Name:   "llama-toolchat-8b",
				Model:  "llama",
				Base:   GaiaToolLlama8BBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
			{
				Name:   "llama-toolchat-3b",
				Model:  "llama",
				Base:   GaiaToolLlama3BBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
		},
		OpenAIFunctionTypeChatOnly: {
			{
				Name:   "openai-chat",
				Model:  "gpt-4o",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/chat/completions"},
			{
				Name:   "llama-chat",
				Model:  "llama",
				Base:   GaiaToolLlama8BBase,
				APIKey: "gaia",
				Url:    "/chat/completions",
			},
		},
		OpenAIFunctionTypeEmbeddings: {
			{
				Name:   "openai-embed",
				Model:  "text-embedding-ada-002",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/embeddings",
			},
			{
				Name:   "nomic-embed",
				Model:  "nomic-embed",
				Base:   GaiaToolLlama8BBase,
				APIKey: "gaia",
				Url:    "/embeddings",
			},
		},
		OpenAIFunctionTypeTextToSpeech: {
			{
				Name:   "openai-tts",
				Model:  "tts-1",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/audio/speech",
			},
		},
		OpenAIFunctionTypeImageGeneration: {
			{
				Name:   "openai-genimage",
				Model:  "dall-e-3",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/images/generations",
			},
		},
		OpenAIFunctionTypeSpeechToText: {
			{
				Name:   "gaia-whisper",
				Model:  "whisper",
				Base:   GaiaWhisperBase,
				APIKey: "gaia",
				Url:    "/audio/transcriptions",
			},
			{
				Name:   "openai-whisper",
				Model:  "whisper-1",
				Base:   OpenAIBase,
				APIKey: os.Getenv("OPENAI_API_KEY"),
				Url:    "/audio/transcriptions",
			},
		},
	}
)
View Source
var BuiltinTools = []ToolRegistry{}

Functions

func RegisterBuiltinTool

func RegisterBuiltinTool(tool ToolRegistry)

Types

type APIEndpointInfo

type APIEndpointInfo struct {
	Name   string
	Model  string
	Base   string
	APIKey string
	Url    string
}

func GetAPIEndpointInfo

func GetAPIEndpointInfo(ft OpenAIFunctionType, modelOrName string) []APIEndpointInfo

type BuiltInToolCbFunc

type BuiltInToolCbFunc func(inv *InvocationInfo, args interface{}) (interface{}, error)

type CommunicationManager

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

communication manager for hostcalls and guest responses

func NewCommunicationManager

func NewCommunicationManager() *CommunicationManager

func (*CommunicationManager) GetIncomingRequest

func (c *CommunicationManager) GetIncomingRequest() *ReqChanData

func (*CommunicationManager) GetIncomingResponse

func (c *CommunicationManager) GetIncomingResponse() *RespChanData

func (*CommunicationManager) InstallToTask

func (c *CommunicationManager) InstallToTask(t task.Task) error

func (*CommunicationManager) SendOutgoingJsonRequest

func (c *CommunicationManager) SendOutgoingJsonRequest(t task.Task, req *rpc.JsonRPCRequest) (*rpc.JsonRPCResponse, error)

users need to specify the id in the request

func (*CommunicationManager) SendOutgoingJsonRequestCallback

func (c *CommunicationManager) SendOutgoingJsonRequestCallback(t task.Task, req *rpc.JsonRPCRequest, cb func(*rpc.JsonRPCResponse) error) error

users need to specify the id in the request

func (*CommunicationManager) SendOutgoingJsonResponse

func (c *CommunicationManager) SendOutgoingJsonResponse(t task.Task, resp *rpc.JsonRPCResponse) error

func (*CommunicationManager) SendOutgoingRPCRequest

func (c *CommunicationManager) SendOutgoingRPCRequest(t task.Task, method string, params interface{}) (*rpc.JsonRPCResponse, error)

automatically generate the id

func (*CommunicationManager) SendOutgoingRPCRequestCallback

func (c *CommunicationManager) SendOutgoingRPCRequestCallback(t task.Task, method string, params interface{}, cb ResquestCallback) error

automatically generate the id

type HostCall

type HostCall struct {
	Name    string
	Handler HostCallHandler
}

type HostCallHandler

type HostCallHandler func(inv *InvocationInfo, args interface{}) (interface{}, error)

type HostCalls

type HostCalls struct {
	// map of hostcalls
	HCMap   map[string]HostCallHandler
	CommMgr *CommunicationManager
}

func NewHostCalls

func NewHostCalls(commMgr *CommunicationManager) *HostCalls

func (*HostCalls) RegisterHostCall

func (h *HostCalls) RegisterHostCall(hc *HostCall) error

func (*HostCalls) Run

func (h *HostCalls) Run()

type InvocationInfo

type InvocationInfo struct {
	Task    *task.Task
	CommMgr *CommunicationManager
}

invokation info

type OpenAIFunctionType

type OpenAIFunctionType int
const (
	OpenAIFunctionTypeChatWithTools OpenAIFunctionType = iota
	OpenAIFunctionTypeChatOnly
	OpenAIFunctionTypeEmbeddings
	OpenAIFunctionTypeTextToSpeech
	OpenAIFunctionTypeSpeechToText
	OpenAIFunctionTypeImageGeneration
)

type ReqChanData

type ReqChanData struct {
	Req     *rpc.JsonRPCRequest
	InvInfo *InvocationInfo
}

type RespChanData

type RespChanData struct {
	Resp    *rpc.JsonRPCResponse
	InvInfo *InvocationInfo
}

type ResquestCallback

type ResquestCallback func(resp *rpc.JsonRPCResponse) error

type ToolId

type ToolId string

type ToolParam

type ToolParam struct {
	Ptype       string
	Description string
	Required    bool
}

type ToolRegistry

type ToolRegistry struct {
	Name        string
	Description string
	Params      map[string]ToolParam
	Cb          string
	CbBuiltIn   BuiltInToolCbFunc
}

func GetBuiltinTools

func GetBuiltinTools() []ToolRegistry

type ToolsetId

type ToolsetId string

type ToolsetRegistry

type ToolsetRegistry struct {
	Description string
	ToolsIds    []ToolId
}

Jump to

Keyboard shortcuts

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