GetCompletion returns a command completion suggestion.
(settings *models.Settings, input, context string)
| 148 | |
| 149 | // GetCompletion returns a command completion suggestion. |
| 150 | func (s *Service) GetCompletion(settings *models.Settings, input, context string) (string, error) { |
| 151 | if len(input) < 2 { |
| 152 | return "", nil |
| 153 | } |
| 154 | prompt := `Current command being typed: "` + input + `" |
| 155 | Complete this command. Only respond with the remaining text to add, nothing else.` |
| 156 | |
| 157 | response, err := s.callAI(settings, prompt, &callOptions{ |
| 158 | maxTokens: 100, |
| 159 | temperature: 0.3, |
| 160 | }, systemPromptCompletion, context, nil) |
| 161 | if err != nil { |
| 162 | return "", err |
| 163 | } |
| 164 | // Clean up: remove quotes, newlines |
| 165 | trimmed := strings.TrimSpace(response) |
| 166 | trimmed = regexp.MustCompile(`^["']|["']$`).ReplaceAllString(trimmed, "") |
| 167 | return trimmed, nil |
| 168 | } |
| 169 | |
| 170 | func (s *Service) callAI(settings *models.Settings, prompt string, opts *callOptions, systemPrompt, context string, history []Message) (string, error) { |
| 171 | if s.enc == nil { |