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 · 3 comments
Open

How to create a separate chat via API? #101

Aviv1000 opened this issue Jun 13, 2024 · 3 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

@ZaMeR12
Copy link

ZaMeR12 commented Sep 12, 2024

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?

What do you mean by your example? Do you mean that even when you do the ollama.chat for the second time, ollama remeber your first prompt? Or you want Ollama to remember the first prompt the second time you call it? Be cause if it's the second case the answer of imareo seem to be what's you need. If it's the first case, well you need aother solution. So please answer back to this issue to we know if your problem is solve or not and what was your need clearly.

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

4 participants