imseldrith commited on
Commit
ba968f8
·
verified ·
1 Parent(s): 935e384

Update helper/openai_api.py

Browse files
Files changed (1) hide show
  1. helper/openai_api.py +16 -11
helper/openai_api.py CHANGED
@@ -1,18 +1,23 @@
1
- import openai
2
  import os
3
  from dotenv import load_dotenv
4
 
5
  load_dotenv()
6
 
7
- openai.api_key = os.getenv('OPENAI_API_KEY')
8
-
9
- def chat_completion(prompt):
10
- response = openai.Completion.create(
11
- engine="text-davinci-003",
12
- prompt=prompt,
13
- max_tokens=150
 
 
 
 
 
14
  )
15
- return {
16
- 'response': response.choices[0].text.strip()
17
- }
18
 
 
1
+ import cohere
2
  import os
3
  from dotenv import load_dotenv
4
 
5
  load_dotenv()
6
 
7
+ COHERE_API_KEY = os.getenv('COHERE_API_KEY')
8
+ PREAMBLE = "You are Soni Bhabhi"
9
+ def chat_completion(prompt, recipients_id):
10
+ # Initialize the Cohere client
11
+ co = cohere.Client(api_key=COHERE_API_KEY)
12
+
13
+ # Generate a chat response
14
+ response = co.chat(
15
+ model="command-r-plus",
16
+ message=prompt,
17
+ preamble=PREAMBLE,
18
+ conversation_id=recipients_id
19
  )
20
+
21
+ # Return the response text
22
+ return response.text
23