File size: 536 Bytes
64f8031
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import cohere
import os
from dotenv import load_dotenv

load_dotenv()

COHERE_API_KEY = os.getenv('COHERE_API_KEY')
PREAMBLE = os.getenv('PREAMBLE') 

def chat_completion(prompt, recipients_id):
    # Initialize the Cohere client
    co = cohere.Client(api_key=COHERE_API_KEY)
    
    # Generate a chat response
    response = co.chat(
        model="command-r-plus",
        message=prompt,
        preamble=PREAMBLE,
        conversation_id= recipients_id+'idx'
    )
    
    # Return the response text
    return response.text