aicli

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 1 Imported by: 0

README

aicli

aicli is AI assistant client library for Go, support ChatGPT, DeepSeek and Gemini.


Example of use

ChatGPT

package main

import (
    "context"
    "fmt"
    "github.com/go-dev-frame/sponge/pkg/aicli/chatgpt"
)

func main() {
    var apiKey = "sk-xxxxxx"
    client, _ := chatgpt.NewClient(apiKey) // you can use set client options, e.g. WithModel(ModelGPT4o)

    // case 1: default
    content, _ := client.Send(context.Background(), "Who are you?)
    fmt.Println(content)

    // case 2: stream
    answer := client.SendStream(context.Background(), "Which model did you use to answer the question?")
    for content := range answer.Content {
        fmt.Printf(content)
    }
    if answer.Err != nil {
        panic(answer.Err)
    }
}

NewClient function supports setting options, such as WithModel("gpt-4o"), WithEnableContext() and other parameter settings.


DeepSeek

package main

import (
    "context"
    "fmt"
    "github.com/go-dev-frame/sponge/pkg/aicli/deepseek"
)

func main() {
    var apiKey = "sk-xxxxxx"
    client, _ := deepseek.NewClient(apiKey) // you can use set client options, e.g. WithModel(ModelDeepSeekReasoner)

    // case 1: default
    content, _ := client.Send(context.Background(), "Who are you?)
    fmt.Println(content)

    // case 2: stream
    answer := client.SendStream(context.Background(), "Which model did you use to answer the question?")
    for content := range answer.Content {
        fmt.Printf(content)
    }
    if answer.Err != nil {
        panic(answer.Err)
    }
}

NewClient function supports setting options, such as WithModel("deepseek-reasoner"), WithEnableContext() and other parameter settings.


Gemini

package main

import (
    "context"
    "fmt"
    "github.com/go-dev-frame/sponge/pkg/aicli/gemini"
)

func main() {
    var apiKey = "sk-xxxxxx"
    client, _ := gemini.NewClient(apiKey) // you can use set client options, e.g. WithModel(Model20FlashThinking)

    // case 1: default
    content, _ := client.Send(context.Background(), "Who are you?")
    fmt.Println(content)

    // case 2: stream
    answer := client.SendStream(context.Background(), "Which model did you use to answer the question?")
    for content := range answer.Content {
        fmt.Printf(content)
    }
    if answer.Err != nil {
        panic(answer.Err)
    }
}

NewClient function supports setting options, such as WithModel("gemini-2.0-flash-thinking-exp"), WithEnableContext() and other parameter settings.

Send and SendStream functions support file upload, example: Send(ctx, "prompt", file).

Supported file types are as follows:

text/plain
application/pdf
audio/mpeg
audio/mp3
audio/wav
image/png
image/jpeg
video/mov
video/mpeg
video/mp4
video/mpg
video/avi
video/wmv
video/mpegps
video/flv

Documentation

Overview

Package aicli provides the interface for sending request to assistant.

Index

Constants

View Source
const (
	GenericRoleDescEN = `You are a helpful assistant, able to answer user questions in a clear and friendly manner.`
	GenericRoleDescCN = `你是一个有帮助的助手,能够以清晰、友好的方式回答用户的问题。`

	GopherRoleDescEN = `` /* 510-byte string literal not displayed */

	GopherRoleDescCN = `` /* 407-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type Assistanter

type Assistanter interface {
	Send(ctx context.Context, prompt string, files ...string) (string, error)
	SendStream(ctx context.Context, prompt string, files ...string) *StreamReply
	RefreshContext()
	ListModelNames(ctx context.Context) ([]string, error)
}

Assistanter interface for sending request to assistant

type StreamReply

type StreamReply struct {
	Content chan string
	Err     error // if nil means successfully response
}

StreamReply reply with stream response

Directories

Path Synopsis
Package chatgpt provides a client for the OpenAI chat GPT API.
Package chatgpt provides a client for the OpenAI chat GPT API.
Package deepseek provides a client for the DeepSeek API.
Package deepseek provides a client for the DeepSeek API.
Package gemini provides a client for the Google generative AI API.
Package gemini provides a client for the Google generative AI API.

Jump to

Keyboard shortcuts

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