-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChatCohere.py
25 lines (21 loc) · 924 Bytes
/
ChatCohere.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cohere
from typing import List, Dict
from dotenv import load_dotenv
import os
load_dotenv()
cohere_api_key = os.getenv("cohere_api_key")
co = cohere.ClientV2(cohere_api_key)
def chat_completion(message_history: List[Dict[str, str]]) -> str:
response = co.chat(
model="command-r-plus-08-2024",
messages=message_history,
)
return response.message.content[0].text
def summarize(message, system_prompt="You are an helpful assistant whose job is to summarize the text you are given in less than 900 charachters (including spaces) in such a way that it would constitute an effective and engaging description of a pokemon card package"):
response = chat_completion(
message_history=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": message},
]
)
return response