as-cle-bert commited on
Commit
00b0db9
·
verified ·
1 Parent(s): adc3639

Create ChatCohere.py

Browse files
Files changed (1) hide show
  1. ChatCohere.py +25 -0
ChatCohere.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cohere
2
+ from typing import List, Dict
3
+ from dotenv import load_dotenv
4
+ import os
5
+
6
+ load_dotenv()
7
+
8
+ cohere_api_key = os.getenv("cohere_api_key")
9
+ co = cohere.ClientV2(cohere_api_key)
10
+
11
+ def chat_completion(message: str) -> str:
12
+ response = co.chat(
13
+ model="command-r-plus-08-2024",
14
+ 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}],
15
+ )
16
+ return response.message.content[0].text
17
+
18
+ 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"):
19
+ response = chat_completion(
20
+ message_history=[
21
+ {"role": "system", "content": system_prompt},
22
+ {"role": "user", "content": message},
23
+ ]
24
+ )
25
+ return response