Files
enkly-ai/pkg/vllmkit/types.go
enkly 79ce8dc4c0
Some checks failed
Go CI Pipeline / build_and_test (push) Failing after 22m0s
Init Project
2026-10-30 18:06:55 +01:00

74 lines
2.7 KiB
Go

package vllmkit
// Role, Message, ToolCallRequest and ToolDef are local equivalents of
// the monolith's internal/models types — kept here, scoped to exactly
// what the OpenAI-compatible chat-completions wire protocol vLLM
// serves needs, so this package has no dependency beyond the Go
// standard library. The agent service (the only caller of ChatStream)
// translates its own domain messages to and from these at the
// boundary; see services/agent/internal/infrastructure/agentrun.
type Role string
const (
RoleUser Role = "user"
RoleAssistant Role = "assistant"
RoleSystem Role = "system"
RoleTool Role = "tool"
)
// Message is one turn in a conversation, as sent to/received from
// vLLM's OpenAI-compatible /v1/chat/completions endpoint.
type Message struct {
Role Role
Content string
ToolName string
Thinking string // reasoning trace (OpenAI wire: "reasoning_content"); sent back to the model, never persisted
// ToolCalls is set on an assistant message that requested one or
// more tool invocations — see ToolCallRequest.
ToolCalls []ToolCallRequest
// ToolCallID identifies, on a role="tool" message, which of the
// preceding assistant message's ToolCalls this is the result for.
// The OpenAI tool-calling contract requires every tool message to
// carry the matching call's id (unlike Ollama's native /api/chat,
// which correlated tool replies positionally with no id at all) —
// vLLM's tool-call parsers (hermes, llama3-json, qwen, …) reject a
// tool message with a missing/mismatched tool_call_id outright, so
// this must be populated whenever Role == RoleTool. Callers get it
// for free: ToolCallRequest.ID below is populated straight off the
// id vLLM assigned the call, and ToolResult carries it forward
// unchanged — see agentrun.Agent.Run, which copies
// ToolCallRequest.ID into the ToolResult it builds and then into
// this field when it appends the reply message.
ToolCallID string
}
// ToolCallRequest is a single tool invocation the model asked for. ID
// is the id vLLM's response assigned the call (OpenAI wire:
// tool_calls[].id) — callers must echo it back as ToolResult's
// ToolCallID so the follow-up tool message can carry Message.ToolCallID.
type ToolCallRequest struct {
ID string
Name string
Arguments map[string]any
}
// ToolResult is what gets fed back to the model after executing a
// ToolCallRequest.
type ToolResult struct {
ToolCallID string
Name string
Content string
IsError bool
}
// ToolDef describes a single callable tool in the JSON-schema shape
// the OpenAI-compatible function-calling API (and therefore vLLM)
// expects.
type ToolDef struct {
Name string
Description string
Parameters map[string]any // JSON Schema object
}