Gemini ведет историю чата для многоходовых разговоров с сервером Python и клиентом React NativePython

Программы на Python
Anonymous
Gemini ведет историю чата для многоходовых разговоров с сервером Python и клиентом React Native

Сообщение Anonymous »

Я разрабатываю приложение React Native, в котором отправляю запросы на свой сервер Python и получаю ответы от ИИ Gemini. Однако у меня возникла проблема с сохранением истории чата для многоходовых разговоров.
Мой вопрос:
Как мне сохранить историю чата на моем сервере Python, чтобы Gemini могла предоставлять контекстно-зависимые ответы для многоходовые разговоры?
Код сервера Python

Код: Выделить всё

@app.route("my/api/endpoint")
def get_prompt(userInput, root, isVoiceChat):
try:

context_message = retriever(userInput)
model = GenerativeModel(
model_name="gemini-1.5-pro-001",
system_instruction=system_instruction
)

response = model.generate_content(context_message)
chat_response = response.candidates[0].content.text

return jsonify(response=chat_response)
except Exception as e:
return jsonify(error=str(e)), 500

Мой нативный код реагирования:

Код: Выделить всё

const sendMessage = async (text, name, isVoiceChat) => {
const newMessage = {
id: messages.length + 1,
text: text,
sender: 'user',
timestamp: new Date()
};

setMessages(messages => [...messages, newMessage]);
setInputText('');

setIsBotTyping(true); // Bot typing status to true

try {
const response = await getGeminiResponse(text, name, isVoiceChat);

const botResponse = {
id: messages.length + 2,
text: response,
sender: 'bot',
timestamp: new Date()
};

setMessages(messages => [...messages, botResponse]);
return response;
} catch (error) {
console.error('Error fetching bot response:', error);
} finally {
setIsBotTyping(false); // Bot typing status to false
}
};
Будем очень признательны за любую помощь или рекомендации!

Подробнее здесь: https://stackoverflow.com/questions/788 ... hon-server

Вернуться в «Python»