Compare commits
37 Commits
1456442d4e
...
657416780d
Author | SHA1 | Date | |
---|---|---|---|
657416780d | |||
c143d863cb | |||
3aff5514e4 | |||
5acdbb5675 | |||
c53e952acc | |||
3d8d3b61b3 | |||
4fb059c850 | |||
e9fde37201 | |||
6242ea17d8 | |||
2ca94e1ffb | |||
2b0d474660 | |||
fdf8033aff | |||
cf46088762 | |||
c4b78aa0c6 | |||
377a4f1dfa | |||
000a2ec6f2 | |||
387dd7534c | |||
c14541577e | |||
213e36f652 | |||
9e02277ee7 | |||
a96eac91b3 | |||
ccf2353a0b | |||
51e6f6ebf6 | |||
6cb8d03c5b | |||
50ad7d9ec6 | |||
5e26ee3373 | |||
8bc2523c17 | |||
a06ac694c6 | |||
00eb57820f | |||
d1f10d2cfc | |||
1bd6baa837 | |||
8613719b58 | |||
51de2b7079 | |||
fe5baf58e3 | |||
0ebfd39297 | |||
780c34a7ef | |||
6bf2f1bb43 |
@ -118,18 +118,11 @@ func HandleConversationReply(ctx *lmcli.Context, c *model.Conversation, persist
|
||||
func FormatForExternalPrompt(messages []model.Message, system bool) string {
|
||||
sb := strings.Builder{}
|
||||
for _, message := range messages {
|
||||
if message.Content == "" {
|
||||
if message.Role != model.MessageRoleUser && (message.Role != model.MessageRoleSystem || !system) {
|
||||
continue
|
||||
}
|
||||
switch message.Role {
|
||||
case model.MessageRoleAssistant, model.MessageRoleToolCall:
|
||||
sb.WriteString("Assistant:\n\n")
|
||||
case model.MessageRoleUser:
|
||||
sb.WriteString("User:\n\n")
|
||||
default:
|
||||
continue
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("%s", lipgloss.NewStyle().PaddingLeft(1).Render(message.Content)))
|
||||
sb.WriteString(fmt.Sprintf("<%s>\n", message.Role.FriendlyRole()))
|
||||
sb.WriteString(fmt.Sprintf("\"\"\"\n%s\n\"\"\"\n\n", message.Content))
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
@ -140,32 +133,13 @@ func GenerateTitle(ctx *lmcli.Context, c *model.Conversation) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
const prompt = `Above is an excerpt from a conversation between a user and AI assistant. Please reply with a short title (no more than 8 words) that reflects the topic of the conversation, read from the user's perspective.
|
||||
|
||||
Example conversation:
|
||||
|
||||
"""
|
||||
User:
|
||||
|
||||
Hello!
|
||||
|
||||
Assistant:
|
||||
|
||||
Hello! How may I assist you?
|
||||
"""
|
||||
|
||||
Example response:
|
||||
|
||||
"""
|
||||
Title: A brief introduction
|
||||
"""
|
||||
`
|
||||
conversation := FormatForExternalPrompt(messages, false)
|
||||
const header = "Generate a concise 4-5 word title for the conversation below."
|
||||
prompt := fmt.Sprintf("%s\n\n---\n\n%s", header, FormatForExternalPrompt(messages, false))
|
||||
|
||||
generateRequest := []model.Message{
|
||||
{
|
||||
Role: model.MessageRoleUser,
|
||||
Content: fmt.Sprintf("\"\"\"\n%s\n\"\"\"\n\n%s", conversation, prompt),
|
||||
Content: prompt,
|
||||
},
|
||||
}
|
||||
|
||||
@ -184,15 +158,12 @@ Title: A brief introduction
|
||||
return "", err
|
||||
}
|
||||
|
||||
response = strings.TrimPrefix(response, "Title: ")
|
||||
response = strings.Trim(response, "\"")
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// ShowWaitAnimation prints an animated ellipses to stdout until something is
|
||||
// received on the signal channel. An empty string sent to the channel to
|
||||
// notify the caller that the animation has completed (carriage returned).
|
||||
// noftify the caller that the animation has completed (carriage returned).
|
||||
func ShowWaitAnimation(signal chan any) {
|
||||
// Save the current cursor position
|
||||
fmt.Print("\033[s")
|
||||
|
@ -68,7 +68,7 @@ func buildRequest(params model.RequestParameters, messages []model.Message) Requ
|
||||
startIdx := 0
|
||||
if len(messages) > 0 && messages[0].Role == model.MessageRoleSystem {
|
||||
requestBody.System = messages[0].Content
|
||||
requestBody.Messages = requestBody.Messages[1:]
|
||||
requestBody.Messages = requestBody.Messages[:len(messages)-1]
|
||||
startIdx = 1
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,9 @@ import (
|
||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
|
||||
)
|
||||
|
||||
const TOOL_PREAMBLE = `You have access to the following tools when replying.
|
||||
const TOOL_PREAMBLE = `In this environment you have access to a set of tools which may assist you in fulfilling user requests.
|
||||
|
||||
You may call them like this:
|
||||
|
||||
<function_calls>
|
||||
<invoke>
|
||||
<tool_name>$TOOL_NAME</tool_name>
|
||||
@ -25,14 +24,6 @@ You may call them like this:
|
||||
|
||||
Here are the tools available:`
|
||||
|
||||
const TOOL_PREAMBLE_FOOTER = `Recognize the utility of these tools in a broad range of different applications, and the power they give you to solve a wide range of different problems. However, ensure that the tools are used judiciously and only when clearly relevant to the user's request. Specifically:
|
||||
|
||||
1. Only use a tool if the user has explicitly requested or provided information that warrants its use. Do not make assumptions about files or data existing without the user mentioning them.
|
||||
|
||||
2. If there is ambiguity about whether using a tool is appropriate, ask a clarifying question to the user before proceeding. Confirm your understanding of their request and intent.
|
||||
|
||||
3. Prioritize providing direct responses and explanations based on your own knowledge and understanding. Use tools to supplement and enhance your responses when clearly applicable, but not as a default action.`
|
||||
|
||||
type XMLTools struct {
|
||||
XMLName struct{} `xml:"tools"`
|
||||
ToolDescriptions []XMLToolDescription `xml:"tool_description"`
|
||||
@ -160,7 +151,7 @@ func buildToolsSystemPrompt(tools []model.Tool) string {
|
||||
if err != nil {
|
||||
panic("Could not serialize []model.Tool to XMLTools")
|
||||
}
|
||||
return TOOL_PREAMBLE + "\n\n" + xmlToolsString + "\n\n" + TOOL_PREAMBLE_FOOTER
|
||||
return TOOL_PREAMBLE + "\n" + xmlToolsString + "\n"
|
||||
}
|
||||
|
||||
func (x XMLTools) XMLString() (string, error) {
|
||||
|
@ -244,7 +244,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if last < 0 {
|
||||
panic("Unexpected empty messages handling msgResponseEnd")
|
||||
}
|
||||
m.setMessageContents(last, strings.TrimSpace(string(msg)))
|
||||
m.setMessageContents(last, strings.TrimSpace(m.messages[last].Content))
|
||||
m.updateContent()
|
||||
m.status = "Press ctrl+s to send"
|
||||
case msgResponseError:
|
||||
@ -786,22 +786,17 @@ func (m *model) conversationView() string {
|
||||
// write message heading with space for content
|
||||
user := style.Render(icon + friendly)
|
||||
|
||||
var prefix string
|
||||
var suffix string
|
||||
|
||||
faint := lipgloss.NewStyle().Faint(true)
|
||||
if m.focus == focusMessages {
|
||||
if i == m.selectedMessage {
|
||||
prefix = "> "
|
||||
}
|
||||
suffix += faint.Render(fmt.Sprintf(" (%d/%d)", i+1, msgCnt))
|
||||
}
|
||||
|
||||
var saved string
|
||||
if message.ID == 0 {
|
||||
suffix += faint.Render(" (not saved)")
|
||||
saved = lipgloss.NewStyle().Faint(true).Render(" (not saved)")
|
||||
}
|
||||
|
||||
header := lipgloss.NewStyle().PaddingLeft(1).Render(prefix + user + suffix)
|
||||
var selectedPrefix string
|
||||
if m.focus == focusMessages && i == m.selectedMessage {
|
||||
selectedPrefix = "> "
|
||||
}
|
||||
|
||||
header := lipgloss.NewStyle().PaddingLeft(1).Render(selectedPrefix + user + saved)
|
||||
sb.WriteString(header)
|
||||
lineCnt += lipgloss.Height(header)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user