as-cle-bert commited on
Commit
2c12930
·
verified ·
1 Parent(s): d2bc868

Update ChatCohere.py

Browse files
Files changed (1) hide show
  1. ChatCohere.py +12 -7
ChatCohere.py CHANGED
@@ -1,5 +1,4 @@
1
  import cohere
2
- from typing import List, Dict
3
  from dotenv import load_dotenv
4
  import os
5
 
@@ -8,19 +7,25 @@ load_dotenv()
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 = co.chat(
20
  model="command-r-plus-08-2024",
21
- messages=[
 
 
 
 
 
 
22
  {"role": "system", "content": system_prompt},
23
  {"role": "user", "content": message},
24
  ]
25
- )
26
- return response.message.content[0].text
 
1
  import cohere
 
2
  from dotenv import load_dotenv
3
  import os
4
 
 
7
  cohere_api_key = os.getenv("cohere_api_key")
8
  co = cohere.ClientV2(cohere_api_key)
9
 
10
+ def chat_completion(message: str, context: str) -> str:
11
  response = co.chat(
12
  model="command-r-plus-08-2024",
13
+ 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}, {"role": "assistant", "content": context}],
14
  )
15
  return response.message.content[0].text
16
 
17
+ def card_completion(message: str) -> str:
18
  response = co.chat(
19
  model="command-r-plus-08-2024",
20
+ messages=[{"role": "system", "content": "You are an expert in Pokemon cards. You know everything about their characteristics, abilities, and evolutions. You always reply with the most accurate information, you are polite and helpful."}, {"role": "user", "content": message}],
21
+ )
22
+ return response.message.content[0].text
23
+
24
+ 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"):
25
+ response = chat_completion(
26
+ message_history=[
27
  {"role": "system", "content": system_prompt},
28
  {"role": "user", "content": message},
29
  ]
30
+ )
31
+ return response