llm

package
v0.0.0-...-7c1ad8c Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseJSONResponse

func ParseJSONResponse[T any](ctx context.Context, client Client, sessionID string, rawResponse string) (T, error)

ParseJSONResponse attempts to parse a JSON response from LLM output. If the raw response is not valid JSON, it tries to extract JSON and optionally retries via the same session.

Types

type Client

type Client interface {
	// CreateSession creates a new isolated LLM session in the given working directory.
	CreateSession(ctx context.Context, title string, workDir string) (*SessionInfo, error)

	// SendPrompt sends a prompt to the given session and waits for completion.
	SendPrompt(ctx context.Context, sessionID string, prompt string) (*PromptResponse, error)

	// GetMessages retrieves all messages from a session.
	GetMessages(ctx context.Context, sessionID string) ([]Message, error)

	// DeleteSession deletes a session.
	DeleteSession(ctx context.Context, sessionID string) error

	// AbortSession aborts a running prompt in a session.
	AbortSession(ctx context.Context, sessionID string) error
}

Client abstracts LLM session operations for testability.

type CopilotClient

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

CopilotClient wraps the GitHub Copilot SDK to implement Client.

func NewCopilotClient

func NewCopilotClient(model string) *CopilotClient

NewCopilotClient creates a CopilotClient that uses the given model for all sessions.

func NewCopilotClientWithServer

func NewCopilotClientWithServer(model, serverURL string) *CopilotClient

NewCopilotClientWithServer creates a CopilotClient that connects to a shared server.

func (*CopilotClient) AbortSession

func (c *CopilotClient) AbortSession(ctx context.Context, sessionID string) error

func (*CopilotClient) CreateSession

func (c *CopilotClient) CreateSession(ctx context.Context, title string, workDir string) (*SessionInfo, error)

func (*CopilotClient) DeleteSession

func (c *CopilotClient) DeleteSession(_ context.Context, sessionID string) error

func (*CopilotClient) GetMessages

func (c *CopilotClient) GetMessages(_ context.Context, sessionID string) ([]Message, error)

func (*CopilotClient) SendPrompt

func (c *CopilotClient) SendPrompt(ctx context.Context, sessionID string, prompt string) (*PromptResponse, error)

func (*CopilotClient) Start

func (c *CopilotClient) Start(ctx context.Context) error

Start initializes the underlying Copilot SDK client.

func (*CopilotClient) Stop

func (c *CopilotClient) Stop() error

Stop shuts down all sessions and the SDK client.

type Message

type Message struct {
	Role    string
	Content string
}

Message represents a message from a session.

type MockClient

type MockClient struct {
	Sessions      map[string]*SessionInfo
	PromptResults map[string]string // sessionID -> response content
	DefaultResult string
	PromptHistory []PromptCall

	CreateErr      error
	PromptErr      error
	MessagesResult []Message
	// contains filtered or unexported fields
}

MockClient is a test double for Client.

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new MockClient with sensible defaults.

func (*MockClient) AbortSession

func (m *MockClient) AbortSession(_ context.Context, _ string) error

func (*MockClient) CreateSession

func (m *MockClient) CreateSession(_ context.Context, title string, _ string) (*SessionInfo, error)

func (*MockClient) DeleteSession

func (m *MockClient) DeleteSession(_ context.Context, sessionID string) error

func (*MockClient) GetMessages

func (m *MockClient) GetMessages(_ context.Context, _ string) ([]Message, error)

func (*MockClient) GetPromptHistory

func (m *MockClient) GetPromptHistory() []PromptCall

GetPromptHistory returns all prompt calls made to this mock.

func (*MockClient) SendPrompt

func (m *MockClient) SendPrompt(_ context.Context, sessionID string, prompt string) (*PromptResponse, error)

func (*MockClient) SetSessionResult

func (m *MockClient) SetSessionResult(sessionID string, result string)

SetSessionResult pre-sets the result for a specific session ID.

type PromptCall

type PromptCall struct {
	SessionID string
	Prompt    string
}

PromptCall records a call to SendPrompt.

type PromptResponse

type PromptResponse struct {
	Content string
}

PromptResponse represents the result of a prompt.

type SessionInfo

type SessionInfo struct {
	ID    string
	Title string
}

SessionInfo represents a created LLM session.

Jump to

Keyboard shortcuts

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