Gemini 1.5 api thread

I created a simple chat program using Gemini 1.5 Pro API in the Google Colab. Now I want to know how to use threads to have simultaneous sessions with this chat . How can I do this?

Hi @Roberto_Caldeira

Welcome to the forum! You can create a simultaneous chat session using the threading class. Here’s a basic outline of the code:

import threading

def worker(prompt):
  chat_session(prompt)

threads = []
n_threads = 5  # Adjust the number of threads as needed

for i in range(n_threads):
  t = threading.Thread(target=worker, args=(prompt,))
  threads.append(t)
  t.start()

for t in threads:
  t.join()

You can pass the desired input to the worker function using the args argument. Worker function will handle the chat logic. You can use a queue or list to store the output for later processing.
If you still have issue please let me know.