pokemon-bot / ChatCohere.py
as-cle-bert's picture
Create ChatCohere.py
00b0db9 verified
raw
history blame
1.18 kB
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: str) -> str:
response = co.chat(
model="command-r-plus-08-2024",
messages=[{"role": "system", "content": "You are a Pokemon expert. You know everything about their characteristics, abilities, and evolutions. You always reply with the most accurate information, you are polite and helpful. Your output cannot be larger than 1500 characters (spaces included)."}, {"role": "user", "content": message}],
)
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