dbus: add Generate and Route methods
Generate: stateless one-shot LLM call (prompt, system, backend, model) Route: classify task, return best backend+model from available models Both delegate to core backend.Generate() and backend.Route(). KDE frontends can use Route as a preprocessing step before CreateSession.
This commit is contained in:
parent
935c234ce9
commit
8bd59a6509
38
main.go
38
main.go
|
|
@ -1019,6 +1019,32 @@ func (m *SessionManager) restoreSession(ps *agent.PersistedSession) error {
|
||||||
|
|
||||||
// --- Completion ---
|
// --- Completion ---
|
||||||
|
|
||||||
|
// Generate performs a stateless one-shot LLM generation.
|
||||||
|
func (m *SessionManager) Generate(prompt, system, backendName, model string) (string, *dbus.Error) {
|
||||||
|
result, err := backend.Generate(context.Background(), backend.GenerateRequest{
|
||||||
|
Prompt: prompt,
|
||||||
|
System: system,
|
||||||
|
Backend: backendName,
|
||||||
|
Model: model,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", dbus.MakeFailedError(err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Route classifies a task and selects the best available backend+model.
|
||||||
|
func (m *SessionManager) Route(task, backendName string) (string, *dbus.Error) {
|
||||||
|
result, err := backend.Route(context.Background(), backend.RouteRequest{
|
||||||
|
Task: task,
|
||||||
|
Backend: backendName,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", dbus.MakeFailedError(err)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("backend=%s model=%s", result.Backend, result.Model), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Complete performs a single-shot code completion using a dedicated copilot session.
|
// Complete performs a single-shot code completion using a dedicated copilot session.
|
||||||
// It takes context about the cursor position and returns raw completion text.
|
// It takes context about the cursor position and returns raw completion text.
|
||||||
func (m *SessionManager) Complete(cwd, filePath, prefix, suffix, extraContext string) (string, *dbus.Error) {
|
func (m *SessionManager) Complete(cwd, filePath, prefix, suffix, extraContext string) (string, *dbus.Error) {
|
||||||
|
|
@ -1328,6 +1354,18 @@ const introspectXML = `<node>
|
||||||
<arg name="prompt" type="s" direction="in"/>
|
<arg name="prompt" type="s" direction="in"/>
|
||||||
<arg name="success" type="b" direction="out"/>
|
<arg name="success" type="b" direction="out"/>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="Generate">
|
||||||
|
<arg name="prompt" type="s" direction="in"/>
|
||||||
|
<arg name="system" type="s" direction="in"/>
|
||||||
|
<arg name="backend" type="s" direction="in"/>
|
||||||
|
<arg name="model" type="s" direction="in"/>
|
||||||
|
<arg name="result" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
|
<method name="Route">
|
||||||
|
<arg name="task" type="s" direction="in"/>
|
||||||
|
<arg name="backend" type="s" direction="in"/>
|
||||||
|
<arg name="result" type="s" direction="out"/>
|
||||||
|
</method>
|
||||||
<method name="Complete">
|
<method name="Complete">
|
||||||
<arg name="cwd" type="s" direction="in"/>
|
<arg name="cwd" type="s" direction="in"/>
|
||||||
<arg name="file" type="s" direction="in"/>
|
<arg name="file" type="s" direction="in"/>
|
||||||
|
|
|
||||||
Reference in New Issue