Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a separate chat via API? #101

Open
Aviv1000 opened this issue Jun 13, 2024 · 2 comments
Open

How to create a separate chat via API? #101

Aviv1000 opened this issue Jun 13, 2024 · 2 comments

Comments

@Aviv1000
Copy link

import ollama from 'ollama'

const message = { role: 'user', content: 'What color of the sky?' }
const response = await ollama.chat({ model: 'llama2', messages: [message], stream: true })
for await (const part of response) {
  process.stdout.write(part.message.content)
}

const message2 = { role: 'user', content: 'What was my first prompt?' }
const response = await ollama.chat({ model: 'llama2', messages: [message2], stream: true })
for await (const part of response) {
  process.stdout.write(part.message.content)
}
//result: your first prompt was "What color of the sky?"

The documentation is not clear enough,
How am I supposed to save a session of the current conversation (to continue talking later) and create a new separate chat conversation?

@hopperelec
Copy link
Contributor

Just tested this exact same code and the same doesn't happen for me

@imareo
Copy link

imareo commented Jun 15, 2024

for one separate chat (in pseudo code):

  1. create empty chat=[] or [{role:'system', content:'...you system prompt here...'}]
  2. add new message: chat=[...chat, message]
  3. await ollama.chat({ model: 'llama2', messages: chat, stream: true })
  4. after get response add answer: chat=[...chat, answer] (answer must be {role:'assistant', content: 'ai bla-bla-bla'})
  5. goto 2

save this chat for late as you wish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants