goai

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

Go AI

build Coverage Status Go Report Card Godoc Release

A golang API library for AI Engineering.

This is a high level feature overview.

  • Chat Completion
  • Embedding

Installation

go get -u 'github.com/tech1024/goai'

Getting Started

package main

import (
	"context"
	"log"

	"github.com/tech1024/goai"
	"github.com/tech1024/goai/provider/ollama"
)

func main() {
	ollamaClient, _ := ollama.NewClient("http://127.0.0.1:11434")
	chat := goai.NewChat(ollama.NewNewChatModel(ollamaClient, "deepseek-r1"))
	result, err := chat.Chat(context.Background(), "What can you do for me ?")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(result)
}

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chat

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

func NewChat

func NewChat(chatModel ChatModel) *Chat

func (*Chat) Chat

func (c *Chat) Chat(ctx context.Context, content string) (string, error)

Chat send a message, it returns string

func (*Chat) ChatStream

func (c *Chat) ChatStream(ctx context.Context, content string, receive func([]byte) error) error

ChatStream send a message, need to receive its returns

func (*Chat) Prompt

func (c *Chat) Prompt(ctx context.Context, p prompt.Prompt) (string, error)

func (*Chat) Stream

func (c *Chat) Stream(ctx context.Context, p prompt.Prompt, fn func([]byte) error) error

type ChatModel

type ChatModel interface {
	Call(ctx context.Context, prompt prompt.Prompt) (string, error)
	Stream(ctx context.Context, prompt prompt.Prompt, receive func([]byte) error) error
}

type Embedding

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

func (*Embedding) Embed

func (e *Embedding) Embed(ctx context.Context, text string) ([]float32, error)

func (*Embedding) Embeds

func (e *Embedding) Embeds(ctx context.Context, texts ...string) ([][]float32, error)

type EmbeddingModel

type EmbeddingModel interface {
	Call(context.Context, embedding.Request) (embedding.Response, error)
}

Directories

Path Synopsis
provider

Jump to

Keyboard shortcuts

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