transitive-bullshit / agentic

AI agent stdlib that works with any LLM and TypeScript AI SDK.
MIT License
16.07k stars 2.11k forks source link

Custom messageId saved into parentMessageId #626

Closed 4skinSkywalker closed 1 month ago

4skinSkywalker commented 8 months ago

Verify latest release

Verify webapp is working

Environment details

Node.js version 18, Windows 11

Describe the Bug

I have built a wrapper on top of ChatGPT API and save messages into my MongoDB. I would like to use my own IDs as messageIds, but I've noticed that when I pass messageId to sendMessage it's saved into parentMessageId on complete. Why is it so? How do I fix this?

image

4skinSkywalker commented 8 months ago

Mmh... I've tried chaining messages as in the examples and it doesn't work: If I pass the current res.id to the next sendMessage as parentMessageId it's basically just spawning a new chat with the prompt... Why is it doing that?

The following is my entry in the DB: image

This is where I send the former completion id as parentMessageId to a new prompt:

image

It answers that he can speak in French, but I'd have expected the output text of the "Golden Circle" wrote in Franch.

4skinSkywalker commented 8 months ago

Follows a full convo test (which I don't think is working as expected). As you can see I'm feeding Output.id into Input.parentMessageId. Why is it choosing whatever parentMessageId it wants from one message to the next?

Listening on port 3000

Input {
  chatId: '654f8e50d927de661d043342',
  parentMessageId: undefined,
  prompt: 'Write a poem about cats.',
  systemMessage: undefined,
  userId: '654f8d0bd927de661d04333d'
}

Output {
  role: 'assistant',
  id: 'chatcmpl-8K5DKKmDthPkKuiChn5nxKSjjNNqG',
  conversationId: '654f8e50d927de661d043342',
  parentMessageId: 'caf714e9-c41e-46c4-9e06-fea666e51196',
  text: 'In moonlit nights, they prowl with grace,\n' +   
    'Silent hunters, an elegant embrace.\n' +
    'Their eyes aglow, reflections gleam,\n' +
    'Mysterious creatures, of feline dream.\n' +
    '\n' +
    'With velvet paws and nimble feet,\n' +
    'They tread their path, both sly and fleet.\n' +      
    'Through alleys dark and rooftops high,\n' +
    'Curiosity fuels their inquisitive sky.\n' +
    '\n' +
    'Whiskers twitch, senses sharp,\n' +
    'Detecting whispers in the dark.\n' +
    "A predator's prowess, honed to perfection,\n" +      
    'Cats reign supreme, a regal connection.\n' +
    '\n' +
    'From playful pounces to gentle purrs,\n' +
    'They charm our hearts without any words.\n' +        
    'Independent souls, yet seeking affection,\n' +       
    'Their presence brings us respite and protection.\n' +
    '\n' +
    'With soft fur and a soothing hum,\n' +
    'They bring warmth when days are glum.\n' +
    'Cats, enchanting beings, so free and wild,\n' +      
    'Forever bewitching, like a whimsical child.\n' +     
    '\n' +
    'So let us honor these captivating friends,\n' +      
    'Whose presence on Earth seems to transcend.\n' +     
    'For in their essence, we find solace and peace,\n' + 
    'Cats, beloved companions, never cease.',
  detail: {
    id: 'chatcmpl-8K5DKKmDthPkKuiChn5nxKSjjNNqG',
    object: 'chat.completion',
    created: 1699797294,
    model: 'gpt-3.5-turbo-0613',
    choices: [ [Object] ],
    usage: { prompt_tokens: 91, completion_tokens: 221, total_tokens: 312 }
  }
}

Input {
  chatId: '654f8e50d927de661d043342',
  parentMessageId: 'chatcmpl-8K5DKKmDthPkKuiChn5nxKSjjNNqG',
  prompt: 'Can you make it cuter and shorter?',
  systemMessage: undefined,
  userId: '654f8d0bd927de661d04333d'
}
Output {
  role: 'assistant',
  id: 'chatcmpl-8K5E3OePuzgKpTOOWbatSUBEnpAZO',
  conversationId: '654f8e50d927de661d043342',
  parentMessageId: 'cc964cb4-d920-44d0-b428-e0c5e473f28d',
  text: 'Sure!',
  detail: {
    id: 'chatcmpl-8K5E3OePuzgKpTOOWbatSUBEnpAZO',
    object: 'chat.completion',
    created: 1699797339,
    model: 'gpt-3.5-turbo-0613',
    choices: [ [Object] ],
    usage: { prompt_tokens: 94, completion_tokens: 2, total_tokens: 96 }
  }
}

Input {
  chatId: '654f8e50d927de661d043342',
  parentMessageId: 'chatcmpl-8K5E3OePuzgKpTOOWbatSUBEnpAZO',
  prompt: 'Now write it in French.',
  systemMessage: undefined,
  userId: '654f8d0bd927de661d04333d'
}
Output {
  role: 'assistant',
  id: 'chatcmpl-8K5EdCVwkNhkYTLPNVioBJtooHtmq',
  conversationId: '654f8e50d927de661d043342',
  parentMessageId: '3cdd3909-efe5-40b4-84d4-539d80bcfdbe',
  text: 'Écrivez-la en français maintenant.',
  detail: {
    id: 'chatcmpl-8K5EdCVwkNhkYTLPNVioBJtooHtmq',
    object: 'chat.completion',
    created: 1699797375,
    model: 'gpt-3.5-turbo-0613',
    choices: [ [Object] ],
    usage: { prompt_tokens: 91, completion_tokens: 9, total_tokens: 100 }
  }
}
transitive-bullshit commented 1 month ago

This project is undergoing a major revamp; closing out old issues as part of the prep process.

The chatgpt package is pretty outdated at this point. I recommend that you use the openai package or the openai-fetch package instead.