@@ -81,25 +81,26 @@ export async function alterGeneratedImg (
8181
8282type ConversationOutput = Omit < ChatConversation , 'timestamp' | 'model' | 'id' | 'author' | 'numSubAgents' >
8383
84- const prepareConversation = ( conversation : ChatConversation [ ] , model : string ) : ConversationOutput [ ] => {
84+ const prepareConversation = ( conversation : ChatConversation [ ] , model : string , ctx : OnMessageContext | OnCallBackQueryData ) : ConversationOutput [ ] => {
8585 const messages = conversation . filter ( c => c . model === model ) . map ( m => { return { content : m . content , role : m . role } } )
8686 if ( messages . length !== 1 || model === LlmModelsEnum . O1 ) {
8787 return messages
8888 }
8989 const systemMessage = {
9090 role : 'system' ,
91- content : config . openAi . chatGpt . chatCompletionContext
91+ content : ctx . session . currentPrompt
9292 }
9393 return [ systemMessage , ...messages ]
9494}
9595
9696export async function chatCompletion (
9797 conversation : ChatConversation [ ] ,
9898 model = config . openAi . chatGpt . model ,
99+ ctx : OnMessageContext | OnCallBackQueryData ,
99100 limitTokens = true ,
100101 parameters ?: ModelParameters
101102) : Promise < LlmCompletion > {
102- const messages = prepareConversation ( conversation , model )
103+ const messages = prepareConversation ( conversation , model , ctx )
103104 parameters = parameters ?? {
104105 max_completion_tokens : config . openAi . chatGpt . maxTokens ,
105106 temperature : config . openAi . dalle . completions . temperature
@@ -139,15 +140,15 @@ export async function chatCompletion (
139140
140141export const streamChatCompletion = async (
141142 conversation : ChatConversation [ ] ,
142- ctx : OnMessageContext | OnCallBackQueryData ,
143143 model = LlmModelsEnum . GPT_4 ,
144+ ctx : OnMessageContext | OnCallBackQueryData ,
144145 msgId : number ,
145146 limitTokens = true ,
146147 parameters ?: ModelParameters
147148) : Promise < LlmCompletion > => {
148149 let completion = ''
149150 let wordCountMinimum = 2
150- const messages = prepareConversation ( conversation , model )
151+ const messages = prepareConversation ( conversation , model , ctx )
151152 parameters = parameters ?? {
152153 max_completion_tokens : config . openAi . chatGpt . maxTokens ,
153154 temperature : config . openAi . dalle . completions . temperature || 0.8
@@ -322,10 +323,10 @@ export const streamChatVisionCompletion = async (
322323 }
323324}
324325
325- export async function improvePrompt ( promptText : string , model : string ) : Promise < string > {
326+ export async function improvePrompt ( promptText : string , model : string , ctx : OnMessageContext | OnCallBackQueryData ) : Promise < string > {
326327 const prompt = `Improve this picture description using max 100 words and don't add additional text to the image: ${ promptText } `
327328 const conversation = [ { role : 'user' , content : prompt , timestamp : Date . now ( ) } ]
328- const response = await chatCompletion ( conversation , model )
329+ const response = await chatCompletion ( conversation , model , ctx )
329330 return response . completion ?. content as string ?? ''
330331}
331332
0 commit comments